Skip to content

Commit 7775f0f

Browse files
authored
fix: should not expand diff by default (#516)
1 parent 1f56679 commit 7775f0f

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

e2e/snapshot/diff.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { dirname } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { expect, it } from '@rstest/core';
4+
import { runRstestCli } from '../scripts';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
it('should show diff as expected', async () => {
10+
const { cli } = await runRstestCli({
11+
command: 'rstest',
12+
args: ['run', 'fixtures/diff.test.ts'],
13+
options: {
14+
nodeOptions: {
15+
cwd: __dirname,
16+
},
17+
},
18+
});
19+
20+
await cli.exec;
21+
expect(cli.exec.process?.exitCode).toBe(1);
22+
23+
const logs = cli.stdout.split('\n').filter(Boolean);
24+
25+
expect(logs.length).toBeLessThan(100);
26+
expect(logs.find((log) => log.includes('- 99"'))).toBeTruthy();
27+
expect(logs.find((log) => log.includes('+ 100"'))).toBeTruthy();
28+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Rstest Snapshot v1
2+
3+
exports[`test snapshot > should failed when snapshot unmatched 1`] = `
4+
"
5+
0
6+
1
7+
2
8+
3
9+
4
10+
5
11+
6
12+
7
13+
8
14+
9
15+
10
16+
11
17+
12
18+
13
19+
14
20+
15
21+
16
22+
17
23+
18
24+
19
25+
20
26+
21
27+
22
28+
23
29+
24
30+
25
31+
26
32+
27
33+
28
34+
29
35+
30
36+
31
37+
32
38+
33
39+
34
40+
35
41+
36
42+
37
43+
38
44+
39
45+
40
46+
41
47+
42
48+
43
49+
44
50+
45
51+
46
52+
47
53+
48
54+
49
55+
50
56+
51
57+
52
58+
53
59+
54
60+
55
61+
56
62+
57
63+
58
64+
59
65+
60
66+
61
67+
62
68+
63
69+
64
70+
65
71+
66
72+
67
73+
68
74+
69
75+
70
76+
71
77+
72
78+
73
79+
74
80+
75
81+
76
82+
77
83+
78
84+
79
85+
80
86+
81
87+
82
88+
83
89+
84
90+
85
91+
86
92+
87
93+
88
94+
89
95+
90
96+
91
97+
92
98+
93
99+
94
100+
95
101+
96
102+
97
103+
98
104+
99"
105+
`;

e2e/snapshot/fixtures/diff.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from '@rstest/core';
2+
3+
describe('test snapshot', () => {
4+
it('should failed when snapshot unmatched', () => {
5+
let content = '';
6+
7+
for (let i = 0; i < 101; i++) {
8+
content += `
9+
${i}`;
10+
}
11+
12+
expect(content).toMatchSnapshot();
13+
});
14+
});

packages/core/src/runtime/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export const formatTestError = (err: any, test?: Test): FormattedError[] => {
3737
error.expected !== undefined &&
3838
error.actual !== undefined)
3939
) {
40-
errObj.diff = diff(err.expected, err.actual)!;
40+
errObj.diff = diff(err.expected, err.actual, {
41+
expand: false,
42+
})!;
4143
}
4244

4345
for (const key of ['actual', 'expected'] as const) {

0 commit comments

Comments
 (0)