test: don't use process.exit to end tests

Newer versions of `tap` run more asynchronously, so sometimes using `process.nextTick(process.exit)`
to end a test would prevent the test from completing correctly. Removing all instances of
`process.nextTick(process.exit)` put tests into three categories:
* the test still worked correctly -- no fixup needed.
* the test would hang because the VM's `_steppingInterval` was keeping
  Node alive. These tests call a new `quit()` method which ends the
  stepping interval.
* the `load-extensions` test needed special attention because the "Video
  Sensing" extension starts its own loop using `setTimeout`. I added a
  `_stopLoop()` method on the extension and directly call that from the
  test. I'm not completely happy with this solution but anything more
  general would likely require a change to the extension spec, so I'm
  leaving that as a followup task.
This commit is contained in:
Christopher Willis-Ford 2022-06-06 12:00:10 -07:00
parent 605b1c2386
commit 840ffb5df0
69 changed files with 182 additions and 156 deletions

View file

@ -56,14 +56,14 @@ const test = tap.test;
test('loading sb2 project with missing bitmap costume file', t => {
t.equal(vm.runtime.targets.length, 2);
const stage = vm.runtime.targets[0];
t.ok(stage.isStage);
const greenGuySprite = vm.runtime.targets[1];
t.equal(greenGuySprite.getName(), 'GreenGuy');
t.equal(greenGuySprite.getCostumes().length, 1);
const missingCostume = greenGuySprite.getCostumes()[0];
t.equal(missingCostume.name, 'GreenGuy');
// Costume should have both default cosutme (e.g. Gray Question Mark) data and original data
@ -81,14 +81,14 @@ test('load and then save sb2 project with missing costume file', t => {
const resavedProject = JSON.parse(vm.toJSON());
t.equal(resavedProject.targets.length, 2);
const stage = resavedProject.targets[0];
t.ok(stage.isStage);
const greenGuySprite = resavedProject.targets[1];
t.equal(greenGuySprite.name, 'GreenGuy');
t.equal(greenGuySprite.costumes.length, 1);
const missingCostume = greenGuySprite.costumes[0];
t.equal(missingCostume.name, 'GreenGuy');
// Costume should have both default cosutme (e.g. Gray Question Mark) data and original data
@ -102,10 +102,9 @@ test('load and then save sb2 project with missing costume file', t => {
test('serializeCostume does not save data for missing costume', t => {
const costumeDescs = serializeCostumes(vm.runtime);
t.equal(costumeDescs.length, 1); // Should only have one costume, the backdrop
t.not(costumeDescs[0].fileName, `${missingCostumeAssetId}.png`);
t.end();
process.nextTick(process.exit);
});