Skip to content

Commit 921f991

Browse files
authored
clean up liveslots tests (#10739)
refs: #5575 ## Description As needed for Ava 6, - #9083 It has different exception behavior that breaks the intentional `.failing` hack. This changes the four`test.failing` to use `test` that are confirmed to be the correct behavior. Since the test is of test failures, it uses a new spy instead. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations ~This is one package of the monorepo on Ava 6. I [tried bumping them all before](#9081) but ran into problems. We should tackle them all eventually,~ (DEFERRED) ### Testing Considerations per se ### Upgrade Considerations none
2 parents 1bb78b9 + 250360f commit 921f991

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
import { test, runDVOTest } from '../../tools/dvo-test-harness.js';
1+
import { runDVOTest, test } from '../../tools/dvo-test-harness.js';
22

33
function bfile(name) {
44
return new URL(name, import.meta.url).pathname;
55
}
66

7-
async function dvoTestTest(t, mode) {
7+
/**
8+
* @param {import('ava').ExecutionContext} t
9+
* @param {'before' | 'after' | 'succeed'} mode
10+
*/
11+
const dvo = test.macro(async (t, mode) => {
12+
/**
13+
* @param {import('ava').ExecutionContext} _t
14+
* @param {'before' | 'after'} phase
15+
* @param {string[]} log
16+
*/
817
function testLogCheck(_t, phase, log) {
9-
t.deepEqual(log, ['start test', phase, 'test thing', { mode }, 'end test']);
18+
t.deepEqual(
19+
log,
20+
[
21+
'start test',
22+
phase,
23+
mode === phase ? `fail during "${phase}"` : 'test thing',
24+
{ mode },
25+
'end test',
26+
],
27+
`Bad log for phase ${phase} with mode ${mode}`,
28+
);
1029
}
1130
await runDVOTest(t, testLogCheck, bfile('vat-dvo-test-test.js'), { mode });
12-
}
13-
14-
test.failing('fail during "before" phase', async t => {
15-
await dvoTestTest(t, 'before');
1631
});
1732

18-
test.failing('fail during "after" phase', async t => {
19-
await dvoTestTest(t, 'after');
20-
});
33+
test('fail during "before" phase', dvo, 'before');
2134

22-
test('succeed', async t => {
23-
await dvoTestTest(t, 'succeed');
24-
});
35+
test('fail during "after" phase', dvo, 'after');
36+
37+
test('succeed', dvo, 'succeed');

packages/swingset-liveslots/test/vo-test-harness.test.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import { runVOTest } from '../tools/vo-test-harness.js';
2+
import { makeSpy, runVOTest } from '../tools/vo-test-harness.js';
33

44
async function voTestTest(t, mode) {
55
let makeThing;
@@ -36,8 +36,6 @@ async function voTestTest(t, mode) {
3636
await runVOTest(t, prepare, makeTestThing, testTestThing);
3737
}
3838

39-
// Note: these first two are not marked "test.failing" because
40-
// something is wrong and we need to fix it. Rather, they are
4139
// confirming that the voTestTest harness would catch problems during
4240
// downstream tests that use the harness, if those problems arose in
4341
// the "before" or "after" phases, and reported by the downstream test
@@ -47,20 +45,26 @@ async function voTestTest(t, mode) {
4745
// fails, otherwise the harness is not doing its job, and is hiding
4846
// real test failures in some downstream client package.
4947

50-
test.failing('fail during "before" phase', async t => {
51-
await voTestTest(t, 'before');
48+
test('fail during "before" phase', async t => {
49+
const tSpy = makeSpy(t);
50+
await voTestTest(tSpy, 'before');
51+
t.is(tSpy.failureMessage, 'deliberate failure in before phase');
5252
});
5353

54-
test.failing('fail during "after" phase', async t => {
55-
await voTestTest(t, 'after');
54+
test('fail during "after" phase', async t => {
55+
const tSpy = makeSpy(t);
56+
await voTestTest(tSpy, 'after');
57+
t.is(tSpy.failureMessage, 'deliberate failure in after phase');
5658
});
5759

5860
// Similarly, this test makes sure that our harness can detect when
5961
// the downstream test misbehaves and holds on to the object they were
6062
// supposed to drop.
6163

62-
test.failing('fail due to held object', async t => {
63-
await voTestTest(t, 'hold');
64+
test('fail due to held object', async t => {
65+
const tSpy = makeSpy(t);
66+
await voTestTest(tSpy, 'hold');
67+
t.is(tSpy.falsyMessage, 'somebody continues to hold test object');
6468
});
6569

6670
test.serial('succeed', async t => {

packages/swingset-liveslots/tools/vo-test-harness.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ import { setupTestLiveslots } from '../test/liveslots-helpers.js';
55
// is to to help verify that a VO can be garbage collected and then
66
// reloaded from persistent storage while maintaining functionality.
77

8+
/**
9+
* A spy wrapping Ava's t for tests that are testing the harness itself.
10+
* @param {import('ava').ExecutionContext} t
11+
*/
12+
export const makeSpy = t => {
13+
const tSpy = {
14+
...t,
15+
fail: msg => {
16+
tSpy.failureMessage = msg;
17+
},
18+
// In Ava 6, assertions throw?
19+
falsy: (check, msg) => {
20+
if (!check) return;
21+
tSpy.falsyMessage = msg;
22+
},
23+
failureMessage: '',
24+
falsyMessage: '',
25+
};
26+
return tSpy;
27+
};
28+
829
// Testing VO swapping with runVOTest:
930
//
1031
// Step 1: import the necessary harness paraphernalia

0 commit comments

Comments
 (0)