diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfc574b9fdc..1fcaf6e96db8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ - `[jest-cli]` Print custom error if error thrown from global hooks is not an error already ([#11003](https://github.com/facebook/jest/pull/11003)) - `[jest-cli]` Allow running multiple "projects" from programmatic API ([#11307](https://github.com/facebook/jest/pull/11307)) - `[jest-cli]` Fix missing collectCoverage after init ([#11353](https://github.com/facebook/jest/pull/11353)) +- `[jest-cli, jest-config, jest-types]` Move all default values into `jest-config` ([#9924](https://github.com/facebook/jest/pull/9924)) - `[jest-config]` [**BREAKING**] Change default file extension order by moving json behind ts and tsx ([10572](https://github.com/facebook/jest/pull/10572)) - `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) - `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123)) diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index c17aa298c841..aee8867ddd8e 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -17,7 +17,6 @@ "exit": "^0.1.2", "graceful-fs": "^4.2.4", "import-local": "^3.0.2", - "is-ci": "^3.0.0", "jest-config": "^27.0.0-next.9", "jest-util": "^27.0.0-next.9", "jest-validate": "^27.0.0-next.9", @@ -28,7 +27,6 @@ "@jest/test-utils": "^27.0.0-next.9", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.3", - "@types/is-ci": "^2.0.0", "@types/prompts": "^2.0.1", "@types/yargs": "^16.0.0" }, diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 60384b41fe1c..3e378b31d15c 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import isCI = require('is-ci'); import type {Config} from '@jest/types'; import {constants, isJSONString} from 'jest-config'; @@ -89,9 +88,9 @@ export const usage = 'Usage: $0 [--config=] [TestPathPattern]'; export const docs = 'Documentation: https://jestjs.io/'; +// The default values are all set in jest-config export const options = { all: { - default: undefined, description: 'The opposite of `onlyChanged`. If `onlyChanged` is set by ' + 'default, running jest with `--all` will force Jest to run all tests ' + @@ -99,19 +98,16 @@ export const options = { type: 'boolean', }, automock: { - default: undefined, description: 'Automock all files by default.', type: 'boolean', }, bail: { alias: 'b', - default: undefined, description: 'Exit the test suite immediately after `n` number of failing tests.', type: 'boolean', }, browser: { - default: undefined, description: 'Respect the "browser" field in package.json ' + 'when resolving modules. Some packages export different versions ' + @@ -119,7 +115,6 @@ export const options = { type: 'boolean', }, cache: { - default: undefined, description: 'Whether to use the transform cache. Disable the cache ' + 'using --no-cache.', @@ -132,7 +127,6 @@ export const options = { type: 'string', }, changedFilesWithAncestor: { - default: undefined, description: 'Runs tests related to the current changes and the changes made in the ' + 'last commit. Behaves similarly to `--onlyChanged`.', @@ -147,7 +141,6 @@ export const options = { type: 'string', }, ci: { - default: isCI, description: 'Whether to run Jest in continuous integration (CI) mode. ' + 'This option is on by default in most popular CI environments. It will ' + @@ -155,21 +148,18 @@ export const options = { type: 'boolean', }, clearCache: { - default: undefined, description: 'Clears the configured Jest cache directory and then exits. ' + 'Default directory can be found by calling jest --showConfig', type: 'boolean', }, clearMocks: { - default: undefined, description: 'Automatically clear mock calls and instances between every ' + 'test. Equivalent to calling jest.clearAllMocks() between each test.', type: 'boolean', }, collectCoverage: { - default: undefined, description: 'Alias for --coverage.', type: 'boolean', }, @@ -185,14 +175,12 @@ export const options = { type: 'array', }, color: { - default: undefined, description: 'Forces test results output color highlighting (even if ' + 'stdout is not a TTY). Set to false if you would like to have no colors.', type: 'boolean', }, colors: { - default: undefined, description: 'Alias for `--color`.', type: 'boolean', }, @@ -206,7 +194,6 @@ export const options = { type: 'string', }, coverage: { - default: undefined, description: 'Indicates that test coverage information should be ' + 'collected and reported in the output.', @@ -242,12 +229,10 @@ export const options = { type: 'string', }, debug: { - default: undefined, description: 'Print debugging info about your jest config.', type: 'boolean', }, detectLeaks: { - default: false, description: '**EXPERIMENTAL**: Detect memory leaks in tests. After executing a ' + 'test, it will try to garbage collect the global object used, and fail ' + @@ -255,7 +240,6 @@ export const options = { type: 'boolean', }, detectOpenHandles: { - default: false, description: 'Print out remaining open handles preventing Jest from exiting at the ' + 'end of a test run. Implies `runInBand`.', @@ -269,18 +253,15 @@ export const options = { type: 'string', }, errorOnDeprecated: { - default: false, description: 'Make calling deprecated APIs throw helpful error messages.', type: 'boolean', }, expand: { alias: 'e', - default: undefined, description: 'Use this flag to show full diffs instead of a patch.', type: 'boolean', }, filter: { - default: undefined, description: 'Path to a module exporting a filtering function. This method receives ' + 'a list of tests which can be manipulated to exclude tests from ' + @@ -289,7 +270,6 @@ export const options = { type: 'string', }, findRelatedTests: { - default: undefined, description: 'Find related tests for a list of source files that were ' + 'passed in as arguments. Useful for pre-commit hook integration to run ' + @@ -297,7 +277,6 @@ export const options = { type: 'boolean', }, forceExit: { - default: undefined, description: 'Force Jest to exit after all tests have completed running. ' + 'This is useful when resources set up by test code cannot be ' + @@ -332,21 +311,18 @@ export const options = { type: 'boolean', }, json: { - default: undefined, description: 'Prints the test results in JSON. This mode will send all ' + 'other test output and user messages to stderr.', type: 'boolean', }, lastCommit: { - default: undefined, description: 'Run all tests affected by file changes in the last commit made. ' + 'Behaves similarly to `--onlyChanged`.', type: 'boolean', }, listTests: { - default: false, description: 'Lists all tests Jest will run given the arguments and ' + 'exits. Most useful in a CI system together with `--findRelatedTests` ' + @@ -354,7 +330,6 @@ export const options = { type: 'boolean', }, logHeapUsage: { - default: undefined, description: 'Logs the heap usage after every test. Useful to debug ' + 'memory leaks. Use together with `--runInBand` and `--expose-gc` in ' + @@ -362,7 +337,6 @@ export const options = { type: 'boolean', }, maxConcurrency: { - default: 5, description: 'Specifies the maximum number of tests that are allowed to run' + 'concurrently. This only affects tests using `test.concurrent`.', @@ -416,23 +390,19 @@ export const options = { type: 'array', }, noStackTrace: { - default: undefined, description: 'Disables stack trace in test results output', type: 'boolean', }, notify: { - default: undefined, description: 'Activates notifications for test results.', type: 'boolean', }, notifyMode: { - default: 'failure-change', description: 'Specifies when notifications will appear for test results.', type: 'string', }, onlyChanged: { alias: 'o', - default: undefined, description: 'Attempts to identify which tests to run based on which ' + "files have changed in the current repository. Only works if you're " + @@ -441,7 +411,6 @@ export const options = { }, onlyFailures: { alias: 'f', - default: undefined, description: 'Run tests that failed in the previous execution.', type: 'boolean', }, @@ -452,7 +421,6 @@ export const options = { type: 'string', }, passWithNoTests: { - default: false, description: 'Will not fail if no tests are found (for example while using `--testPathPattern`.)', type: 'boolean', @@ -462,7 +430,6 @@ export const options = { type: 'string', }, prettierPath: { - default: undefined, description: 'The path to the "prettier" module used for inline snapshots.', type: 'string', }, @@ -479,14 +446,12 @@ export const options = { type: 'array', }, resetMocks: { - default: undefined, description: 'Automatically reset mock state between every test. ' + 'Equivalent to calling jest.resetAllMocks() between each test.', type: 'boolean', }, resetModules: { - default: undefined, description: 'If enabled, the module registry for every test file will ' + 'be reset before running each individual test.', @@ -497,7 +462,6 @@ export const options = { type: 'string', }, restoreMocks: { - default: undefined, description: 'Automatically restore mock state and implementation between every test. ' + 'Equivalent to calling jest.restoreAllMocks() between each test.', @@ -518,7 +482,6 @@ export const options = { }, runInBand: { alias: 'i', - default: undefined, description: 'Run all tests serially in the current process (rather than ' + 'creating a worker pool of child processes that run tests). This ' + @@ -527,7 +490,6 @@ export const options = { type: 'boolean', }, runTestsByPath: { - default: false, description: 'Used when provided patterns are exact file paths. This avoids ' + 'converting them into a regular expression and matching it against ' + @@ -561,17 +523,14 @@ export const options = { type: 'array', }, showConfig: { - default: undefined, description: 'Print your jest config and then exits.', type: 'boolean', }, silent: { - default: undefined, description: 'Prevent tests from printing messages through the console.', type: 'boolean', }, skipFilter: { - default: undefined, description: 'Disables the filter provided by --filter. Useful for CI jobs, or ' + 'local enforcement when fixing tests.', @@ -599,7 +558,6 @@ export const options = { type: 'string', // number }, testLocationInResults: { - default: false, description: 'Add `location` information to the test results', type: 'boolean', }, @@ -692,7 +650,6 @@ export const options = { }, updateSnapshot: { alias: 'u', - default: undefined, description: 'Use this flag to re-record snapshots. ' + 'Can be used together with a test suite pattern or with ' + @@ -701,24 +658,20 @@ export const options = { type: 'boolean', }, useStderr: { - default: undefined, description: 'Divert all output to stderr.', type: 'boolean', }, verbose: { - default: undefined, description: 'Display individual test results with the test suite hierarchy.', type: 'boolean', }, version: { alias: 'v', - default: undefined, description: 'Print the version and exit', type: 'boolean', }, watch: { - default: undefined, description: 'Watch files for changes and rerun tests related to ' + 'changed files. If you want to re-run all tests when a file has ' + @@ -726,7 +679,6 @@ export const options = { type: 'boolean', }, watchAll: { - default: undefined, description: 'Watch files for changes and rerun all tests. If you want ' + 'to re-run only the tests related to the changed files, use the ' + @@ -742,7 +694,6 @@ export const options = { type: 'array', }, watchman: { - default: undefined, description: 'Whether to use watchman for file crawling. Disable using ' + '--no-watchman.', diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 0b1f97ca8dd7..48a9ce63672f 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -30,6 +30,7 @@ "deepmerge": "^4.2.2", "glob": "^7.1.1", "graceful-fs": "^4.2.4", + "is-ci": "^3.0.0", "jest-circus": "^27.0.0-next.9", "jest-environment-jsdom": "^27.0.0-next.9", "jest-environment-node": "^27.0.0-next.9", @@ -46,6 +47,7 @@ "@types/babel__core": "^7.0.4", "@types/glob": "^7.1.1", "@types/graceful-fs": "^4.1.3", + "@types/is-ci": "^3.0.0", "@types/micromatch": "^4.0.1", "jest-snapshot-serializer-raw": "^1.1.0", "strip-ansi": "^6.0.0", diff --git a/packages/jest-config/src/Defaults.ts b/packages/jest-config/src/Defaults.ts index 7522da678ee3..d8a31dc02df3 100644 --- a/packages/jest-config/src/Defaults.ts +++ b/packages/jest-config/src/Defaults.ts @@ -6,6 +6,7 @@ */ import {sep} from 'path'; +import isCI = require('is-ci'); import type {Config} from '@jest/types'; import {replacePathSepForRegex} from 'jest-regex-util'; import {NODE_MODULES} from './constants'; @@ -19,11 +20,14 @@ const defaultOptions: Config.DefaultOptions = { cache: true, cacheDirectory: getCacheDirectory(), changedFilesWithAncestor: false, + ci: isCI, clearMocks: false, collectCoverage: false, coveragePathIgnorePatterns: [NODE_MODULES_REGEXP], coverageProvider: 'babel', coverageReporters: ['json', 'text', 'lcov', 'clover'], + detectLeaks: false, + detectOpenHandles: false, errorOnDeprecated: false, expand: false, extensionsToTreatAsEsm: [], @@ -36,6 +40,7 @@ const defaultOptions: Config.DefaultOptions = { throwOnModuleCollision: false, }, injectGlobals: true, + listTests: false, maxConcurrency: 5, maxWorkers: '50%', moduleDirectories: ['node_modules'], @@ -45,6 +50,7 @@ const defaultOptions: Config.DefaultOptions = { noStackTrace: false, notify: false, notifyMode: 'failure-change', + passWithNoTests: false, prettierPath: 'prettier', resetMocks: false, resetModules: false, diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index d655914a100e..9fc46708c47e 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -19,6 +19,7 @@ const initialOptions: Config.InitialOptions = { cacheDirectory: '/tmp/user/jest', changedFilesWithAncestor: false, changedSince: 'master', + ci: false, clearMocks: false, collectCoverage: true, collectCoverageFrom: ['src', '!public'], @@ -38,6 +39,8 @@ const initialOptions: Config.InitialOptions = { }, }, dependencyExtractor: '/dependencyExtractor.js', + detectLeaks: false, + detectOpenHandles: false, displayName: multipleValidOptions('test-config', { color: 'blue', name: 'test-config', @@ -64,6 +67,7 @@ const initialOptions: Config.InitialOptions = { injectGlobals: true, json: false, lastCommit: false, + listTests: false, logHeapUsage: true, maxConcurrency: 5, maxWorkers: '50%', @@ -81,6 +85,7 @@ const initialOptions: Config.InitialOptions = { notifyMode: 'failure-change', onlyChanged: false, onlyFailures: false, + passWithNoTests: false, preset: 'react-native', prettierPath: '/node_modules/prettier', projects: ['project-a', 'project-b/'], diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 5b53f4b637c7..756fc26e7f67 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -64,11 +64,14 @@ export type DefaultOptions = { cache: boolean; cacheDirectory: Path; changedFilesWithAncestor: boolean; + ci: boolean; clearMocks: boolean; collectCoverage: boolean; coveragePathIgnorePatterns: Array; coverageReporters: Array; coverageProvider: CoverageProvider; + detectLeaks: boolean; + detectOpenHandles: boolean; errorOnDeprecated: boolean; expand: boolean; extensionsToTreatAsEsm: Array; @@ -76,6 +79,7 @@ export type DefaultOptions = { globals: ConfigGlobals; haste: HasteConfig; injectGlobals: boolean; + listTests: boolean; maxConcurrency: number; maxWorkers: number | string; moduleDirectories: Array; @@ -85,6 +89,7 @@ export type DefaultOptions = { noStackTrace: boolean; notify: boolean; notifyMode: NotifyMode; + passWithNoTests: boolean; prettierPath: string; resetMocks: boolean; resetModules: boolean; @@ -133,6 +138,7 @@ export type InitialOptions = Partial<{ bail: boolean | number; cache: boolean; cacheDirectory: Path; + ci: boolean; clearMocks: boolean; changedFilesWithAncestor: boolean; changedSince: string; diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index 0c30fba0e5a3..1aec93dd0ec6 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "@types/graceful-fs": "^4.1.2", - "@types/is-ci": "^2.0.0", + "@types/is-ci": "^3.0.0", "@types/micromatch": "^4.0.1", "@types/picomatch": "^2.2.2" }, diff --git a/yarn.lock b/yarn.lock index a53c8341c1e9..21b0eac2b934 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4464,13 +4464,6 @@ __metadata: languageName: node linkType: hard -"@types/ci-info@npm:*": - version: 2.0.0 - resolution: "@types/ci-info@npm:2.0.0" - checksum: 89efcab6fdc38ae27febdf87e1de9b49bfff13778ca807f4a2236340d4fa53d446f4abe3c19a1b19619a295f1fac72d64c88eb49927e5f54a29c9cedb2ccd685 - languageName: node - linkType: hard - "@types/co@npm:^4.6.0, @types/co@npm:^4.6.2": version: 4.6.2 resolution: "@types/co@npm:4.6.2" @@ -4600,12 +4593,12 @@ __metadata: languageName: node linkType: hard -"@types/is-ci@npm:^2.0.0": - version: 2.0.0 - resolution: "@types/is-ci@npm:2.0.0" +"@types/is-ci@npm:^3.0.0": + version: 3.0.0 + resolution: "@types/is-ci@npm:3.0.0" dependencies: - "@types/ci-info": "*" - checksum: 870279b2fb690288351bca6c06e83c50d706ebe5c6da59fdfef2b4ced65572a459005b8fc020863b4f84fc59a3a71e565210c18dafd4fe85e86e4bf579803e74 + ci-info: ^3.1.0 + checksum: 661e9cc9ba61e1c283f3814fbb1355aca70b281b5d71def665348f8e17db1fbdf5e62db496b0c2ab7b913e49ad626faa28478c06b9fecf70f860f4386469973f languageName: node linkType: hard @@ -7147,7 +7140,7 @@ __metadata: languageName: node linkType: hard -"ci-info@npm:^3.0.0, ci-info@npm:^3.1.1": +"ci-info@npm:^3.0.0, ci-info@npm:^3.1.0, ci-info@npm:^3.1.1": version: 3.1.1 resolution: "ci-info@npm:3.1.1" checksum: 417d2bf17c320d477bc32997d3831bcc1b174d6b48616c2f0463765f042f073bfbfb15e06abdeea55b05ca9c8e054057eb9e0672e4e6031457e87216b2faddda @@ -12793,14 +12786,12 @@ fsevents@^1.2.7: "@jest/types": ^27.0.0-next.8 "@types/exit": ^0.1.30 "@types/graceful-fs": ^4.1.3 - "@types/is-ci": ^2.0.0 "@types/prompts": ^2.0.1 "@types/yargs": ^16.0.0 chalk: ^4.0.0 exit: ^0.1.2 graceful-fs: ^4.2.4 import-local: ^3.0.2 - is-ci: ^3.0.0 jest-config: ^27.0.0-next.9 jest-util: ^27.0.0-next.9 jest-validate: ^27.0.0-next.9 @@ -12826,12 +12817,14 @@ fsevents@^1.2.7: "@types/babel__core": ^7.0.4 "@types/glob": ^7.1.1 "@types/graceful-fs": ^4.1.3 + "@types/is-ci": ^3.0.0 "@types/micromatch": ^4.0.1 babel-jest: ^27.0.0-next.9 chalk: ^4.0.0 deepmerge: ^4.2.2 glob: ^7.1.1 graceful-fs: ^4.2.4 + is-ci: ^3.0.0 jest-circus: ^27.0.0-next.9 jest-environment-jsdom: ^27.0.0-next.9 jest-environment-node: ^27.0.0-next.9 @@ -13380,7 +13373,7 @@ fsevents@^1.2.7: dependencies: "@jest/types": ^27.0.0-next.8 "@types/graceful-fs": ^4.1.2 - "@types/is-ci": ^2.0.0 + "@types/is-ci": ^3.0.0 "@types/micromatch": ^4.0.1 "@types/node": "*" "@types/picomatch": ^2.2.2