Skip to content

Commit

Permalink
refactor: rename timeout to testTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb committed Jun 2, 2019
1 parent 8a7ac7b commit 2ea81b9
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion TestUtils.ts
Expand Up @@ -55,7 +55,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
testNamePattern: '',
testPathPattern: '',
testResultsProcessor: null,
timeout: 5000,
testTimeout: 5000,
updateSnapshot: 'none',
useStderr: false,
verbose: false,
Expand Down
4 changes: 2 additions & 2 deletions docs/CLI.md
Expand Up @@ -301,9 +301,9 @@ Lets you specify a custom test runner.

Lets you specify a custom test sequencer. Please refer to the documentation of the corresponding configuration property for details.

### `--timeout=<number>`
### `--testTimeout=<number>`

Default timeout of the test case. If the value is 0 then the timeout is 1 193 days.
Default timeout of a test. If the value is 0 then the timeout is ~1 193 days.

### `--updateSnapshot`

Expand Down
10 changes: 5 additions & 5 deletions e2e/__tests__/__snapshots__/timeouts.test.ts.snap
Expand Up @@ -21,33 +21,33 @@ Time: <<REPLACED>>
Ran all test suites.
`;
exports[`exceeds the command line timeout 1`] = `
exports[`exceeds the command line testTimeout 1`] = `
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
`;
exports[`does not exceed the command line timeout 1`] = `
exports[`does not exceed the command line testTimeout 1`] = `
PASS __tests__/a-banana.js
✓ banana
`;
exports[`does not exceed the command line timeout 2`] = `
exports[`does not exceed the command line testTimeout 2`] = `
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
`;
exports[`if command line timeout=0 its mean no timeout 1`] = `
exports[`if command line timeout=0 its mean no testTimeout 1`] = `
PASS __tests__/a-banana.js
✓ banana
`;
exports[`if command line timeout=0 its mean no timeout 2`] = `
exports[`if command line timeout=0 its mean no testTimeout 2`] = `
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Expand Down
16 changes: 10 additions & 6 deletions e2e/__tests__/timeouts.test.ts
Expand Up @@ -61,7 +61,7 @@ test('does not exceed the timeout', () => {
expect(status).toBe(0);
});

test('exceeds the command line timeout', () => {
test('exceeds the command line testTimeout', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
Expand All @@ -77,7 +77,7 @@ test('exceeds the command line timeout', () => {
const {stderr, status} = runJest(DIR, [
'-w=1',
'--ci=false',
'--timeout=200',
'--testTimeout=200',
]);
const {rest, summary} = extractSummary(stderr);
expect(rest).toMatch(
Expand All @@ -87,7 +87,7 @@ test('exceeds the command line timeout', () => {
expect(status).toBe(1);
});

test('does not exceed the command line timeout', () => {
test('does not exceed the command line testTimeout', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
Expand All @@ -103,15 +103,15 @@ test('does not exceed the command line timeout', () => {
const {stderr, status} = runJest(DIR, [
'-w=1',
'--ci=false',
'--timeout=1000',
'--testTimeout=1000',
]);
const {rest, summary} = extractSummary(stderr);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
expect(status).toBe(0);
});

test('if command line timeout=0 its mean no timeout', () => {
test('if command line timeout=0 its mean no testTimeout', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
Expand All @@ -124,7 +124,11 @@ test('if command line timeout=0 its mean no timeout', () => {
'package.json': '{}',
});

const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', '--timeout=0']);
const {stderr, status} = runJest(DIR, [
'-w=1',
'--ci=false',
'--testTimeout=0',
]);
const {rest, summary} = extractSummary(stderr);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
Expand Down
Expand Up @@ -47,7 +47,8 @@ export const initialize = ({
testPath: Config.Path;
parentProcess: Process;
}) => {
if (globalConfig.timeout) getRunnerState().testTimeout = globalConfig.timeout;
if (globalConfig.testTimeout)
getRunnerState().testTimeout = globalConfig.testTimeout;

const mutex = throat(globalConfig.maxConcurrency);

Expand Down
10 changes: 5 additions & 5 deletions packages/jest-cli/src/cli/args.ts
Expand Up @@ -622,16 +622,16 @@ export const options = {
'provided: `<rootDir>/path/to/testSequencer.js`',
type: 'string' as 'string',
},
testURL: {
description: 'This option sets the URL for the jsdom environment.',
type: 'string' as 'string',
},
timeout: {
testTimeout: {
description:
'This option sets the default timeouts of test cases.' +
"If you don't want timeout set it to 0",
type: 'number' as 'number',
},
testURL: {
description: 'This option sets the URL for the jsdom environment.',
type: 'string' as 'string',
},
timers: {
description:
'Setting this value to fake allows the use of fake timers ' +
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -113,8 +113,8 @@ const initialOptions: Config.InitialOptions = {
testResultsProcessor: 'processor-node-module',
testRunner: 'jasmine2',
testSequencer: '@jest/test-sequencer',
testTimeout: 5000,
testURL: 'http://localhost',
timeout: 5000,
timers: 'real',
transform: {
'^.+\\.js$': '<rootDir>/preprocessor.js',
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -1563,18 +1563,18 @@ describe('displayName', () => {
);
});

describe('timeout', () => {
describe('testTimeout', () => {
it('should return timeout value if defined', () => {
console.warn.mockImplementation(() => {});
const {options} = normalize({rootDir: '/root/', timeout: 1000}, {});
const {options} = normalize({rootDir: '/root/', testTimeout: 1000}, {});

expect(options.timeout).toBe(1000);
expect(options.testTimeout).toBe(1000);
expect(console.warn).not.toHaveBeenCalled();
});

it('should return with 2^32 -1 if timeout=0', () => {
const {options} = normalize({rootDir: '/root/', timeout: 0}, {});
const {options} = normalize({rootDir: '/root/', testTimeout: 0}, {});

expect(options.timeout).toBe(Math.pow(2, 31) - 1);
expect(options.testTimeout).toBe(Math.pow(2, 31) - 1);
});
});
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -149,7 +149,7 @@ const groupOptions = (
testPathPattern: options.testPathPattern,
testResultsProcessor: options.testResultsProcessor,
testSequencer: options.testSequencer,
timeout: options.timeout,
testTimeout: options.testTimeout,
updateSnapshot: options.updateSnapshot,
useStderr: options.useStderr,
verbose: options.verbose,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -790,7 +790,7 @@ export default function normalize(
value = oldOptions[key];
break;
}
case 'timeout': {
case 'testTimeout': {
value =
oldOptions[key] === 0 ? MAX_32_BIT_SIGNED_INTEGER : oldOptions[key];
break;
Expand Down
Expand Up @@ -112,7 +112,7 @@ exports[`prints the config object 1`] = `
"testNamePattern": "",
"testPathPattern": "",
"testResultsProcessor": null,
"timeout": 5000,
"testTimeout": 5000,
"updateSnapshot": "none",
"useStderr": false,
"verbose": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jasmine/jasmineLight.ts
Expand Up @@ -43,7 +43,7 @@ import Timer from './Timer';
const create = function(createOptions: Record<string, any>): Jasmine {
const j$ = {...createOptions} as Jasmine;

j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.globalConfig.timeout || 5000;
j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.globalConfig.testTimeout || 5000;

j$.getEnv = function(options?: object) {
const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options));
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-types/src/Config.ts
Expand Up @@ -207,7 +207,7 @@ export type InitialOptions = {
testRunner?: string;
testSequencer?: string;
testURL?: string;
timeout?: number;
testTimeout?: number;
timers?: 'real' | 'fake';
transform?: {
[key: string]: string;
Expand Down Expand Up @@ -345,7 +345,7 @@ export type GlobalConfig = {
testPathPattern: string;
testResultsProcessor: string | null | undefined;
testSequencer: string;
timeout: number;
testTimeout: number;
updateSnapshot: SnapshotUpdateState;
useStderr: boolean;
verbose: boolean | null | undefined;
Expand Down Expand Up @@ -491,7 +491,7 @@ export type Argv = Arguments<
testRunner: string;
testSequencer: string;
testURL: string;
timeout: number | null | undefined;
testTimeout: number | null | undefined;
timers: string;
transform: string;
transformIgnorePatterns: Array<string>;
Expand Down

0 comments on commit 2ea81b9

Please sign in to comment.