Skip to content

Commit fd4bfbd

Browse files
authoredJul 7, 2022
chore: replace pretty-format/ConvertAnsi with jest-serializer-ansi-escapes (#12935)
1 parent 312d3a9 commit fd4bfbd

14 files changed

+236
-226
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
### Chore & Maintenance
1414

15+
- `[*]` Replace internal usage of `pretty-format/ConvertAnsi` with `jest-serializer-ansi-escapes` ([#12935](https://github.com/facebook/jest/pull/12935))
16+
1517
### Performance
1618

1719
## 28.1.2

‎e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap

+56-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`can press "p" to filter by file name 1`] = `
4-
4+
"<hideCursor>
5+
<clearTerminal>
56
Pattern Mode Usage
67
› Press Esc to exit pattern mode.
78
› Press Enter to filter by a filenames regex pattern.
89
9-
pattern › 
10-
pattern › b
11-
pattern › ba
12-
pattern › bar
13-
14-
15-
10+
<showCursor>
11+
<eraseLine>
12+
<moveCursorToColumn1>
13+
<eraseScreenDown>
14+
pattern ›
15+
<saveCursorPosition>
16+
<moveCursorToRow6Column12>
17+
<restoreCursorPosition>
18+
<eraseLine>
19+
<moveCursorToColumn1>
20+
<eraseScreenDown>
21+
pattern › b
22+
<saveCursorPosition>
23+
<moveCursorToRow6Column13>
24+
<restoreCursorPosition>
25+
<eraseLine>
26+
<moveCursorToColumn1>
27+
<eraseScreenDown>
28+
pattern › ba
29+
<saveCursorPosition>
30+
<moveCursorToRow6Column14>
31+
<restoreCursorPosition>
32+
<eraseLine>
33+
<moveCursorToColumn1>
34+
<eraseScreenDown>
35+
pattern › bar
36+
<saveCursorPosition>
37+
<moveCursorToRow6Column15>
38+
<restoreCursorPosition>
39+
40+
<moveCursorDownBy1Row>
41+
<eraseScreenDown>
42+
"
1643
`;
1744
1845
exports[`can press "p" to filter by file name: test results 1`] = `
@@ -43,16 +70,31 @@ Ran all test suites matching /bar/i."
4370
`;
4471
4572
exports[`can press "t" to filter by test name 1`] = `
46-
73+
"<hideCursor>
74+
<clearTerminal>
4775
Pattern Mode Usage
4876
› Press Esc to exit pattern mode.
4977
› Press Enter to filter by a tests regex pattern.
5078
51-
pattern › 
52-
pattern › 2
53-
54-
55-
79+
<showCursor>
80+
<eraseLine>
81+
<moveCursorToColumn1>
82+
<eraseScreenDown>
83+
pattern ›
84+
<saveCursorPosition>
85+
<moveCursorToRow6Column12>
86+
<restoreCursorPosition>
87+
<eraseLine>
88+
<moveCursorToColumn1>
89+
<eraseScreenDown>
90+
pattern › 2
91+
<saveCursorPosition>
92+
<moveCursorToRow6Column13>
93+
<restoreCursorPosition>
94+
95+
<moveCursorDownBy1Row>
96+
<eraseScreenDown>
97+
"
5698
`;
5799
58100
exports[`can press "t" to filter by test name: test results 1`] = `

‎e2e/__tests__/watchModeOnlyFailed.test.ts

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ const pluginPath = path.resolve(__dirname, '../MockStdinWatchPlugin');
1616
beforeEach(() => cleanup(DIR));
1717
afterAll(() => cleanup(DIR));
1818

19-
expect.addSnapshotSerializer({
20-
print: val => (val as string).replace(/\[s\[u/g, '\n'),
21-
test: val => typeof val === 'string' && val.includes('[s'),
22-
});
23-
2419
const setupFiles = (input: Array<{keys: Array<string>}>) => {
2520
writeFiles(DIR, {
2621
'__tests__/bar.spec.js': `

‎e2e/__tests__/watchModePatterns.test.ts

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ const pluginPath = path.resolve(__dirname, '../MockStdinWatchPlugin');
1616
beforeEach(() => cleanup(DIR));
1717
afterAll(() => cleanup(DIR));
1818

19-
expect.addSnapshotSerializer({
20-
print: val => (val as string).replace(/\[s\[u/g, '\n'),
21-
test: val => typeof val === 'string' && val.includes('[s'),
22-
});
23-
2419
const setupFiles = (input: Array<{keys: Array<string>}>) => {
2520
writeFiles(DIR, {
2621
'__tests__/bar.spec.js': `

‎jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
snapshotFormat: {
3636
escapeString: false,
3737
},
38-
snapshotSerializers: [require.resolve('pretty-format/ConvertAnsi')],
38+
snapshotSerializers: [require.resolve('jest-serializer-ansi-escapes')],
3939
testPathIgnorePatterns: [
4040
'/__arbitraries__/',
4141
'/__benchmarks__/',

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"jest-junit": "^13.0.0",
5656
"jest-mock": "workspace:*",
5757
"jest-runner-tsd": "^3.1.0",
58+
"jest-serializer-ansi-escapes": "^1.0.0",
5859
"jest-silent-reporter": "^0.5.0",
5960
"jest-snapshot": "workspace:*",
6061
"jest-watch-typeahead": "^1.1.0",

‎packages/jest-core/src/__tests__/SnapshotInteractiveMode.test.js

-17
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@ import chalk from 'chalk';
99
import {KEYS} from 'jest-watcher';
1010
import SnapshotInteractiveMode from '../SnapshotInteractiveMode';
1111

12-
jest
13-
.mock('ansi-escapes', () => ({
14-
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
15-
cursorSavePosition: '[MOCK - cursorSavePosition]',
16-
cursorScrollDown: '[MOCK - cursorScrollDown]',
17-
cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`,
18-
cursorUp: () => '[MOCK - cursorUp]',
19-
eraseDown: '[MOCK - eraseDown]',
20-
}))
21-
.mock('jest-util', () => {
22-
const {specialChars, ...util} = jest.requireActual('jest-util');
23-
return {
24-
...util,
25-
specialChars: {...specialChars, CLEAR: '[MOCK - clear]'},
26-
};
27-
});
28-
2912
jest.doMock('chalk', () =>
3013
Object.assign(new chalk.Instance({level: 0}), {
3114
stripColor: str => str,

‎packages/jest-core/src/__tests__/__snapshots__/SnapshotInteractiveMode.test.js.snap

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

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

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

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

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

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

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

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

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

6161
<bold>Interactive Snapshot Progress</>
6262
› <bold><dim>1 snapshot remaining</></>
@@ -70,8 +70,8 @@ exports[`SnapshotInteractiveMode skip 1 test, then restart 3`] = `
7070
`;
7171

7272
exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 1`] = `
73-
"[MOCK - cursorUp]
74-
[MOCK - eraseDown]
73+
"<moveCursorUpBy6Rows>
74+
<eraseScreenDown>
7575

7676
<bold>Interactive Snapshot Progress</>
7777
› <bold><dim>2 snapshots remaining</></>
@@ -85,8 +85,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res
8585
`;
8686

8787
exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 2`] = `
88-
"[MOCK - cursorUp]
89-
[MOCK - eraseDown]
88+
"<moveCursorUpBy6Rows>
89+
<eraseScreenDown>
9090

9191
<bold>Interactive Snapshot Progress</>
9292
› <bold><dim>1 snapshot remaining</></>, <bold><yellow>1 snapshot skipped</></>
@@ -100,7 +100,7 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res
100100
`;
101101

102102
exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 3`] = `
103-
"[MOCK - clear]
103+
"<clearTerminal>
104104

105105
<bold>Interactive Snapshot Result</>
106106
› <bold><dim>2 snapshots reviewed</></>, <bold><green>1 snapshot updated</></>, <bold><yellow>1 snapshot skipped</></>
@@ -112,8 +112,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res
112112
`;
113113

114114
exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and restart 4`] = `
115-
"[MOCK - cursorUp]
116-
[MOCK - eraseDown]
115+
"<moveCursorUpBy6Rows>
116+
<eraseScreenDown>
117117

118118
<bold>Interactive Snapshot Progress</>
119119
› <bold><dim>1 snapshot remaining</></>
@@ -127,8 +127,8 @@ exports[`SnapshotInteractiveMode skip 1 test, update 1 test, then finish and res
127127
`;
128128

129129
exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 1`] = `
130-
"[MOCK - cursorUp]
131-
[MOCK - eraseDown]
130+
"<moveCursorUpBy6Rows>
131+
<eraseScreenDown>
132132

133133
<bold>Interactive Snapshot Progress</>
134134
› <bold><dim>2 snapshots remaining</></>
@@ -142,8 +142,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 1`] = `
142142
`;
143143

144144
exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 2`] = `
145-
"[MOCK - cursorUp]
146-
[MOCK - eraseDown]
145+
"<moveCursorUpBy6Rows>
146+
<eraseScreenDown>
147147

148148
<bold>Interactive Snapshot Progress</>
149149
› <bold><dim>1 snapshot remaining</></>, <bold><yellow>1 snapshot skipped</></>
@@ -157,7 +157,7 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 2`] = `
157157
`;
158158

159159
exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 3`] = `
160-
"[MOCK - clear]
160+
"<clearTerminal>
161161

162162
<bold>Interactive Snapshot Result</>
163163
› <bold><dim>2 snapshots reviewed</></>, <bold><yellow>2 snapshots skipped</></>
@@ -169,8 +169,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 3`] = `
169169
`;
170170

171171
exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 4`] = `
172-
"[MOCK - cursorUp]
173-
[MOCK - eraseDown]
172+
"<moveCursorUpBy6Rows>
173+
<eraseScreenDown>
174174

175175
<bold>Interactive Snapshot Progress</>
176176
› <bold><dim>2 snapshots remaining</></>
@@ -184,8 +184,8 @@ exports[`SnapshotInteractiveMode skip 2 tests, then finish and restart 4`] = `
184184
`;
185185

186186
exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 1`] = `
187-
"[MOCK - cursorUp]
188-
[MOCK - eraseDown]
187+
"<moveCursorUpBy6Rows>
188+
<eraseScreenDown>
189189

190190
<bold>Interactive Snapshot Progress</>
191191
› <bold><dim>2 snapshots remaining</></>
@@ -199,8 +199,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res
199199
`;
200200

201201
exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 2`] = `
202-
"[MOCK - cursorUp]
203-
[MOCK - eraseDown]
202+
"<moveCursorUpBy6Rows>
203+
<eraseScreenDown>
204204

205205
<bold>Interactive Snapshot Progress</>
206206
› <bold><dim>1 snapshot remaining</></>, <bold><green>1 snapshot updated</></>
@@ -214,7 +214,7 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res
214214
`;
215215

216216
exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 3`] = `
217-
"[MOCK - clear]
217+
"<clearTerminal>
218218

219219
<bold>Interactive Snapshot Result</>
220220
› <bold><dim>2 snapshots reviewed</></>, <bold><green>1 snapshot updated</></>, <bold><yellow>1 snapshot skipped</></>
@@ -226,8 +226,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res
226226
`;
227227

228228
exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and restart 4`] = `
229-
"[MOCK - cursorUp]
230-
[MOCK - eraseDown]
229+
"<moveCursorUpBy6Rows>
230+
<eraseScreenDown>
231231

232232
<bold>Interactive Snapshot Progress</>
233233
› <bold><dim>1 snapshot remaining</></>
@@ -241,8 +241,8 @@ exports[`SnapshotInteractiveMode update 1 test, skip 1 test, then finish and res
241241
`;
242242

243243
exports[`SnapshotInteractiveMode update 1 test, then finish and return 1`] = `
244-
"[MOCK - cursorUp]
245-
[MOCK - eraseDown]
244+
"<moveCursorUpBy6Rows>
245+
<eraseScreenDown>
246246

247247
<bold>Interactive Snapshot Progress</>
248248
› <bold><dim>1 snapshot remaining</></>
@@ -256,7 +256,7 @@ exports[`SnapshotInteractiveMode update 1 test, then finish and return 1`] = `
256256
`;
257257

258258
exports[`SnapshotInteractiveMode update 1 test, then finish and return 2`] = `
259-
"[MOCK - clear]
259+
"<clearTerminal>
260260

261261
<bold>Interactive Snapshot Result</>
262262
› <bold><dim>1 snapshot reviewed</></>, <bold><green>1 snapshot updated</></>
@@ -267,8 +267,8 @@ exports[`SnapshotInteractiveMode update 1 test, then finish and return 2`] = `
267267
`;
268268

269269
exports[`SnapshotInteractiveMode update 2 tests, then finish and return 1`] = `
270-
"[MOCK - cursorUp]
271-
[MOCK - eraseDown]
270+
"<moveCursorUpBy6Rows>
271+
<eraseScreenDown>
272272

273273
<bold>Interactive Snapshot Progress</>
274274
› <bold><dim>2 snapshots remaining</></>
@@ -282,8 +282,8 @@ exports[`SnapshotInteractiveMode update 2 tests, then finish and return 1`] = `
282282
`;
283283

284284
exports[`SnapshotInteractiveMode update 2 tests, then finish and return 2`] = `
285-
"[MOCK - cursorUp]
286-
[MOCK - eraseDown]
285+
"<moveCursorUpBy6Rows>
286+
<eraseScreenDown>
287287

288288
<bold>Interactive Snapshot Progress</>
289289
› <bold><dim>1 snapshot remaining</></>, <bold><green>1 snapshot updated</></>
@@ -297,7 +297,7 @@ exports[`SnapshotInteractiveMode update 2 tests, then finish and return 2`] = `
297297
`;
298298

299299
exports[`SnapshotInteractiveMode update 2 tests, then finish and return 3`] = `
300-
"[MOCK - clear]
300+
"<clearTerminal>
301301

302302
<bold>Interactive Snapshot Result</>
303303
› <bold><dim>2 snapshots reviewed</></>, <bold><green>2 snapshots updated</></>

0 commit comments

Comments
 (0)
Please sign in to comment.