2017-11-07 16:26:35 -05:00
|
|
|
const Worker = require('tiny-worker');
|
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');
|
2017-04-20 19:17:05 -04:00
|
|
|
const extract = require('../fixtures/extract');
|
|
|
|
const VirtualMachine = require('../../src/index');
|
2017-11-07 16:26:35 -05:00
|
|
|
const dispatch = require('../../src/dispatch/central-dispatch');
|
2017-02-03 17:39:36 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const uri = path.resolve(__dirname, '../fixtures/sound.sb2');
|
|
|
|
const project = extract(uri);
|
2017-02-03 17:39:36 -05:00
|
|
|
|
2017-11-07 16:26:35 -05:00
|
|
|
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
|
|
|
|
dispatch.workerClass = Worker;
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('sound', t => {
|
|
|
|
const vm = new VirtualMachine();
|
2017-06-09 17:54:10 -04:00
|
|
|
vm.attachStorage(makeTestStorage());
|
2017-02-03 17:39:36 -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-03 17:39:36 -05:00
|
|
|
t.ok(threads.length > 0);
|
|
|
|
t.end();
|
|
|
|
process.nextTick(process.exit);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start VM, load project, and run
|
2017-04-20 19:17:05 -04:00
|
|
|
t.doesNotThrow(() => {
|
2017-02-03 17:39:36 -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-03 17:39:36 -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-03 17:39:36 -05:00
|
|
|
});
|