mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
840ffb5df0
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.
28 lines
1,000 B
JavaScript
28 lines
1,000 B
JavaScript
const tap = require('tap');
|
|
const path = require('path');
|
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
|
const makeTestStorage = require('../fixtures/make-test-storage');
|
|
const VirtualMachine = require('../../src/virtual-machine');
|
|
|
|
const test = tap.test;
|
|
|
|
// Test that loading a project does not emit a project change
|
|
// This is in its own file so that it does not affect the test setup
|
|
// and results of the other project changed state tests
|
|
test('Loading a project should not emit a project changed event', t => {
|
|
const projectUri = path.resolve(__dirname, '../fixtures/default.sb2');
|
|
const project = readFileToBuffer(projectUri);
|
|
|
|
const vm = new VirtualMachine();
|
|
|
|
let projectChanged = false;
|
|
vm.runtime.addListener('PROJECT_CHANGED', () => {
|
|
projectChanged = true;
|
|
});
|
|
|
|
vm.attachStorage(makeTestStorage());
|
|
return vm.loadProject(project).then(() => {
|
|
t.equal(projectChanged, false);
|
|
t.end();
|
|
});
|
|
});
|