Update tests to allow parsing whole .sb2s

This commit is contained in:
Karishma Chadha 2018-03-25 19:08:52 -04:00
parent b8e67a7727
commit 1511fa79e3
21 changed files with 52 additions and 46 deletions

View file

@ -1,6 +0,0 @@
const AdmZip = require('adm-zip');
module.exports = function (path) {
const zip = new AdmZip(path);
return zip.readAsText('project.json', 'utf8');
};

12
test/fixtures/readProjectFile.js vendored Normal file
View file

@ -0,0 +1,12 @@
const AdmZip = require('adm-zip');
const fs = require('fs');
module.exports = {
readAsBuffer: function (path) {
return new Buffer(fs.readFileSync(path));
},
readAsString: function (path) {
const zip = new AdmZip(path);
return zip.readAsText('project.json', 'utf8');
}
};

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
test('clone-cleanup', t => { test('clone-cleanup', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -2,11 +2,11 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json'); const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
const sprite = fs.readFileSync(spriteUri, 'utf8'); const sprite = fs.readFileSync(spriteUri, 'utf8');

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/control.sb2'); const uri = path.resolve(__dirname, '../fixtures/control.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('control', t => { test('control', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/data.sb2'); const uri = path.resolve(__dirname, '../fixtures/data.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('data', t => { test('data', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/event.sb2'); const uri = path.resolve(__dirname, '../fixtures/event.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('event', t => { test('event', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
test('complex', t => { test('complex', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,13 +1,13 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const Thread = require('../../src/engine/thread'); const Thread = require('../../src/engine/thread');
const Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
const projectUri = path.resolve(__dirname, '../fixtures/loudness-hat-block.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/loudness-hat-block.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
const checkIsHatThread = (t, vm, hatThread) => { const checkIsHatThread = (t, vm, hatThread) => {
t.equal(hatThread.stackClick, false); t.equal(hatThread.stackClick, false);

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsString = require('../fixtures/readProjectFile').readAsString;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/default.sb2'); const uri = path.resolve(__dirname, '../fixtures/default.sb2');
const project = JSON.parse(extract(uri)); const project = JSON.parse(readAsString(uri));
test('default', t => { test('default', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,7 +1,7 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsString = require('../fixtures/readProjectFile').readAsString;
const renderedTarget = require('../../src/sprites/rendered-target'); const renderedTarget = require('../../src/sprites/rendered-target');
const runtime = require('../../src/engine/runtime'); const runtime = require('../../src/engine/runtime');
@ -15,7 +15,7 @@ test('spec', t => {
test('default', t => { test('default', t => {
// Get SB2 JSON (string) // Get SB2 JSON (string)
const uri = path.resolve(__dirname, '../fixtures/default.sb2'); const uri = path.resolve(__dirname, '../fixtures/default.sb2');
const file = extract(uri); const file = readAsString(uri);
const json = JSON.parse(file); const json = JSON.parse(file);
// Create runtime instance & load SB2 into it // Create runtime instance & load SB2 into it

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/looks.sb2'); const uri = path.resolve(__dirname, '../fixtures/looks.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('looks', t => { test('looks', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -1,13 +1,13 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const Thread = require('../../src/engine/thread'); const Thread = require('../../src/engine/thread');
const Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
const projectUri = path.resolve(__dirname, '../fixtures/default.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/default.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
const checkMonitorThreadPresent = (t, threads) => { const checkMonitorThreadPresent = (t, threads) => {
t.equal(threads.length, 1); t.equal(threads.length, 1);

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/motion.sb2'); const uri = path.resolve(__dirname, '../fixtures/motion.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('motion', t => { test('motion', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -7,10 +7,10 @@ const VirtualMachine = require('../../src/index');
const dispatch = require('../../src/dispatch/central-dispatch'); const dispatch = require('../../src/dispatch/central-dispatch');
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const uri = path.resolve(__dirname, '../fixtures/pen.sb2'); const uri = path.resolve(__dirname, '../fixtures/pen.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead. // By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
dispatch.workerClass = Worker; dispatch.workerClass = Worker;

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/procedure.sb2'); const uri = path.resolve(__dirname, '../fixtures/procedure.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('procedure', t => { test('procedure', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -2,12 +2,12 @@ const Worker = require('tiny-worker');
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const dispatch = require('../../src/dispatch/central-dispatch'); const dispatch = require('../../src/dispatch/central-dispatch');
const uri = path.resolve(__dirname, '../fixtures/saythink-and-wait.sb2'); const uri = path.resolve(__dirname, '../fixtures/saythink-and-wait.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead. // By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
dispatch.workerClass = Worker; dispatch.workerClass = Worker;

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const uri = path.resolve(__dirname, '../fixtures/sensing.sb2'); const uri = path.resolve(__dirname, '../fixtures/sensing.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
test('sensing', t => { test('sensing', t => {
const vm = new VirtualMachine(); const vm = new VirtualMachine();

View file

@ -2,12 +2,12 @@ const Worker = require('tiny-worker');
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const dispatch = require('../../src/dispatch/central-dispatch'); const dispatch = require('../../src/dispatch/central-dispatch');
const uri = path.resolve(__dirname, '../fixtures/sound.sb2'); const uri = path.resolve(__dirname, '../fixtures/sound.sb2');
const project = extract(uri); const project = readAsBuffer(uri);
// By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead. // By default Central Dispatch works with the Worker class built into the browser. Tell it to use TinyWorker instead.
dispatch.workerClass = Worker; dispatch.workerClass = Worker;

View file

@ -1,11 +1,11 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage'); const makeTestStorage = require('../fixtures/make-test-storage');
const extract = require('../fixtures/extract'); const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer;
const VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
const projectUri = path.resolve(__dirname, '../fixtures/stack-click.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/stack-click.sb2');
const project = extract(projectUri); const project = readAsBuffer(projectUri);
/** /**
* stack-click.sb2 contains a sprite at (0, 0) with a single stack * stack-click.sb2 contains a sprite at (0, 0) with a single stack

View file

@ -1,6 +1,6 @@
const path = require('path'); const path = require('path');
const test = require('tap').test; const test = require('tap').test;
const extract = require('../fixtures/extract'); const readAsString = require('../fixtures/readProjectFile').readAsString;
const RenderedTarget = require('../../src/sprites/rendered-target'); const RenderedTarget = require('../../src/sprites/rendered-target');
const Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
@ -15,7 +15,7 @@ test('spec', t => {
test('default', t => { test('default', t => {
// Get SB2 JSON (string) // Get SB2 JSON (string)
const uri = path.resolve(__dirname, '../fixtures/default.sb2'); const uri = path.resolve(__dirname, '../fixtures/default.sb2');
const file = extract(uri); const file = readAsString(uri);
const json = JSON.parse(file); const json = JSON.parse(file);
// Create runtime instance & load SB2 into it // Create runtime instance & load SB2 into it
@ -55,7 +55,7 @@ test('default', t => {
test('data scoping', t => { test('data scoping', t => {
// Get SB2 JSON (string) // Get SB2 JSON (string)
const uri = path.resolve(__dirname, '../fixtures/data.sb2'); const uri = path.resolve(__dirname, '../fixtures/data.sb2');
const file = extract(uri); const file = readAsString(uri);
const json = JSON.parse(file); const json = JSON.parse(file);
// Create runtime instance & load SB2 into it // Create runtime instance & load SB2 into it
@ -72,7 +72,7 @@ test('data scoping', t => {
test('whenclicked blocks imported separately', t => { test('whenclicked blocks imported separately', t => {
// This sb2 fixture has a single "whenClicked" block on both sprite and stage // This sb2 fixture has a single "whenClicked" block on both sprite and stage
const uri = path.resolve(__dirname, '../fixtures/when-clicked.sb2'); const uri = path.resolve(__dirname, '../fixtures/when-clicked.sb2');
const file = extract(uri); const file = readAsString(uri);
const json = JSON.parse(file); const json = JSON.parse(file);
// Create runtime instance & load SB2 into it // Create runtime instance & load SB2 into it