scratch-vm/test/integration/sound.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-11-07 16:26:35 -05:00
const Worker = require('tiny-worker');
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-11-07 16:26:35 -05:00
const dispatch = require('../../src/dispatch/central-dispatch');
const uri = path.resolve(__dirname, '../fixtures/sound.sb2');
const project = readFileToBuffer(uri);
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;
test('sound', t => {
const vm = new VirtualMachine();
vm.attachStorage(makeTestStorage());
// Evaluate playground data and exit
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length > 0);
t.end();
process.nextTick(process.exit);
});
// Start VM, load project, and run
t.doesNotThrow(() => {
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-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);
});
});
});