diff --git a/TestUtils.ts b/TestUtils.ts index 1275e4ecb8eb..7150270a7b2e 100644 --- a/TestUtils.ts +++ b/TestUtils.ts @@ -55,7 +55,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = { testNamePattern: '', testPathPattern: '', testResultsProcessor: null, - timeout: 5000, + testTimeout: 5000, updateSnapshot: 'none', useStderr: false, verbose: false, diff --git a/docs/CLI.md b/docs/CLI.md index d6a7a7b664cd..1be3b2af3316 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -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=` +### `--testTimeout=` -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` diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index 2375a758ccc6..609c578cbc0f 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -21,7 +21,7 @@ Time: <> 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 @@ -29,12 +29,12 @@ Time: <> 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 @@ -42,12 +42,12 @@ Time: <> 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 diff --git a/e2e/__tests__/timeouts.test.ts b/e2e/__tests__/timeouts.test.ts index b5177166c475..3430475e91aa 100644 --- a/e2e/__tests__/timeouts.test.ts +++ b/e2e/__tests__/timeouts.test.ts @@ -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': ` @@ -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( @@ -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': ` @@ -103,7 +103,7 @@ 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(); @@ -111,7 +111,7 @@ test('does not exceed the command line timeout', () => { 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': ` @@ -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(); diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 60b92c84015a..10cfefcdf5a0 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -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); diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index ec48ec359f13..44447a1000f0 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -622,16 +622,16 @@ export const options = { 'provided: `/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 ' + diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index b1e743606d30..ee69c72b178f 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -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$': '/preprocessor.js', diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 6d721808e479..22e7d954c3be 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -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); }); }); diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index 9cf7161ef9ab..9290126323df 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -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, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index f84424c49a9d..034f1eb4e0c6 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -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; diff --git a/packages/jest-core/src/lib/__tests__/__snapshots__/log_debug_messages.test.ts.snap b/packages/jest-core/src/lib/__tests__/__snapshots__/log_debug_messages.test.ts.snap index b3aff5324245..357612825f0a 100644 --- a/packages/jest-core/src/lib/__tests__/__snapshots__/log_debug_messages.test.ts.snap +++ b/packages/jest-core/src/lib/__tests__/__snapshots__/log_debug_messages.test.ts.snap @@ -112,7 +112,7 @@ exports[`prints the config object 1`] = ` "testNamePattern": "", "testPathPattern": "", "testResultsProcessor": null, - "timeout": 5000, + "testTimeout": 5000, "updateSnapshot": "none", "useStderr": false, "verbose": false, diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index 3b2ae0f88458..2f9e08aa2362 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -43,7 +43,7 @@ import Timer from './Timer'; const create = function(createOptions: Record): 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)); diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 9dfc8db6a0a5..00a78f0bd1ca 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -207,7 +207,7 @@ export type InitialOptions = { testRunner?: string; testSequencer?: string; testURL?: string; - timeout?: number; + testTimeout?: number; timers?: 'real' | 'fake'; transform?: { [key: string]: string; @@ -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; @@ -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;