diff --git a/CHANGELOG.md b/CHANGELOG.md index c74f57649f92..9c890a8f2fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - `[jest-config]` [**BREAKING**] Stop shipping `jest-environment-jsdom` by default ([#12354](https://github.com/facebook/jest/pull/12354)) - `[jest-config]` [**BREAKING**] Stop shipping `jest-jasmine2` by default ([#12355](https://github.com/facebook/jest/pull/12355)) +- `[jest-config, @jest/types]` Add `ci` to `GlobalConfig` ([#12378](https://github.com/facebook/jest/pull/12378)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade jsdom to 19.0.0 ([#12290](https://github.com/facebook/jest/pull/12290)) - `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924)) - `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924)) @@ -16,6 +17,7 @@ - `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346)) - `[expect]` Expose `AsymmetricMatchers` and `RawMatcherFn` interfaces ([#12363](https://github.com/facebook/jest/pull/12363)) - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) +- `[jest-config]` Correctly detect CI environment and update snapshots accordingly ([#12378](https://github.com/facebook/jest/pull/12378)) - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) ### Chore & Maintenance diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 7a7744fb52d6..a1fab78aca78 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -85,6 +85,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "globalConfig": { "bail": 0, "changedFilesWithAncestor": false, + "ci": true, "collectCoverage": false, "collectCoverageFrom": [], "coverageDirectory": "<>/coverage", @@ -121,7 +122,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "testFailureExitCode": 1, "testPathPattern": "", "testSequencer": "<>/jest-test-sequencer/build/index.js", - "updateSnapshot": "all", + "updateSnapshot": "none", "useStderr": false, "watch": false, "watchAll": false, diff --git a/e2e/__tests__/showConfig.test.ts b/e2e/__tests__/showConfig.test.ts index a73c5fcecf10..f0c545d28c19 100644 --- a/e2e/__tests__/showConfig.test.ts +++ b/e2e/__tests__/showConfig.test.ts @@ -25,7 +25,7 @@ test('--showConfig outputs config info and exits', () => { '--showConfig', '--no-cache', // Make the snapshot flag stable on CI. - '--updateSnapshot', + '--ci', ]); stdout = stdout diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 795e037b79d0..19f489da24f5 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -1844,19 +1844,22 @@ describe('extensionsToTreatAsEsm', () => { describe('haste.enableSymlinks', () => { it('should throw if watchman is not disabled', async () => { await expect( - normalize({haste: {enableSymlinks: true}, rootDir: '/root/'}, {}), + normalize( + {haste: {enableSymlinks: true}, rootDir: '/root/'}, + {} as Config.Argv, + ), ).rejects.toThrow('haste.enableSymlinks is incompatible with watchman'); await expect( normalize( {haste: {enableSymlinks: true}, rootDir: '/root/', watchman: true}, - {}, + {} as Config.Argv, ), ).rejects.toThrow('haste.enableSymlinks is incompatible with watchman'); const {options} = await normalize( {haste: {enableSymlinks: true}, rootDir: '/root/', watchman: false}, - {}, + {} as Config.Argv, ); expect(options.haste.enableSymlinks).toBe(true); @@ -1868,10 +1871,50 @@ describe('haste.forceNodeFilesystemAPI', () => { it('should pass option through', async () => { const {options} = await normalize( {haste: {forceNodeFilesystemAPI: true}, rootDir: '/root/'}, - {}, + {} as Config.Argv, ); expect(options.haste.forceNodeFilesystemAPI).toBe(true); expect(console.warn).not.toHaveBeenCalled(); }); }); + +describe('updateSnapshot', () => { + it('should be all if updateSnapshot is true', async () => { + const {options} = await normalize({rootDir: '/root/'}, { + updateSnapshot: true, + } as Config.Argv); + expect(options.updateSnapshot).toBe('all'); + }); + it('should be new if updateSnapshot is falsy', async () => { + { + const {options} = await normalize( + {ci: false, rootDir: '/root/'}, + {} as Config.Argv, + ); + expect(options.updateSnapshot).toBe('new'); + } + { + const {options} = await normalize({ci: false, rootDir: '/root/'}, { + updateSnapshot: false, + } as Config.Argv); + expect(options.updateSnapshot).toBe('new'); + } + }); + it('should be none if updateSnapshot is falsy and ci mode is true', async () => { + const defaultCiConfig = Defaults.ci; + { + Defaults.ci = false; + const {options} = await normalize({rootDir: '/root/'}, { + ci: true, + } as Config.Argv); + expect(options.updateSnapshot).toBe('none'); + } + { + Defaults.ci = true; + const {options} = await normalize({rootDir: '/root/'}, {} as Config.Argv); + expect(options.updateSnapshot).toBe('none'); + } + Defaults.ci = defaultCiConfig; + }); +}); diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index dc3d063fc257..5254186e48db 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -117,6 +117,7 @@ const groupOptions = ( bail: options.bail, changedFilesWithAncestor: options.changedFilesWithAncestor, changedSince: options.changedSince, + ci: options.ci, collectCoverage: options.collectCoverage, collectCoverageFrom: options.collectCoverageFrom, collectCoverageOnlyFrom: options.collectCoverageOnlyFrom, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 935f733e3fa5..09574fe4d69d 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1131,8 +1131,12 @@ export default async function normalize( newOptions.moduleNameMapper = []; } + if (argv.ci != null) { + newOptions.ci = argv.ci; + } + newOptions.updateSnapshot = - argv.ci && !argv.updateSnapshot + newOptions.ci && !argv.updateSnapshot ? 'none' : argv.updateSnapshot ? 'all' diff --git a/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap b/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap index d90a214c4873..3e92033b0402 100644 --- a/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap +++ b/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap @@ -62,6 +62,7 @@ exports[`prints the config object 1`] = ` "bail": 0, "changedFilesWithAncestor": false, "changedSince": "", + "ci": false, "collectCoverage": false, "collectCoverageFrom": [], "coverageDirectory": "coverage", diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index d94e4296b5f5..fa0d2a205595 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -289,6 +289,7 @@ export type GlobalConfig = { bail: number; changedSince?: string; changedFilesWithAncestor: boolean; + ci: boolean; collectCoverage: boolean; collectCoverageFrom: Array; collectCoverageOnlyFrom?: { diff --git a/packages/test-utils/src/config.ts b/packages/test-utils/src/config.ts index 9a97135d8d77..a6146b14bcb2 100644 --- a/packages/test-utils/src/config.ts +++ b/packages/test-utils/src/config.ts @@ -11,6 +11,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = { bail: 0, changedFilesWithAncestor: false, changedSince: '', + ci: false, collectCoverage: false, collectCoverageFrom: [], collectCoverageOnlyFrom: undefined,