Skip to content

Commit c1d538f

Browse files
[test optimization] Make EFD and impacted tests compatible with jest's snapshot testing (#6584)
1 parent 2c9beca commit c1d538f

19 files changed

+748
-162
lines changed
68 Bytes
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`parallel snapshot can do multiple snapshots 1`] = `"hello"`;
4+
exports[`parallel snapshot can do multiple snapshots 2`] = `"good bye"`;
5+
exports[`parallel snapshot can do multiple snapshots in a different test 1`] = `3`
6+
exports[`parallel snapshot can do multiple snapshots in a different test 2`] = `4`
7+
exports[`parallel snapshot is not new 1`] = `"yes"`
8+
exports[`parallel snapshot is not new 2`] = `"no"`
9+
exports[`parallel snapshot is flaky 1`] = `3`
10+
exports[`parallel snapshot is flaky 2`] = `"a"`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`parallel snapshot 2 can do multiple snapshots 1`] = `"hello"`;
4+
exports[`parallel snapshot 2 can do multiple snapshots 2`] = `"good bye"`;
5+
exports[`parallel snapshot 2 can do multiple snapshots in a different test 1`] = `3`
6+
exports[`parallel snapshot 2 can do multiple snapshots in a different test 2`] = `4`
7+
exports[`parallel snapshot 2 is not new 1`] = `"yes"`
8+
exports[`parallel snapshot 2 is not new 2`] = `"no"`
9+
exports[`parallel snapshot 2 is flaky 1`] = `3`
10+
exports[`parallel snapshot 2 is flaky 2`] = `"a"`
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`test can do snapshot 1`] = `3`;
3+
exports[`test can do multiple snapshots 1`] = `"hello"`;
4+
exports[`test can do multiple snapshots 2`] = `"good bye"`;
5+
exports[`test can do multiple snapshots in a different test 1`] = `3`
6+
exports[`test can do multiple snapshots in a different test 2`] = `4`
7+
exports[`test is not new 1`] = `"yes"`
8+
exports[`test is not new 2`] = `"no"`
9+
exports[`test is flaky 1`] = `3`
10+
exports[`test is flaky 2`] = `"a"`
11+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
const { toMatchImageSnapshot } = require('jest-image-snapshot')
4+
5+
expect.extend({ toMatchImageSnapshot })
6+
7+
let retryCounter = 0
8+
describe('snapshot', () => {
9+
it('can match', () => {
10+
// This is a base64 encoded 1x1 transparent PNG image with correct CRC32 checksums
11+
const b64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR4nGNgAAIAAAUAAXpeqz8AAAAASUVORK5CYII='
12+
const img = Buffer.from(b64, 'base64')
13+
14+
const b64Wrong = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
15+
const wrongImage = Buffer.from(b64Wrong, 'base64') // Different 1x1 image
16+
17+
if (++retryCounter > 2) {
18+
expect(img).toMatchImageSnapshot()
19+
} else {
20+
expect(wrongImage).toMatchImageSnapshot()
21+
}
22+
})
23+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
3+
let retryCounter = 0
4+
5+
describe('parallel snapshot', () => {
6+
it('can do multiple snapshots', () => {
7+
expect('hello').toMatchSnapshot()
8+
9+
expect('good bye').toMatchSnapshot()
10+
})
11+
12+
it('can do multiple snapshots in a different test', () => {
13+
expect(1 + 2).toMatchSnapshot()
14+
15+
expect(1 + 3).toMatchSnapshot()
16+
})
17+
18+
it('is not new', () => {
19+
expect('yes').toMatchSnapshot()
20+
expect('no').toMatchSnapshot()
21+
})
22+
23+
it('has inline snapshot', () => {
24+
expect('yes').toMatchInlineSnapshot('"yes"')
25+
expect('no').toMatchInlineSnapshot('"no"')
26+
})
27+
28+
it('has snapshot and is known', () => {
29+
expect('yes').toMatchInlineSnapshot('"yes"')
30+
expect('no').toMatchInlineSnapshot('"no"')
31+
})
32+
33+
it('is flaky', () => {
34+
retryCounter++
35+
const sum = retryCounter > 2 ? 3 : 4
36+
if (retryCounter > 2) {
37+
expect(sum).toMatchSnapshot()
38+
} else {
39+
expect(sum).toMatchSnapshot()
40+
}
41+
expect('a').toMatchSnapshot()
42+
})
43+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
3+
let retryCounter = 0
4+
5+
describe('parallel snapshot 2', () => {
6+
it('can do multiple snapshots', () => {
7+
expect('hello').toMatchSnapshot()
8+
9+
expect('good bye').toMatchSnapshot()
10+
})
11+
12+
it('can do multiple snapshots in a different test', () => {
13+
expect(1 + 2).toMatchSnapshot()
14+
15+
expect(1 + 3).toMatchSnapshot()
16+
})
17+
18+
it('is not new', () => {
19+
expect('yes').toMatchSnapshot()
20+
expect('no').toMatchSnapshot()
21+
})
22+
23+
it('has inline snapshot', () => {
24+
expect('yes').toMatchInlineSnapshot('"yes"')
25+
expect('no').toMatchInlineSnapshot('"no"')
26+
})
27+
28+
it('has snapshot and is known', () => {
29+
expect('yes').toMatchInlineSnapshot('"yes"')
30+
expect('no').toMatchInlineSnapshot('"no"')
31+
})
32+
33+
it('is flaky', () => {
34+
retryCounter++
35+
const sum = retryCounter > 2 ? 3 : 4
36+
if (retryCounter > 2) {
37+
expect(sum).toMatchSnapshot()
38+
} else {
39+
expect(sum).toMatchSnapshot()
40+
}
41+
expect('a').toMatchSnapshot()
42+
})
43+
})
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
'use strict'
22

3+
let retryCounter = 0
4+
35
describe('test', () => {
4-
it('can do snapshot', () => {
6+
it('can do multiple snapshots', () => {
7+
expect('hello').toMatchSnapshot()
8+
9+
expect('good bye').toMatchSnapshot()
10+
})
11+
12+
it('can do multiple snapshots in a different test', () => {
513
expect(1 + 2).toMatchSnapshot()
14+
15+
expect(1 + 3).toMatchSnapshot()
16+
})
17+
18+
it('is not new', () => {
19+
expect('yes').toMatchSnapshot()
20+
expect('no').toMatchSnapshot()
21+
})
22+
23+
it('has inline snapshot', () => {
24+
expect('yes').toMatchInlineSnapshot('"yes"')
25+
expect('no').toMatchInlineSnapshot('"no"')
26+
})
27+
28+
it('has snapshot and is known', () => {
29+
expect('yes').toMatchInlineSnapshot('"yes"')
30+
expect('no').toMatchInlineSnapshot('"no"')
31+
})
32+
33+
it('is flaky', () => {
34+
retryCounter++
35+
const sum = retryCounter > 2 ? 3 : 4
36+
if (retryCounter > 2) {
37+
expect(sum).toMatchSnapshot()
38+
} else {
39+
expect(sum).toMatchSnapshot()
40+
}
41+
expect('a').toMatchSnapshot()
642
})
743
})
68 Bytes
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`attempt to fix snapshot is flaky 1`] = `3`
4+
exports[`attempt to fix snapshot is flaky 2`] = `"a"`

0 commit comments

Comments
 (0)