scratch-vm/test/integration/hat-execution-order.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

const path = require('path');
const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const VirtualMachine = require('../../src/index');
2017-02-14 19:33:42 -05:00
const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
const project = readFileToBuffer(projectUri);
2017-02-14 19:33:42 -05:00
test('complex', t => {
const vm = new VirtualMachine();
vm.attachStorage(makeTestStorage());
2017-02-14 19:33:42 -05:00
// Evaluate playground data and exit
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
2017-02-14 19:33:42 -05:00
t.ok(threads.length === 0);
2017-11-13 14:25:12 -05:00
const resultKey = Object.keys(vm.runtime.targets[0].variables)[0];
const results = vm.runtime.targets[0].variables[resultKey].value;
2017-02-14 19:33:42 -05:00
t.deepEqual(results, ['3', '2', '1', 'stage']);
vm.quit();
2017-02-14 19:33:42 -05:00
t.end();
});
// Start VM, load project, and run
t.doesNotThrow(() => {
2017-02-14 19:33:42 -05:00
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(() => {
2017-04-18 11:55:38 -04:00
vm.greenFlag();
2017-02-14 19:33:42 -05:00
2017-04-18 11:55:38 -04:00
// After two seconds, get playground data and stop
setTimeout(() => {
2017-04-18 11:55:38 -04:00
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
});
});
2017-02-14 19:33:42 -05:00
});