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 2 commits
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;
}
});
});
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newOptions already has the default checking the env var in it, so this only overrides that if argv has a value

}

newOptions.updateSnapshot =
argv.ci && !argv.updateSnapshot
newOptions.ci && !argv.updateSnapshot
? 'none'
: argv.updateSnapshot
? 'all'
Expand Down