mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-29 09:22:35 -05:00
cd1c72c7cc
Rather than assuming that the storage instance will be attached to a VM, just return it. Callers may attach it to a `VM` or (in the case of `import_sb2.js`) to a `Runtime`.
54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
const path = require('path');
|
|
const test = require('tap').test;
|
|
const makeTestStorage = require('../fixtures/make-test-storage');
|
|
const extract = require('../fixtures/extract');
|
|
|
|
const renderedTarget = require('../../src/sprites/rendered-target');
|
|
const runtime = require('../../src/engine/runtime');
|
|
const sb2 = require('../../src/serialization/sb2');
|
|
|
|
test('spec', t => {
|
|
t.type(sb2.deserialize, 'function');
|
|
t.end();
|
|
});
|
|
|
|
test('default', t => {
|
|
// Get SB2 JSON (string)
|
|
const uri = path.resolve(__dirname, '../fixtures/default.sb2');
|
|
const file = extract(uri);
|
|
const json = JSON.parse(file);
|
|
|
|
// Create runtime instance & load SB2 into it
|
|
const rt = new runtime();
|
|
rt.attachStorage(makeTestStorage());
|
|
sb2.deserialize(json, rt).then(targets => {
|
|
// Test
|
|
t.type(file, 'string');
|
|
t.type(json, 'object');
|
|
t.type(rt, 'object');
|
|
t.type(targets, 'object');
|
|
|
|
t.ok(targets[0] instanceof renderedTarget);
|
|
t.type(targets[0].id, 'string');
|
|
t.type(targets[0].blocks, 'object');
|
|
t.type(targets[0].variables, 'object');
|
|
t.type(targets[0].lists, 'object');
|
|
|
|
t.equal(targets[0].isOriginal, true);
|
|
t.equal(targets[0].currentCostume, 0);
|
|
t.equal(targets[0].isOriginal, true);
|
|
t.equal(targets[0].isStage, true);
|
|
|
|
t.ok(targets[1] instanceof renderedTarget);
|
|
t.type(targets[1].id, 'string');
|
|
t.type(targets[1].blocks, 'object');
|
|
t.type(targets[1].variables, 'object');
|
|
t.type(targets[1].lists, 'object');
|
|
|
|
t.equal(targets[1].isOriginal, true);
|
|
t.equal(targets[1].currentCostume, 0);
|
|
t.equal(targets[1].isOriginal, true);
|
|
t.equal(targets[1].isStage, false);
|
|
t.end();
|
|
});
|
|
});
|