Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-config): correctly detect CI environment and update snapshots accordingly #12378

Merged
merged 10 commits into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 43 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,46 @@ 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({rootDir: '/root/'}, {} as Config.Argv);
expect(options.updateSnapshot).toBe('new');
}
{
const {options} = await normalize({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 {options} = await normalize({rootDir: '/root/'}, {
ci: true,
} as Config.Argv);
expect(options.updateSnapshot).toBe('none');
}
{
const defaultCiConfig = Defaults.ci;
Defaults.ci = true;
const {options} = await normalize({rootDir: '/root/'}, {} as Config.Argv);
expect(options.updateSnapshot).toBe('none');
Defaults.ci = defaultCiConfig;
}
});
});
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -1132,7 +1132,7 @@ export default async function normalize(
}

newOptions.updateSnapshot =
argv.ci && !argv.updateSnapshot
(!!argv.ci || DEFAULT_CONFIG.ci) && !argv.updateSnapshot
SimenB marked this conversation as resolved.
Show resolved Hide resolved
? 'none'
: argv.updateSnapshot
? 'all'
Expand Down