2017-04-20 19:17:05 -04:00
|
|
|
const path = require('path');
|
|
|
|
const test = require('tap').test;
|
2017-06-09 17:54:10 -04:00
|
|
|
const makeTestStorage = require('../fixtures/make-test-storage');
|
2018-04-05 13:46:07 -04:00
|
|
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
2017-04-20 19:17:05 -04:00
|
|
|
const VirtualMachine = require('../../src/index');
|
2017-02-14 19:33:42 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
|
2018-04-05 13:46:07 -04:00
|
|
|
const project = readFileToBuffer(projectUri);
|
2017-02-14 19:33:42 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('complex', t => {
|
|
|
|
const vm = new VirtualMachine();
|
2017-06-09 17:54:10 -04:00
|
|
|
vm.attachStorage(makeTestStorage());
|
2017-02-14 19:33:42 -05:00
|
|
|
|
|
|
|
// Evaluate playground data and exit
|
2017-04-20 19:17:05 -04:00
|
|
|
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']);
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
process.nextTick(process.exit);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start VM, load project, and run
|
2017-04-20 19:17:05 -04:00
|
|
|
t.doesNotThrow(() => {
|
2017-02-14 19:33:42 -05:00
|
|
|
vm.start();
|
|
|
|
vm.clear();
|
|
|
|
vm.setCompatibilityMode(false);
|
|
|
|
vm.setTurboMode(false);
|
2017-04-20 19:17:05 -04:00
|
|
|
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
|
2017-04-20 19:17:05 -04:00
|
|
|
setTimeout(() => {
|
2017-04-18 11:55:38 -04:00
|
|
|
vm.getPlaygroundData();
|
|
|
|
vm.stopAll();
|
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
});
|
2017-02-14 19:33:42 -05:00
|
|
|
});
|