mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-13 17:04:39 -04:00
Add test for nested sb2
This commit is contained in:
parent
a4b0550013
commit
7e9297145d
3 changed files with 56 additions and 0 deletions
BIN
test/fixtures/default_nested.sb2
vendored
Normal file
BIN
test/fixtures/default_nested.sb2
vendored
Normal file
Binary file not shown.
4
test/fixtures/readProjectFile.js
vendored
4
test/fixtures/readProjectFile.js
vendored
|
@ -8,5 +8,9 @@ module.exports = {
|
|||
extractProjectJson: function (path) {
|
||||
const zip = new AdmZip(path);
|
||||
return JSON.parse(zip.readAsText('project.json', 'utf8'));
|
||||
},
|
||||
extractNestedProjectJson: function (path, folder) {
|
||||
const zip = new AdmZip(path);
|
||||
return JSON.parse(zip.readAsText(`${folder}/project.json`, 'utf8'));
|
||||
}
|
||||
};
|
||||
|
|
52
test/integration/import_nested_sb2.js
Normal file
52
test/integration/import_nested_sb2.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
const path = require('path');
|
||||
const test = require('tap').test;
|
||||
const makeTestStorage = require('../fixtures/make-test-storage');
|
||||
const extractNestedProjectJson = require('../fixtures/readProjectFile').extractNestedProjectJson;
|
||||
|
||||
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('nested default/*', t => {
|
||||
// Get SB2 JSON (string)
|
||||
const uri = path.resolve(__dirname, '../fixtures/default_nested.sb2');
|
||||
const json = extractNestedProjectJson(uri, 'default');
|
||||
|
||||
// Create runtime instance & load SB2 into it
|
||||
const rt = new runtime();
|
||||
rt.attachStorage(makeTestStorage());
|
||||
sb2.deserialize(json, rt).then(({targets}) => {
|
||||
// Test
|
||||
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].comments, '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].comments, '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();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue