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

chore: replace pretty-format/ConvertAnsi with jest-serializer-ansi-escapes #12935

Merged
merged 4 commits into from
Jul 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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
Expand Down
70 changes: 56 additions & 14 deletions e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can press "p" to filter by file name 1`] = `

"<hideCursor>
<clearTerminal>
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



<showCursor>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern ›
<saveCursorPosition>
<moveCursorToRow6Column12>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern › b
<saveCursorPosition>
<moveCursorToRow6Column13>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern › ba
<saveCursorPosition>
<moveCursorToRow6Column14>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern › bar
<saveCursorPosition>
<moveCursorToRow6Column15>
<restoreCursorPosition>

<moveCursorDownBy1Row>
<eraseScreenDown>
"
`;

exports[`can press "p" to filter by file name: test results 1`] = `
Expand Down Expand Up @@ -43,16 +70,31 @@ Ran all test suites matching /bar/i."
`;

exports[`can press "t" to filter by test name 1`] = `

"<hideCursor>
<clearTerminal>
Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to filter by a tests regex pattern.

pattern › 
pattern › 2



<showCursor>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern ›
<saveCursorPosition>
<moveCursorToRow6Column12>
<restoreCursorPosition>
<eraseLine>
<moveCursorToColumn1>
<eraseScreenDown>
pattern › 2
<saveCursorPosition>
<moveCursorToRow6Column13>
<restoreCursorPosition>

<moveCursorDownBy1Row>
<eraseScreenDown>
"
`;

exports[`can press "t" to filter by test name: test results 1`] = `
Expand Down
5 changes: 0 additions & 5 deletions e2e/__tests__/watchModeOnlyFailed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>}>) => {
writeFiles(DIR, {
'__tests__/bar.spec.js': `
Expand Down
5 changes: 0 additions & 5 deletions e2e/__tests__/watchModePatterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>}>) => {
writeFiles(DIR, {
'__tests__/bar.spec.js': `
Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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__/',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 0 additions & 17 deletions packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SnapshotInteractiveMode skip 1 test, then quit 1`] = `
"[MOCK - cursorUp]
[MOCK - eraseDown]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -16,7 +16,7 @@ exports[`SnapshotInteractiveMode skip 1 test, then quit 1`] = `
`;

exports[`SnapshotInteractiveMode skip 1 test, then quit 2`] = `
"[MOCK - clear]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>1 snapshot reviewed</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -28,8 +28,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then quit 2`] = `
`;

exports[`SnapshotInteractiveMode skip 1 test, then restart 1`] = `
"[MOCK - cursorUp]
[MOCK - eraseDown]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -43,7 +43,7 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 1`] = `
`;

exports[`SnapshotInteractiveMode skip 1 test, then restart 2`] = `
"[MOCK - clear]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>1 snapshot reviewed</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -55,8 +55,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 2`] = `
`;

exports[`SnapshotInteractiveMode skip 1 test, then restart 3`] = `
"[MOCK - cursorUp]
[MOCK - eraseDown]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>2 snapshots remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -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]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>2 snapshots reviewed</></>, <bold><green>1 snapshot updated</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>2 snapshots remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -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]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>2 snapshots reviewed</></>, <bold><yellow>2 snapshots skipped</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>2 snapshots remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>2 snapshots remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>, <bold><green>1 snapshot updated</></>
Expand All @@ -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]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>2 snapshots reviewed</></>, <bold><green>1 snapshot updated</></>, <bold><yellow>1 snapshot skipped</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>
Expand All @@ -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]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>1 snapshot reviewed</></>, <bold><green>1 snapshot updated</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>2 snapshots remaining</></>
Expand All @@ -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]
"<moveCursorUpBy6Rows>
<eraseScreenDown>

<bold>Interactive Snapshot Progress</>
› <bold><dim>1 snapshot remaining</></>, <bold><green>1 snapshot updated</></>
Expand All @@ -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]
"<clearTerminal>

<bold>Interactive Snapshot Result</>
› <bold><dim>2 snapshots reviewed</></>, <bold><green>2 snapshots updated</></>
Expand Down
Loading