scratch-vm/test/integration/import_sb2.js
Christopher Willis-Ford e4fd9d57a2 Fix tests involving scratch-storage
- Attach the storage module to the VM for tests which load projects or
  other assets.
- Move `import_sb2.js` from `test/unit/ into `test/integration` since it
  now depends heavily on `scratch-storage`.
- Skip loading costumes when there is no renderer.
2017-03-09 15:50:43 -08:00

52 lines
1.6 KiB
JavaScript

var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var renderedTarget = require('../../src/sprites/rendered-target');
var runtime = require('../../src/engine/runtime');
var sb2 = require('../../src/import/sb2import');
test('spec', function (t) {
t.type(sb2, 'function');
t.end();
});
test('default', function (t) {
// Get SB2 JSON (string)
var uri = path.resolve(__dirname, '../fixtures/default.sb2');
var file = extract(uri);
// Create runtime instance & load SB2 into it
var rt = new runtime();
attachTestStorage(rt);
sb2(file, rt);
// Test
t.type(file, 'string');
t.type(rt, 'object');
t.type(rt.targets, 'object');
t.ok(rt.targets[0] instanceof renderedTarget);
t.type(rt.targets[0].id, 'string');
t.type(rt.targets[0].blocks, 'object');
t.type(rt.targets[0].variables, 'object');
t.type(rt.targets[0].lists, 'object');
t.equal(rt.targets[0].isOriginal, true);
t.equal(rt.targets[0].currentCostume, 0);
t.equal(rt.targets[0].isOriginal, true);
t.equal(rt.targets[0].isStage, true);
t.ok(rt.targets[1] instanceof renderedTarget);
t.type(rt.targets[1].id, 'string');
t.type(rt.targets[1].blocks, 'object');
t.type(rt.targets[1].variables, 'object');
t.type(rt.targets[1].lists, 'object');
t.equal(rt.targets[1].isOriginal, true);
t.equal(rt.targets[1].currentCostume, 0);
t.equal(rt.targets[1].isOriginal, true);
t.equal(rt.targets[1].isStage, false);
t.end();
});