Skip to content

Commit

Permalink
fix(jest-config): correctly detect CI environment and update snapshot…
Browse files Browse the repository at this point in the history
…s accordingly (#12378)

Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
  • Loading branch information
cola119 and SimenB committed Feb 13, 2022
1 parent 520e30d commit 4305088
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -85,6 +85,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"ci": true,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "<<REPLACED_ROOT_DIR>>/coverage",
Expand Down Expand Up @@ -121,7 +122,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"testFailureExitCode": 1,
"testPathPattern": "",
"testSequencer": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-test-sequencer/build/index.js",
"updateSnapshot": "all",
"updateSnapshot": "none",
"useStderr": false,
"watch": false,
"watchAll": false,
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/showConfig.test.ts
Expand Up @@ -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
Expand Down
51 changes: 47 additions & 4 deletions packages/jest-config/src/__tests__/normalize.test.ts
Expand Up @@ -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);
Expand All @@ -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;
});
});
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -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'
Expand Down
Expand Up @@ -62,6 +62,7 @@ exports[`prints the config object 1`] = `
"bail": 0,
"changedFilesWithAncestor": false,
"changedSince": "",
"ci": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "coverage",
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Expand Up @@ -289,6 +289,7 @@ export type GlobalConfig = {
bail: number;
changedSince?: string;
changedFilesWithAncestor: boolean;
ci: boolean;
collectCoverage: boolean;
collectCoverageFrom: Array<Glob>;
collectCoverageOnlyFrom?: {
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/config.ts
Expand Up @@ -11,6 +11,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
bail: 0,
changedFilesWithAncestor: false,
changedSince: '',
ci: false,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
Expand Down

0 comments on commit 4305088

Please sign in to comment.