diff --git a/CHANGELOG.md b/CHANGELOG.md index 2162247a3be9..bf8893b6b24f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### Chore & Maintenance +- `[*]` Replace internal usage of `pretty-format/ConvertAnsi` with `jest-serializer-ansi-escapes` ([#12935](https://github.com/facebook/jest/pull/12935)) + ### Performance ## 28.1.2 diff --git a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap index 64c805df8b1c..1a0e4d7b91ae 100644 --- a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap @@ -1,18 +1,45 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can press "p" to filter by file name 1`] = ` - +" + Pattern Mode Usage › Press Esc to exit pattern mode. › Press Enter to filter by a filenames regex pattern. - pattern ›  - pattern › b - pattern › ba - pattern › bar - - - + + + + + pattern › + + + + + + + pattern › b + + + + + + + pattern › ba + + + + + + + pattern › bar + + + + + + +" `; exports[`can press "p" to filter by file name: test results 1`] = ` @@ -43,16 +70,31 @@ Ran all test suites matching /bar/i." `; exports[`can press "t" to filter by test name 1`] = ` - +" + Pattern Mode Usage › Press Esc to exit pattern mode. › Press Enter to filter by a tests regex pattern. - pattern ›  - pattern › 2 - - - + + + + + pattern › + + + + + + + pattern › 2 + + + + + + +" `; exports[`can press "t" to filter by test name: test results 1`] = ` diff --git a/e2e/__tests__/watchModeOnlyFailed.test.ts b/e2e/__tests__/watchModeOnlyFailed.test.ts index 3cdbab6514e9..e47e385597d2 100644 --- a/e2e/__tests__/watchModeOnlyFailed.test.ts +++ b/e2e/__tests__/watchModeOnlyFailed.test.ts @@ -16,11 +16,6 @@ const pluginPath = path.resolve(__dirname, '../MockStdinWatchPlugin'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); -expect.addSnapshotSerializer({ - print: val => (val as string).replace(/\[s\[u/g, '\n'), - test: val => typeof val === 'string' && val.includes('[s'), -}); - const setupFiles = (input: Array<{keys: Array}>) => { writeFiles(DIR, { '__tests__/bar.spec.js': ` diff --git a/e2e/__tests__/watchModePatterns.test.ts b/e2e/__tests__/watchModePatterns.test.ts index 7361a5f426ea..efff41464f97 100644 --- a/e2e/__tests__/watchModePatterns.test.ts +++ b/e2e/__tests__/watchModePatterns.test.ts @@ -16,11 +16,6 @@ const pluginPath = path.resolve(__dirname, '../MockStdinWatchPlugin'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); -expect.addSnapshotSerializer({ - print: val => (val as string).replace(/\[s\[u/g, '\n'), - test: val => typeof val === 'string' && val.includes('[s'), -}); - const setupFiles = (input: Array<{keys: Array}>) => { writeFiles(DIR, { '__tests__/bar.spec.js': ` diff --git a/jest.config.mjs b/jest.config.mjs index 28c68e7890e4..e5e37ed06c0a 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -35,7 +35,7 @@ export default { snapshotFormat: { escapeString: false, }, - snapshotSerializers: [require.resolve('pretty-format/ConvertAnsi')], + snapshotSerializers: [require.resolve('jest-serializer-ansi-escapes')], testPathIgnorePatterns: [ '/__arbitraries__/', '/__benchmarks__/', diff --git a/package.json b/package.json index 63a2788a236e..8dea7072ea8c 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "jest-junit": "^13.0.0", "jest-mock": "workspace:*", "jest-runner-tsd": "^3.1.0", + "jest-serializer-ansi-escapes": "^1.0.0", "jest-silent-reporter": "^0.5.0", "jest-snapshot": "workspace:*", "jest-watch-typeahead": "^1.1.0", diff --git a/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js b/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js index af11788ab076..6e7135a87796 100644 --- a/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js +++ b/packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js @@ -9,23 +9,6 @@ import chalk from 'chalk'; import {KEYS} from 'jest-watcher'; import SnapshotInteractiveMode from '../SnapshotInteractiveMode'; -jest - .mock('ansi-escapes', () => ({ - cursorRestorePosition: '[MOCK - cursorRestorePosition]', - cursorSavePosition: '[MOCK - cursorSavePosition]', - cursorScrollDown: '[MOCK - cursorScrollDown]', - cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`, - cursorUp: () => '[MOCK - cursorUp]', - eraseDown: '[MOCK - eraseDown]', - })) - .mock('jest-util', () => { - const {specialChars, ...util} = jest.requireActual('jest-util'); - return { - ...util, - specialChars: {...specialChars, CLEAR: '[MOCK - clear]'}, - }; - }); - jest.doMock('chalk', () => Object.assign(new chalk.Instance({level: 0}), { stripColor: str => str, diff --git a/packages/jest-core/src/__tests__/__snapshots__/SnapshotInteractiveMode.test.js.snap b/packages/jest-core/src/__tests__/__snapshots__/SnapshotInteractiveMode.test.js.snap index 411444957a8b..02bb55489ba1 100644 --- a/packages/jest-core/src/__tests__/__snapshots__/SnapshotInteractiveMode.test.js.snap +++ b/packages/jest-core/src/__tests__/__snapshots__/SnapshotInteractiveMode.test.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`SnapshotInteractiveMode skip 1 test, then quit 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -16,7 +16,7 @@ exports[`SnapshotInteractiveMode skip 1 test, then quit 1`] = ` `; exports[`SnapshotInteractiveMode skip 1 test, then quit 2`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 1 snapshot reviewed, 1 snapshot skipped @@ -28,8 +28,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then quit 2`] = ` `; exports[`SnapshotInteractiveMode skip 1 test, then restart 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -43,7 +43,7 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 1`] = ` `; exports[`SnapshotInteractiveMode skip 1 test, then restart 2`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 1 snapshot reviewed, 1 snapshot skipped @@ -55,8 +55,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 2`] = ` `; exports[`SnapshotInteractiveMode skip 1 test, then restart 3`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -70,8 +70,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 3`] = ` `; exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 2 snapshots remaining @@ -85,8 +85,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res `; exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 2`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining, 1 snapshot skipped @@ -100,7 +100,7 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res `; exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 3`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 2 snapshots reviewed, 1 snapshot updated, 1 snapshot skipped @@ -112,8 +112,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res `; exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 4`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -127,8 +127,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res `; exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 2 snapshots remaining @@ -142,8 +142,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 1`] = ` `; exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 2`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining, 1 snapshot skipped @@ -157,7 +157,7 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 2`] = ` `; exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 3`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 2 snapshots reviewed, 2 snapshots skipped @@ -169,8 +169,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 3`] = ` `; exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 4`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 2 snapshots remaining @@ -184,8 +184,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 4`] = ` `; exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 2 snapshots remaining @@ -199,8 +199,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res `; exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 2`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining, 1 snapshot updated @@ -214,7 +214,7 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res `; exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 3`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 2 snapshots reviewed, 1 snapshot updated, 1 snapshot skipped @@ -226,8 +226,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res `; exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 4`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -241,8 +241,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res `; exports[`SnapshotInteractiveMode update 1 test, then finish and return 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining @@ -256,7 +256,7 @@ exports[`SnapshotInteractiveMode update 1 test, then finish and return 1`] = ` `; exports[`SnapshotInteractiveMode update 1 test, then finish and return 2`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 1 snapshot reviewed, 1 snapshot updated @@ -267,8 +267,8 @@ exports[`SnapshotInteractiveMode update 1 test, then finish and return 2`] = ` `; exports[`SnapshotInteractiveMode update 2 tests, then finish and return 1`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 2 snapshots remaining @@ -282,8 +282,8 @@ exports[`SnapshotInteractiveMode update 2 tests, then finish and return 1`] = ` `; exports[`SnapshotInteractiveMode update 2 tests, then finish and return 2`] = ` -"[MOCK - cursorUp] -[MOCK - eraseDown] +" + Interactive Snapshot Progress › 1 snapshot remaining, 1 snapshot updated @@ -297,7 +297,7 @@ exports[`SnapshotInteractiveMode update 2 tests, then finish and return 2`] = ` `; exports[`SnapshotInteractiveMode update 2 tests, then finish and return 3`] = ` -"[MOCK - clear] +" Interactive Snapshot Result › 2 snapshots reviewed, 2 snapshots updated diff --git a/packages/jest-core/src/__tests__/__snapshots__/watchFilenamePatternMode.test.js.snap b/packages/jest-core/src/__tests__/__snapshots__/watchFilenamePatternMode.test.js.snap index 192bd10d4b91..2dd55f418bed 100644 --- a/packages/jest-core/src/__tests__/__snapshots__/watchFilenamePatternMode.test.js.snap +++ b/packages/jest-core/src/__tests__/__snapshots__/watchFilenamePatternMode.test.js.snap @@ -1,83 +1,91 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Watch mode flows Pressing "P" enters pattern mode 1`] = ` -" - - +" + + pattern › p -[MOCK - cursorSavePosition] -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 2`] = ` -" - - +" + + pattern › p. -[MOCK - cursorSavePosition] -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 3`] = ` -" - - +" + + pattern › p.* -[MOCK - cursorSavePosition] -[MOCK - cursorTo(14, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 4`] = ` -" - - +" + + pattern › p.*1 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(15, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 5`] = ` -" - - +" + + pattern › p.*10 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(16, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 6`] = ` -" - - +" + + pattern › p.*1 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(15, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 7`] = ` -" - - +" + + pattern › p.* -[MOCK - cursorSavePosition] -[MOCK - cursorTo(14, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 8`] = ` -" - - +" + + pattern › p.*3 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(15, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "P" enters pattern mode 9`] = ` @@ -91,20 +99,21 @@ Object { `; exports[`Watch mode flows Pressing "c" clears the filters 1`] = ` -"[MOCK - cursorHide] -[MOCK - clear] +" + Pattern Mode Usage › Press Esc to exit pattern mode. › Press Enter to filter by a filenames regex pattern. -[MOCK - cursorShow] - - - + + + + pattern › -[MOCK - cursorSavePosition] -[MOCK - cursorTo(11, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; diff --git a/packages/jest-core/src/__tests__/__snapshots__/watchTestNamePatternMode.test.js.snap b/packages/jest-core/src/__tests__/__snapshots__/watchTestNamePatternMode.test.js.snap index 940258709a50..adba322360be 100644 --- a/packages/jest-core/src/__tests__/__snapshots__/watchTestNamePatternMode.test.js.snap +++ b/packages/jest-core/src/__tests__/__snapshots__/watchTestNamePatternMode.test.js.snap @@ -1,91 +1,100 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Watch mode flows Pressing "T" enters pattern mode 1`] = ` -" - - +" + + pattern › c -[MOCK - cursorSavePosition] -[MOCK - cursorTo(12, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 2`] = ` -" - - +" + + pattern › co -[MOCK - cursorSavePosition] -[MOCK - cursorTo(13, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 3`] = ` -" - - +" + + pattern › con -[MOCK - cursorSavePosition] -[MOCK - cursorTo(14, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 4`] = ` -" - - +" + + pattern › con -[MOCK - cursorSavePosition] -[MOCK - cursorTo(15, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 5`] = ` -" - - +" + + pattern › con 1 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(16, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 6`] = ` -" - - +" + + pattern › con 12 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(17, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 7`] = ` -" - - +" + + pattern › con 1 -[MOCK - cursorSavePosition] -[MOCK - cursorTo(16, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 8`] = ` -" - - +" + + pattern › con -[MOCK - cursorSavePosition] -[MOCK - cursorTo(15, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; exports[`Watch mode flows Pressing "T" enters pattern mode 9`] = ` -" - - +" + + pattern › con * -[MOCK - cursorSavePosition] -[MOCK - cursorTo(16, 5)] -[MOCK - cursorRestorePosition]" + + + +" `; diff --git a/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js b/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js index 5322e283340a..cde9694f668e 100644 --- a/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js +++ b/packages/jest-core/src/__tests__/watchFilenamePatternMode.test.js @@ -12,23 +12,6 @@ import {KEYS} from 'jest-watcher'; const runJestMock = jest.fn(); -jest - .mock('ansi-escapes', () => ({ - cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`, - cursorHide: '[MOCK - cursorHide]', - cursorRestorePosition: '[MOCK - cursorRestorePosition]', - cursorSavePosition: '[MOCK - cursorSavePosition]', - cursorShow: '[MOCK - cursorShow]', - cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`, - })) - .mock('jest-util', () => { - const {specialChars, ...util} = jest.requireActual('jest-util'); - return { - ...util, - specialChars: {...specialChars, CLEAR: '[MOCK - clear]'}, - }; - }); - jest.mock( '../SearchSource', () => diff --git a/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js b/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js index 01cb7f85a591..9c7987b0bd56 100644 --- a/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js +++ b/packages/jest-core/src/__tests__/watchTestNamePatternMode.test.js @@ -12,23 +12,6 @@ import {KEYS} from 'jest-watcher'; const runJestMock = jest.fn(); -jest - .mock('ansi-escapes', () => ({ - cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`, - cursorHide: '[MOCK - cursorHide]', - cursorRestorePosition: '[MOCK - cursorRestorePosition]', - cursorSavePosition: '[MOCK - cursorSavePosition]', - cursorShow: '[MOCK - cursorShow]', - cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`, - })) - .mock('jest-util', () => { - const {specialChars, ...util} = jest.requireActual('jest-util'); - return { - ...util, - specialChars: {...specialChars, CLEAR: '[MOCK - clear]'}, - }; - }); - jest.mock( '../SearchSource', () => diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/utils.test.ts.snap b/packages/jest-reporters/src/__tests__/__snapshots__/utils.test.ts.snap index aea8ba842e74..5196a773223b 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/utils.test.ts.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/utils.test.ts.snap @@ -31,8 +31,8 @@ hththththt hthththtet etetetette tetetetete -tetetestnh -snthsnthss +tetetestnh +snthsnthss ot" `; diff --git a/yarn.lock b/yarn.lock index 358bb323b13f..3277d69b5b63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2712,6 +2712,7 @@ __metadata: jest-junit: ^13.0.0 jest-mock: "workspace:*" jest-runner-tsd: ^3.1.0 + jest-serializer-ansi-escapes: ^1.0.0 jest-silent-reporter: ^0.5.0 jest-snapshot: "workspace:*" jest-watch-typeahead: ^1.1.0 @@ -13646,6 +13647,13 @@ __metadata: languageName: unknown linkType: soft +"jest-serializer-ansi-escapes@npm:^1.0.0": + version: 1.0.1 + resolution: "jest-serializer-ansi-escapes@npm:1.0.1" + checksum: 9cf71b090d27b45a7237247feebb556c474cafc52d12c0e5c49b08a5b871dec6046a83343e148eb607f2e6eb901513946347c08708ff35b0daf514085d599c65 + languageName: node + linkType: hard + "jest-serializer@npm:^27.5.1": version: 27.5.1 resolution: "jest-serializer@npm:27.5.1"