2017-04-20 19:17:05 -04:00
|
|
|
const path = require('path');
|
|
|
|
const test = require('tap').test;
|
2017-06-09 17:54:10 -04:00
|
|
|
const makeTestStorage = require('../fixtures/make-test-storage');
|
2018-04-05 13:46:07 -04:00
|
|
|
const extractProjectJson = require('../fixtures/readProjectFile').extractProjectJson;
|
2016-10-17 11:55:21 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const renderedTarget = require('../../src/sprites/rendered-target');
|
|
|
|
const runtime = require('../../src/engine/runtime');
|
2017-04-26 16:50:53 -04:00
|
|
|
const sb2 = require('../../src/serialization/sb2');
|
2016-10-17 11:55:21 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('spec', t => {
|
2017-04-27 17:49:57 -04:00
|
|
|
t.type(sb2.deserialize, 'function');
|
2016-10-17 11:55:21 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('default', t => {
|
2016-10-17 11:55:21 -04:00
|
|
|
// Get SB2 JSON (string)
|
2017-04-20 19:17:05 -04:00
|
|
|
const uri = path.resolve(__dirname, '../fixtures/default.sb2');
|
2018-04-05 13:46:07 -04:00
|
|
|
const file = extractProjectJson(uri);
|
2017-04-27 17:49:57 -04:00
|
|
|
const json = JSON.parse(file);
|
2016-10-17 11:55:21 -04:00
|
|
|
|
|
|
|
// Create runtime instance & load SB2 into it
|
2017-04-20 19:17:05 -04:00
|
|
|
const rt = new runtime();
|
2017-06-09 17:54:10 -04:00
|
|
|
rt.attachStorage(makeTestStorage());
|
2017-11-03 14:42:20 -04:00
|
|
|
sb2.deserialize(json, rt).then(({targets}) => {
|
2017-04-18 11:55:38 -04:00
|
|
|
// Test
|
|
|
|
t.type(file, 'string');
|
2017-04-27 17:49:57 -04:00
|
|
|
t.type(json, 'object');
|
2017-04-18 11:55:38 -04:00
|
|
|
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();
|
|
|
|
});
|
2016-10-17 11:55:21 -04:00
|
|
|
});
|