scratch-vm/test/integration/pen.js

62 lines
2 KiB
JavaScript
Raw Normal View History

2017-10-04 18:40:25 -04:00
const Worker = require('tiny-worker');
const path = require('path');
const test = require('tap').test;
2017-06-16 19:29:12 -04:00
2017-12-01 10:32:32 -05:00
const Scratch3PenBlocks = require('../../src/extensions/scratch3_pen/index.js');
2017-06-16 19:29:12 -04:00
const VirtualMachine = require('../../src/index');
2017-10-04 18:40:25 -04:00
const dispatch = require('../../src/dispatch/central-dispatch');
2017-06-16 19:29:12 -04:00
const makeTestStorage = require('../fixtures/make-test-storage');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const uri = path.resolve(__dirname, '../fixtures/pen.sb2');
const project = readFileToBuffer(uri);
2017-10-04 18:40:25 -04:00
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
dispatch.workerClass = Worker;
test('pen', t => {
const vm = new VirtualMachine();
vm.attachStorage(makeTestStorage());
// Evaluate playground data and exit
vm.on('playgroundData', () => {
// @todo Additional tests
2017-06-16 19:29:12 -04:00
const catSprite = vm.runtime.targets[1].sprite;
const [originalCat, cloneCat] = catSprite.clones;
t.notStrictEqual(originalCat, cloneCat);
/** @type {PenState} */
const originalPenState = originalCat.getCustomState(Scratch3PenBlocks.STATE_KEY);
/** @type {PenState} */
const clonePenState = cloneCat.getCustomState(Scratch3PenBlocks.STATE_KEY);
t.notStrictEqual(originalPenState, clonePenState);
t.equal(originalPenState.penAttributes.diameter, 51);
t.equal(clonePenState.penAttributes.diameter, 42);
t.end();
process.nextTick(process.exit);
});
// Start VM, load project, and run
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
2017-10-04 18:40:25 -04:00
vm.loadProject(project)
.then(() => {
vm.greenFlag();
// After two seconds, get playground data and stop
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
});
2017-04-18 11:55:38 -04:00
});
});