2017-10-04 18:40:25 -04: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-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
|
|
|
|
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-01-19 18:58:00 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const uri = path.resolve(__dirname, '../fixtures/pen.sb2');
|
2018-04-05 13:46:07 -04:00
|
|
|
const project = readFileToBuffer(uri);
|
2017-01-19 18:58:00 -05:00
|
|
|
|
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;
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('pen', t => {
|
|
|
|
const vm = new VirtualMachine();
|
2017-06-09 17:54:10 -04:00
|
|
|
vm.attachStorage(makeTestStorage());
|
2017-01-19 18:58:00 -05:00
|
|
|
|
|
|
|
// Evaluate playground data and exit
|
2017-04-20 19:17:05 -04:00
|
|
|
vm.on('playgroundData', () => {
|
2017-01-19 18:58:00 -05:00
|
|
|
// @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);
|
|
|
|
|
2017-01-19 18:58:00 -05:00
|
|
|
t.end();
|
|
|
|
process.nextTick(process.exit);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start VM, load project, and run
|
2017-04-20 19:17:05 -04:00
|
|
|
t.doesNotThrow(() => {
|
2017-01-19 18:58:00 -05:00
|
|
|
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
|
|
|
});
|
2017-01-19 18:58:00 -05:00
|
|
|
});
|