diff --git a/test/fixtures/extract.js b/test/fixtures/extract.js deleted file mode 100644 index 098261308..000000000 --- a/test/fixtures/extract.js +++ /dev/null @@ -1,6 +0,0 @@ -const AdmZip = require('adm-zip'); - -module.exports = function (path) { - const zip = new AdmZip(path); - return zip.readAsText('project.json', 'utf8'); -}; diff --git a/test/fixtures/readProjectFile.js b/test/fixtures/readProjectFile.js new file mode 100644 index 000000000..22c413a62 --- /dev/null +++ b/test/fixtures/readProjectFile.js @@ -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'); + } +}; diff --git a/test/integration/clone-cleanup.js b/test/integration/clone-cleanup.js index 8b801a00e..9378cf0b8 100644 --- a/test/integration/clone-cleanup.js +++ b/test/integration/clone-cleanup.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const projectUri = path.resolve(__dirname, '../fixtures/clone-cleanup.sb2'); -const project = extract(projectUri); +const project = readAsBuffer(projectUri); test('clone-cleanup', t => { const vm = new VirtualMachine(); diff --git a/test/integration/complex.js b/test/integration/complex.js index 331f2a982..a99d6b8d1 100644 --- a/test/integration/complex.js +++ b/test/integration/complex.js @@ -2,11 +2,11 @@ const fs = require('fs'); const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); 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 sprite = fs.readFileSync(spriteUri, 'utf8'); diff --git a/test/integration/control.js b/test/integration/control.js index 66b4c0283..4f5a06554 100644 --- a/test/integration/control.js +++ b/test/integration/control.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/control.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('control', t => { const vm = new VirtualMachine(); diff --git a/test/integration/data.js b/test/integration/data.js index c6cd71d1e..ed62e572c 100644 --- a/test/integration/data.js +++ b/test/integration/data.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/data.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('data', t => { const vm = new VirtualMachine(); diff --git a/test/integration/event.js b/test/integration/event.js index c4f3ee58a..6f14cc49a 100644 --- a/test/integration/event.js +++ b/test/integration/event.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/event.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('event', t => { const vm = new VirtualMachine(); diff --git a/test/integration/hat-execution-order.js b/test/integration/hat-execution-order.js index 3e5e92a2c..a6ef5304f 100644 --- a/test/integration/hat-execution-order.js +++ b/test/integration/hat-execution-order.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2'); -const project = extract(projectUri); +const project = readAsBuffer(projectUri); test('complex', t => { const vm = new VirtualMachine(); diff --git a/test/integration/hat-threads-run-every-frame.js b/test/integration/hat-threads-run-every-frame.js index 3f0fd2bf0..fa21aa379 100644 --- a/test/integration/hat-threads-run-every-frame.js +++ b/test/integration/hat-threads-run-every-frame.js @@ -1,13 +1,13 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const Thread = require('../../src/engine/thread'); const Runtime = require('../../src/engine/runtime'); const projectUri = path.resolve(__dirname, '../fixtures/loudness-hat-block.sb2'); -const project = extract(projectUri); +const project = readAsBuffer(projectUri); const checkIsHatThread = (t, vm, hatThread) => { t.equal(hatThread.stackClick, false); diff --git a/test/integration/import-sb2-from-object.js b/test/integration/import-sb2-from-object.js index c53234f16..846f645b5 100644 --- a/test/integration/import-sb2-from-object.js +++ b/test/integration/import-sb2-from-object.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsString = require('../fixtures/readProjectFile').readAsString; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/default.sb2'); -const project = JSON.parse(extract(uri)); +const project = JSON.parse(readAsString(uri)); test('default', t => { const vm = new VirtualMachine(); diff --git a/test/integration/import_sb2.js b/test/integration/import_sb2.js index ec553dd90..70fd478a2 100644 --- a/test/integration/import_sb2.js +++ b/test/integration/import_sb2.js @@ -1,7 +1,7 @@ const path = require('path'); const test = require('tap').test; 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 runtime = require('../../src/engine/runtime'); @@ -15,7 +15,7 @@ test('spec', t => { test('default', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/default.sb2'); - const file = extract(uri); + const file = readAsString(uri); const json = JSON.parse(file); // Create runtime instance & load SB2 into it diff --git a/test/integration/looks.js b/test/integration/looks.js index 874646496..0ce296ca0 100644 --- a/test/integration/looks.js +++ b/test/integration/looks.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/looks.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('looks', t => { const vm = new VirtualMachine(); diff --git a/test/integration/monitor-threads-run-every-frame.js b/test/integration/monitor-threads-run-every-frame.js index daf33693d..310404797 100644 --- a/test/integration/monitor-threads-run-every-frame.js +++ b/test/integration/monitor-threads-run-every-frame.js @@ -1,13 +1,13 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const Thread = require('../../src/engine/thread'); const Runtime = require('../../src/engine/runtime'); const projectUri = path.resolve(__dirname, '../fixtures/default.sb2'); -const project = extract(projectUri); +const project = readAsBuffer(projectUri); const checkMonitorThreadPresent = (t, threads) => { t.equal(threads.length, 1); diff --git a/test/integration/motion.js b/test/integration/motion.js index 689b21871..909ce50ed 100644 --- a/test/integration/motion.js +++ b/test/integration/motion.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/motion.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('motion', t => { const vm = new VirtualMachine(); diff --git a/test/integration/pen.js b/test/integration/pen.js index bb9f7c828..1164825b4 100644 --- a/test/integration/pen.js +++ b/test/integration/pen.js @@ -7,10 +7,10 @@ const VirtualMachine = require('../../src/index'); const dispatch = require('../../src/dispatch/central-dispatch'); 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 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. dispatch.workerClass = Worker; diff --git a/test/integration/procedure.js b/test/integration/procedure.js index e62f2b108..673e06ec4 100644 --- a/test/integration/procedure.js +++ b/test/integration/procedure.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/procedure.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('procedure', t => { const vm = new VirtualMachine(); diff --git a/test/integration/saythink-and-wait.js b/test/integration/saythink-and-wait.js index abde2d978..ed490d0f4 100644 --- a/test/integration/saythink-and-wait.js +++ b/test/integration/saythink-and-wait.js @@ -2,12 +2,12 @@ const Worker = require('tiny-worker'); const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const dispatch = require('../../src/dispatch/central-dispatch'); 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. dispatch.workerClass = Worker; diff --git a/test/integration/sensing.js b/test/integration/sensing.js index 1d7d30852..7b6869515 100644 --- a/test/integration/sensing.js +++ b/test/integration/sensing.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/sensing.sb2'); -const project = extract(uri); +const project = readAsBuffer(uri); test('sensing', t => { const vm = new VirtualMachine(); diff --git a/test/integration/sound.js b/test/integration/sound.js index 1c5f20dcd..61bc5d473 100644 --- a/test/integration/sound.js +++ b/test/integration/sound.js @@ -2,12 +2,12 @@ const Worker = require('tiny-worker'); const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); const dispatch = require('../../src/dispatch/central-dispatch'); 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. dispatch.workerClass = Worker; diff --git a/test/integration/stack-click.js b/test/integration/stack-click.js index 1243eed6a..b036aec5c 100644 --- a/test/integration/stack-click.js +++ b/test/integration/stack-click.js @@ -1,11 +1,11 @@ const path = require('path'); const test = require('tap').test; const makeTestStorage = require('../fixtures/make-test-storage'); -const extract = require('../fixtures/extract'); +const readAsBuffer = require('../fixtures/readProjectFile').readAsBuffer; const VirtualMachine = require('../../src/index'); 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 diff --git a/test/unit/serialization_sb2.js b/test/unit/serialization_sb2.js index 933baa3e0..43a3cf02f 100644 --- a/test/unit/serialization_sb2.js +++ b/test/unit/serialization_sb2.js @@ -1,6 +1,6 @@ const path = require('path'); const test = require('tap').test; -const extract = require('../fixtures/extract'); +const readAsString = require('../fixtures/readProjectFile').readAsString; const RenderedTarget = require('../../src/sprites/rendered-target'); const Runtime = require('../../src/engine/runtime'); @@ -15,7 +15,7 @@ test('spec', t => { test('default', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/default.sb2'); - const file = extract(uri); + const file = readAsString(uri); const json = JSON.parse(file); // Create runtime instance & load SB2 into it @@ -55,7 +55,7 @@ test('default', t => { test('data scoping', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/data.sb2'); - const file = extract(uri); + const file = readAsString(uri); const json = JSON.parse(file); // Create runtime instance & load SB2 into it @@ -72,7 +72,7 @@ test('data scoping', t => { test('whenclicked blocks imported separately', t => { // This sb2 fixture has a single "whenClicked" block on both sprite and stage const uri = path.resolve(__dirname, '../fixtures/when-clicked.sb2'); - const file = extract(uri); + const file = readAsString(uri); const json = JSON.parse(file); // Create runtime instance & load SB2 into it