Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
## main

### Fixes

- `[jest-snapshot-utils]` Fix deprecated goo.gl snapshot warning not handling Windows end-of-line sequences ([#15800](https://github.com/jestjs/jest/pull/15800))

## 30.1.0

## Features

- `[jest-leak-detector]` Configurable GC aggressiveness regarding to V8 heap snapshot generation ([#15793](https://github.com/jestjs/jest/pull/15793/))
- `[jest-leak-detector]` Configurable GC aggressiveness regarding to V8 heap snapshot generation ([#15793](https://github.com/jestjs/jest/pull/15793/))
- `[jest-runtime]` Reduce redundant ReferenceError messages
- `[jest-core]` Include test modules that failed to load when --onlyFailures is active

### Fixes

- `[jest-snapshot-utils] Fix deprecated goo.gl snapshot guide link not getting replaced with fully canonical URL ([#15787](https://github.com/jestjs/jest/pull/15787))
- `[jest-snapshot-utils]` Fix deprecated goo.gl snapshot guide link not getting replaced with fully canonical URL ([#15787](https://github.com/jestjs/jest/pull/15787))
- `[jest-circus]` Fix `it.concurrent` not working with `describe.skip` ([#15765](https://github.com/jestjs/jest/pull/15765))
- `[jest-snapshot]` Fix mangled inline snapshot updates when used with Prettier 3 and CRLF line endings
- `[jest-runtime]` Importing from `@jest/globals` in more than one file no longer breaks relative paths ([#15772](https://github.com/jestjs/jest/issues/15772))
Expand Down
50 changes: 29 additions & 21 deletions packages/jest-snapshot-utils/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,33 @@ test('getSnapshotData() throws for older snapshot version', () => {
);
});

test('getSnapshotData() throws for newer snapshot version', () => {
const filename = path.join(__dirname, 'old-snapshot.snap');
jest
.mocked(fs.readFileSync)
.mockReturnValue(
`// Jest Snapshot v2, ${SNAPSHOT_GUIDE_LINK}\n\n` +
'exports[`myKey`] = `<div>\n</div>`;\n',
test.each([
['Linux', '\n'],
['Windows', '\r\n'],
])(
'getSnapshotData() throws for newer snapshot version with %s line endings',
(_: string, fileEol: string) => {
const filename = path.join(__dirname, 'old-snapshot.snap');
jest
.mocked(fs.readFileSync)
.mockReturnValue(
`// Jest Snapshot v2, ${SNAPSHOT_GUIDE_LINK}${fileEol}${fileEol}` +
`exports[\`myKey\`] = \`<div>${fileEol}</div>\`;${fileEol}`,
);
const update = 'none';

expect(() => getSnapshotData(filename, update)).toThrow(
`${chalk.red(
`${chalk.red.bold('Outdated Jest version')}: The version of this ` +
'snapshot file indicates that this project is meant to be used ' +
'with a newer version of Jest. ' +
'The snapshot file version ensures that all developers on a project ' +
'are using the same version of Jest. ' +
'Please update your version of Jest and re-run the tests.',
)}\n\nExpected: v${SNAPSHOT_VERSION}\nReceived: v2`,
);
const update = 'none';

expect(() => getSnapshotData(filename, update)).toThrow(
`${chalk.red(
`${chalk.red.bold('Outdated Jest version')}: The version of this ` +
'snapshot file indicates that this project is meant to be used ' +
'with a newer version of Jest. ' +
'The snapshot file version ensures that all developers on a project ' +
'are using the same version of Jest. ' +
'Please update your version of Jest and re-run the tests.',
)}\n\nExpected: v${SNAPSHOT_VERSION}\nReceived: v2`,
);
});
},
);

test('getSnapshotData() throws for deprecated snapshot guide link', () => {
const deprecatedGuideLink = 'https://goo.gl/fbAQLP';
Expand All @@ -170,7 +176,9 @@ test('getSnapshotData() throws for deprecated snapshot guide link', () => {

expect(() => getSnapshotData(filename, update)).toThrow(
`${chalk.red(
`${chalk.red.bold('Outdated guide link')}: The snapshot guide link is outdated.` +
`${chalk.red.bold(
'Outdated guide link',
)}: The snapshot guide link is outdated.` +
'Please update all snapshots while upgrading of Jest',
)}\n\nExpected: ${SNAPSHOT_GUIDE_LINK}\n` +
`Received: ${deprecatedGuideLink}`,
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-snapshot-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {Config} from '@jest/types';
import type {SnapshotData} from './types';

export const SNAPSHOT_VERSION = '1';
const SNAPSHOT_HEADER_REGEXP = /^\/\/ Jest Snapshot v(.+), (.+)\n/;
const SNAPSHOT_HEADER_REGEXP = /^\/\/ Jest Snapshot v(.+), (.+)\r?\n/;
export const SNAPSHOT_GUIDE_LINK = 'https://jestjs.io/docs/snapshot-testing';
export const SNAPSHOT_VERSION_WARNING = chalk.yellow(
`${chalk.bold('Warning')}: Before you upgrade snapshots, ` +
Expand Down Expand Up @@ -77,7 +77,9 @@ const validateSnapshotHeader = (snapshotContents: string) => {
return new Error(
// eslint-disable-next-line prefer-template
chalk.red(
`${chalk.red.bold('Outdated guide link')}: The snapshot guide link is outdated.` +
`${chalk.red.bold(
'Outdated guide link',
)}: The snapshot guide link is outdated.` +
'Please update all snapshots while upgrading of Jest',
) +
'\n\n' +
Expand Down
Loading