Skip to content

Commit e4faf51

Browse files
committed
test: adjust project execution tests for tap >=18
Calling `t.plan()` has more significant consequences now in terms of test teardown. In particular, calling `t.plan(0)` is a bit hard to deal with correctly. Adding 1 to the plan count reported by the project, and consistently adding exactly one test after the project finishes, makes the behavior pretty much the same as it was with tap 16. I also used `async` and `await` to make some of this code easier to read.
1 parent 89fbe49 commit e4faf51

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

packages/scratch-vm/test/integration/execute.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const fileFilter = /\.sb[23]?$/i;
6464
fs.readdirSync(executeDir)
6565
.filter(uri => fileFilter.test(uri))
6666
.forEach(uri => {
67-
test(uri, t => {
67+
test(uri, async t => {
6868
// Disable logging during this test.
6969
log.suggest.deny('vm', 'error');
7070
t.teardown(() => log.suggest.clear());
@@ -86,13 +86,20 @@ fs.readdirSync(executeDir)
8686
t.fail(reason);
8787
},
8888
plan (count) {
89+
if (didPlan) {
90+
t.fail('tried to set plan more than once');
91+
}
8992
didPlan = true;
90-
t.plan(Number(count));
93+
// +1 for t.ok(didEnd) below
94+
t.plan(Number(count) + 1);
9195
},
9296
end () {
97+
if (didEnd) {
98+
t.fail('tried to end more than once');
99+
}
93100
didEnd = true;
94101
vm.quit();
95-
t.end();
102+
// don't t.end() here: wait for the t.ok(didEnd) below
96103
}
97104
};
98105
const reportVmResult = text => {
@@ -128,24 +135,23 @@ fs.readdirSync(executeDir)
128135

129136
// Load the project and once all threads are complete ensure that
130137
// the scratch project sent us a "end" message.
131-
return vm.loadProject(project)
132-
.then(() => vm.greenFlag())
133-
.then(() => whenThreadsComplete(t, vm, uri))
134-
.then(() => {
135-
// Setting a plan is not required but is a good idea.
136-
if (!didPlan) {
137-
t.comment('did not say "plan NUMBER_OF_TESTS"');
138-
}
138+
await vm.loadProject(project);
139+
vm.greenFlag();
140+
await whenThreadsComplete(t, vm, uri);
139141

140-
// End must be called so that tap knows the test is done. If
141-
// the test has an SAY "end" block but that block did not
142-
// execute, this explicit failure will raise that issue so
143-
// it can be resolved.
144-
if (!didEnd) {
145-
t.fail('did not say "end"');
146-
vm.quit();
147-
t.end();
148-
}
149-
});
142+
// Setting a plan is not required but is a good idea.
143+
if (!didPlan) {
144+
t.comment('did not say "plan NUMBER_OF_TESTS"');
145+
}
146+
147+
// End must be called so that tap knows the test is done. If
148+
// the test has an SAY "end" block but that block did not
149+
// execute, this explicit failure will raise that issue so
150+
// it can be resolved.
151+
if (!didEnd) {
152+
vm.quit();
153+
}
154+
t.ok(didEnd, 'did say "end"');
155+
t.end();
150156
});
151157
});

0 commit comments

Comments
 (0)