Skip to content

Commit bcb750c

Browse files
committed
snapshot() assertion no longer works in hooks
Fixes #2534.
1 parent 7f64f5c commit bcb750c

File tree

9 files changed

+16
-165
lines changed

9 files changed

+16
-165
lines changed

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class Assertions {
699699
});
700700

701701
this.snapshot = withSkip((expected, ...rest) => {
702-
if (disableSnapshots && experiments.disableSnapshotsInHooks) {
702+
if (disableSnapshots) {
703703
fail(new AssertionError({
704704
assertion: 'snapshot',
705705
message: '`t.snapshot()` can only be used in tests',

lib/load-config.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const pkgConf = require('pkg-conf');
99
const NO_SUCH_FILE = Symbol('no ava.config.js file');
1010
const MISSING_DEFAULT_EXPORT = Symbol('missing default export');
1111
const EXPERIMENTS = new Set([
12-
'disableSnapshotsInHooks',
1312
'nextGenConfig',
1413
'reverseTeardowns',
1514
'sharedWorkers'
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
2-
"ava": {
3-
"files": [
4-
"*.js"
5-
],
6-
"nonSemVerExperiments": {
7-
"disableSnapshotsInHooks": true
8-
}
9-
}
2+
"ava": {
3+
"files": [
4+
"*.js"
5+
]
6+
}
107
}

test/snapshot-order/fixtures/randomness/test.js

-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@ const randomDelay = () => new Promise(resolve => {
55
setTimeout(resolve, Math.random() * 1000);
66
});
77

8-
test.before(async t => {
9-
await randomDelay();
10-
t.snapshot(id(-2), 'in a before hook');
11-
});
12-
13-
test.beforeEach(async t => {
14-
await randomDelay();
15-
t.snapshot(id(-1.5), 'in a beforeEach hook');
16-
});
17-
18-
test.afterEach(async t => {
19-
await randomDelay();
20-
t.snapshot(id(-1), 'in an afterEach hook');
21-
});
22-
23-
test.afterEach.always(async t => {
24-
await randomDelay();
25-
t.snapshot(id(-0.5), 'in an afterEachAlways hook');
26-
});
27-
288
test('B - declare some snapshots', async t => {
299
await randomDelay();
3010
t.snapshot(id(0));

test/snapshot-order/fixtures/randomness/test.js.md

-96
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,6 @@ The actual snapshot is saved in `test.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7-
## before hook
8-
9-
> in a before hook
10-
11-
'index: -2'
12-
13-
## beforeEach hook for B - declare some snapshots
14-
15-
> in a beforeEach hook
16-
17-
'index: -1.5'
18-
19-
## beforeEach hook for A - declare some more snapshots
20-
21-
> in a beforeEach hook
22-
23-
'index: -1.5'
24-
25-
## beforeEach hook for C - declare some snapshots in a try()
26-
27-
> in a beforeEach hook
28-
29-
'index: -1.5'
30-
31-
## beforeEach hook for E - discard some snapshots in a try()
32-
33-
> in a beforeEach hook
34-
35-
'index: -1.5'
36-
37-
## beforeEach hook for D - more snapshots with IDs
38-
39-
> in a beforeEach hook
40-
41-
'index: -1.5'
42-
43-
## afterEach hook for B - declare some snapshots
44-
45-
> in an afterEach hook
46-
47-
'index: -1'
48-
49-
## afterEach hook for A - declare some more snapshots
50-
51-
> in an afterEach hook
52-
53-
'index: -1'
54-
55-
## afterEach hook for C - declare some snapshots in a try()
56-
57-
> in an afterEach hook
58-
59-
'index: -1'
60-
61-
## afterEach hook for E - discard some snapshots in a try()
62-
63-
> in an afterEach hook
64-
65-
'index: -1'
66-
67-
## afterEach hook for D - more snapshots with IDs
68-
69-
> in an afterEach hook
70-
71-
'index: -1'
72-
73-
## afterEach.always hook for B - declare some snapshots
74-
75-
> in an afterEachAlways hook
76-
77-
'index: -0.5'
78-
79-
## afterEach.always hook for A - declare some more snapshots
80-
81-
> in an afterEachAlways hook
82-
83-
'index: -0.5'
84-
85-
## afterEach.always hook for C - declare some snapshots in a try()
86-
87-
> in an afterEachAlways hook
88-
89-
'index: -0.5'
90-
91-
## afterEach.always hook for E - discard some snapshots in a try()
92-
93-
> in an afterEachAlways hook
94-
95-
'index: -0.5'
96-
97-
## afterEach.always hook for D - more snapshots with IDs
98-
99-
> in an afterEachAlways hook
100-
101-
'index: -0.5'
102-
1037
## B - declare some snapshots
1048

1059
> Snapshot 1
-395 Bytes
Binary file not shown.

test/snapshot-order/fixtures/report-declaration-order/test.js

-16
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@ const test = require('ava');
22

33
const id = index => `index: ${index}`;
44

5-
test.before(t => {
6-
t.snapshot(id(-2), 'in a before hook');
7-
});
8-
9-
test.beforeEach(t => {
10-
t.snapshot(id(-1.5), 'in a beforeEach hook');
11-
});
12-
13-
test.afterEach(t => {
14-
t.snapshot(id(-1), 'in an afterEach hook');
15-
});
16-
17-
test.afterEach.always(t => {
18-
t.snapshot(id(-0.5), 'in an afterEachAlways hook');
19-
});
20-
215
test('B - declare some snapshots', t => {
226
t.snapshot(id(0));
237
t.snapshot(id(1), 'has a message');

test/snapshot-order/snapshots/randomness.js.md

+10-23
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,14 @@ Generated by [AVA](https://avajs.dev).
99
> resulting snapshot in binary encoding
1010
1111
Buffer @Uint8Array [
12-
41564120 536e6170 73686f74 2076320a 020019c4 186451f5 248fc7d2 9bc1c0e4
13-
9b6a1f8b 08000000 00000003 5bc6c4c0 20c1c0f0 66f53aff 9b6187ad 7ef5c6ab
14-
69395f66 64000171 2096889b cea1f1e9 cc6abe6a 8e3f7d1f 986418c1 a27a402c
15-
f92db345 dc7c62a0 c041a66b d91bd7ef 64048bba 02b1aac3 da1d160f fc2bce6e
16-
2c0e6758 7caf8611 2c1a0792 79f85f47 95e7679d 64a4c26c 05cd09a5 8c60d152
17-
20d660e4 5eb73253 60dffb96 e3159d5a 47bf3182 45fb80d8 dae87dec d21fce25
18-
a16953cf ed927c7c 9f112cba 1c886d8a c3372ce4 345bbcf8 7ee9e682 a52fa731
19-
82450f80 640e7f35 58673293 ad63ff91 8f6c1d69 b719c1a2 3781384c 37e7c7ff
20-
f90717b9 44cd5ee3 cd709e8b 112cfa09 8823fc12 73fd7cad 27c83e5c ea6e79d9
21-
df9b112c ca0d0c8a d8d04fa2 b5e55b9e dd7f7a6d 5b7b9946 22235854 1188e3d7
22-
de5d29f8 9edd4fae fbdaa4dc 33acff98 c1a2e650 ec0bc5c9 409ce62a 6725c693
23-
a66d716f fe29dbe3 0b0e3282 458141c3 90f9a478 bf83ee83 7ba6775e ad991632
24-
e5192358 742a1097 ce5b9b6a c12dc2a7 cef5532a 8525f52a 23587435 10371dd0
25-
7efe5874 b1e8c4fd cc9167de cfdcc508 163d04c4 93ac7e68 78dc5d7c c794a9d1
26-
f95ba6de 0346b0e8 4d209ebc ffafc6d4 57fce1e5 e1378236 6d5c15c8 0416fd00
27-
c5ecc074 70c995f9 e6ee835b 535b27ae a8dad95b a4cb0416 95856213 908a33cf
28-
6d74158e 32ae2ae8 cc37f936 7d292358 d41b885f da3eac39 e977af69 a6fda7b0
29-
e70a8c9e 8c60d114 20fe2230 5fdde7e0 7cfb673e 8fc5773e d0ef6006 8b5641f1
30-
04285e06 c4bfbeda 79ee3a24 7cb8f998 d876d6f3 071918c1 a27b8198 99811d9c
31-
22195919 04193933 f352522b ac14740d 49113634 4111e686 a936d033 c56e8c11
32-
71eae112 86b82448 d741b404 0754c204 ab2876b5 665845cd 29743bcc 1c63ec81
33-
4f5a5419 611736c6 6aa30576 c506c4d8 88d39f30 c30db08a 1a6215c5 ee6a5d43
34-
00e09b96 2e630500 00
12+
41564120 536e6170 73686f74 2076320a 02008017 6c36567a 01a19351 43f9bd06
13+
d5301f8b 08000000 00000003 63636460 e06090fc 96d9226e 3e3150e0 20d3b5ec
14+
8deb7702 0581401c 8863433f 89d6966f 7976ffe9 b56ded65 1a898c60 515d208e
15+
5f7b77a5 e07b763f b9ee6b93 72cfb0fe 63068b3a 43712414 e70371e9 bcb5a916
16+
dc227cea 5c3fa552 5852af32 82455b81 b8e980f6 f3c7a28b 4527ee67 8e3cf37e
17+
e62e46b0 e81c209e bcffafc6 d457fce1 e5e13782 366d5c15 c80416dd 0cc5a780
18+
f8922bf3 cddd07b7 a6b64e5c 51b5b3b7 4897092c fa008abf 03f11781 f9ea3e07
19+
e7db3ff3 792cbef3 817e0733 58949711 8295a1d8 12889919 d8c13e66 64651064
20+
e4cccc4b 49adb052 30344111 e6800a63 1735c52a 6a8655d4 1caba831 76471862
21+
1736c22e 6c8cd568 0bec8a0d b02ac62e 6a8855d4 08002fd4 dcd73f02 0000
3522
]
-404 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)