Skip to content

Commit

Permalink
feat(config): adds compare option
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jan 9, 2021
1 parent 175e770 commit acb97c5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ module.exports = {
/** Optional boolean flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching. Defaults to true. */
cache: true,

/** Optional boolean flag used to enable result comparison. Defaults to false. */
compare: false,

/** Optional time limit in seconds for the scan. Scan is interrupted after reaching the limit. Defaults to 5 hours 30 minutes. */
timeLimit: 5.5 * 60 * 60, // 5 hours 30 minutes

Expand Down
2 changes: 2 additions & 0 deletions eslint-remote-tester.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {

cache: true,

compare: false,

/**
* Optional callback invoked once scan is complete.
*
Expand Down
5 changes: 4 additions & 1 deletion lib/config/config-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ export const CONFIGURATION_FILE_TEMPLATE =
/** Optional setting for log level. Valid values are verbose, info, warn, error. Defaults to verbose. */
logLevel: 'verbose',
/** Optional boolean flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching. Defauls to true. */
/** Optional boolean flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching. Defaults to true. */
cache: true,
/** Optional time limit in seconds for the scan. Scan is interrupted after reaching the limit. Defaults to 5 hours 30 minutes. */
timeLimit: 5.5 * 60 * 60, // 5 hours 30 minutes
/** Optional boolean flag used to enable result comparison. Defaults to false. */
compare: false,
/**
* Optional callback invoked once scan is complete.
*
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Config {
logLevel: LogLevel;
cache: boolean;
timeLimit: number;
compare: boolean;
onComplete?: (results: Result[]) => Promise<void> | void;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/config/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_MAX_FILE_SIZE_BYTES = 2000000;
const DEFAULT_TIME_LIMIT_SECONDS = 5.5 * 60 * 60;
const DEFAULT_CI = process.env.CI === 'true';
const DEFAULT_CACHE = true;
const DEFAULT_COMPARE = false;

const UNKNOWN_RULE_REGEXP = /^Definition for rule (.*) was not found.$/;

Expand Down Expand Up @@ -91,6 +92,7 @@ export default async function validate(
logLevel,
cache,
timeLimit,
compare,
onComplete,
...unknownKeys
} = configToValidate;
Expand Down Expand Up @@ -180,6 +182,10 @@ export default async function validate(

errors.push(validateOptionalPositiveNumber('timeLimit', timeLimit));

if (compare != null && typeof compare !== 'boolean') {
errors.push(`compare (${compare}) should be a boolean.`);
}

if (onComplete && typeof onComplete !== 'function') {
errors.push(`onComplete (${onComplete}) should be a function`);
}
Expand Down Expand Up @@ -231,6 +237,8 @@ export function getConfigWithDefaults(config: ConfigWithOptionals): Config {
concurrentTasks: config.concurrentTasks || DEFAULT_CONCURRENT_TASKS,

timeLimit: config.timeLimit || DEFAULT_TIME_LIMIT_SECONDS,

compare: config.compare != null ? config.compare : DEFAULT_COMPARE,
};
}

Expand Down
29 changes: 29 additions & 0 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_CONFIGURATION: ConfigWithOptionals = {
cache: undefined,
logLevel: undefined,
timeLimit: undefined,
compare: undefined,
onComplete: undefined,
};

Expand All @@ -46,6 +47,7 @@ describe('config', () => {
expect(config.timeLimit).toBe(5.5 * 60 * 60);
expect(config.pathIgnorePattern).toBe(undefined);
expect(config.cache).toBe(true);
expect(config.compare).toBe(false);
expect(config.onComplete).toBe(undefined);
});

Expand All @@ -61,6 +63,7 @@ describe('config', () => {
expect(config.timeLimit).toBe(5.5 * 60 * 60);
expect(config.pathIgnorePattern).toBe(undefined);
expect(config.cache).toBe(true);
expect(config.compare).toBe(false);
expect(config.onComplete).toBe(undefined);
});

Expand Down Expand Up @@ -288,6 +291,20 @@ describe('validateConfig', () => {
});
});

test('compare is optional', async () => {
await validateConfig({
...DEFAULT_CONFIGURATION,
compare: undefined,
});
});

test('compare accepts boolean', async () => {
await validateConfig({
...DEFAULT_CONFIGURATION,
compare: true,
});
});

test('onComplete is optional', async () => {
await validateConfig({
...DEFAULT_CONFIGURATION,
Expand Down Expand Up @@ -635,6 +652,18 @@ describe('validateConfig', () => {
);
});

test('compare requires boolean', async () => {
await validateConfig({
...DEFAULT_CONFIGURATION,
compare: 'text' as any,
});

const [validationError] = getConsoleLogCalls();
expect(validationError).toMatch(
'compare (text) should be a boolean.'
);
});

test('onComplete requires function', async () => {
await validateConfig({
...DEFAULT_CONFIGURATION,
Expand Down

0 comments on commit acb97c5

Please sign in to comment.