mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-05 18:14:55 -04:00
test(clone-cleanup): improve clone-cleanup test reliability
Previously the test relied on the project's `wait` blocks running at roughly real time. Now, the project drives the timing using `say` blocks.
This commit is contained in:
parent
05f8692300
commit
605b1c2386
4 changed files with 9 additions and 13 deletions
test
BIN
test/fixtures/clone-cleanup.sb2
vendored
BIN
test/fixtures/clone-cleanup.sb2
vendored
Binary file not shown.
BIN
test/fixtures/clone-cleanup.sb3
vendored
Normal file
BIN
test/fixtures/clone-cleanup.sb3
vendored
Normal file
Binary file not shown.
|
@ -4,7 +4,7 @@ const makeTestStorage = require('../fixtures/make-test-storage');
|
||||||
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
||||||
const VirtualMachine = require('../../src/index');
|
const VirtualMachine = require('../../src/index');
|
||||||
|
|
||||||
const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2');
|
const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb3');
|
||||||
const project = readFileToBuffer(projectUri);
|
const project = readFileToBuffer(projectUri);
|
||||||
|
|
||||||
test('clone-cleanup', t => {
|
test('clone-cleanup', t => {
|
||||||
|
@ -17,12 +17,6 @@ test('clone-cleanup', t => {
|
||||||
*/
|
*/
|
||||||
let testStep = -1;
|
let testStep = -1;
|
||||||
|
|
||||||
/**
|
|
||||||
* We test using setInterval; track the interval ID here so we can cancel it.
|
|
||||||
* @type {object}
|
|
||||||
*/
|
|
||||||
let testInterval = null;
|
|
||||||
|
|
||||||
const verifyCounts = (expectedClones, extraThreads) => {
|
const verifyCounts = (expectedClones, extraThreads) => {
|
||||||
// stage plus one sprite, plus clones
|
// stage plus one sprite, plus clones
|
||||||
t.strictEqual(vm.runtime.targets.length, 2 + expectedClones,
|
t.strictEqual(vm.runtime.targets.length, 2 + expectedClones,
|
||||||
|
@ -60,15 +54,17 @@ test('clone-cleanup', t => {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// The second batch of clones has been created and the main thread has ended
|
// The second batch of clones has been created and the main thread is about to end
|
||||||
verifyCounts(10, 0);
|
verifyCounts(10, 1);
|
||||||
|
|
||||||
|
// After the main thread ends, do one last test step
|
||||||
|
setTimeout(() => testNextStep(), 1000);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
// The second batch of clones has deleted themselves; everything is finished
|
// The second batch of clones has deleted themselves; everything is finished
|
||||||
verifyCounts(0, 0);
|
verifyCounts(0, 0);
|
||||||
|
|
||||||
clearInterval(testInterval);
|
|
||||||
t.end();
|
t.end();
|
||||||
process.nextTick(process.exit);
|
process.nextTick(process.exit);
|
||||||
break;
|
break;
|
||||||
|
@ -88,8 +84,8 @@ test('clone-cleanup', t => {
|
||||||
|
|
||||||
vm.greenFlag();
|
vm.greenFlag();
|
||||||
|
|
||||||
// Every second, advance the testing step
|
// Let the project control the pace of the tests
|
||||||
testInterval = setInterval(testNextStep, 1000);
|
vm.runtime.on('SAY', () => testNextStep());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const VirtualMachine = require('../../src/index');
|
||||||
const Runtime = require('../../src/engine/runtime');
|
const Runtime = require('../../src/engine/runtime');
|
||||||
const sb3 = require('../../src/serialization/sb3');
|
const sb3 = require('../../src/serialization/sb3');
|
||||||
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
||||||
const exampleProjectPath = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2');
|
const exampleProjectPath = path.resolve(__dirname, '../fixtures/complex.sb2');
|
||||||
const commentsSB2ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb2');
|
const commentsSB2ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb2');
|
||||||
const commentsSB3ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb3');
|
const commentsSB3ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb3');
|
||||||
const commentsSB3NoDupeIds = path.resolve(__dirname, '../fixtures/comments_no_duplicate_id_serialization.sb3');
|
const commentsSB3NoDupeIds = path.resolve(__dirname, '../fixtures/comments_no_duplicate_id_serialization.sb3');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue