From b2a4f563a0eaafdf0bfe5fdb3848ea4e89801a7b Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Thu, 5 Apr 2018 13:58:45 -0400 Subject: [PATCH] Pull JSON.parse into extractProjectJson function. --- test/fixtures/readProjectFile.js | 2 +- test/integration/import-sb2-from-object.js | 2 +- test/integration/import_sb2.js | 4 +--- test/unit/serialization_sb2.js | 10 +++------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/fixtures/readProjectFile.js b/test/fixtures/readProjectFile.js index 6b8e5777..82231cbf 100644 --- a/test/fixtures/readProjectFile.js +++ b/test/fixtures/readProjectFile.js @@ -7,6 +7,6 @@ module.exports = { }, extractProjectJson: function (path) { const zip = new AdmZip(path); - return zip.readAsText('project.json', 'utf8'); + return JSON.parse(zip.readAsText('project.json', 'utf8')); } }; diff --git a/test/integration/import-sb2-from-object.js b/test/integration/import-sb2-from-object.js index 8a07b3c7..43397d09 100644 --- a/test/integration/import-sb2-from-object.js +++ b/test/integration/import-sb2-from-object.js @@ -5,7 +5,7 @@ const extractProjectJson = require('../fixtures/readProjectFile').extractProject const VirtualMachine = require('../../src/index'); const uri = path.resolve(__dirname, '../fixtures/default.sb2'); -const project = JSON.parse(extractProjectJson(uri)); +const project = extractProjectJson(uri); test('default', t => { const vm = new VirtualMachine(); diff --git a/test/integration/import_sb2.js b/test/integration/import_sb2.js index 61da0110..04c41d46 100644 --- a/test/integration/import_sb2.js +++ b/test/integration/import_sb2.js @@ -15,15 +15,13 @@ test('spec', t => { test('default', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/default.sb2'); - const file = extractProjectJson(uri); - const json = JSON.parse(file); + const json = extractProjectJson(uri); // Create runtime instance & load SB2 into it const rt = new runtime(); rt.attachStorage(makeTestStorage()); sb2.deserialize(json, rt).then(({targets}) => { // Test - t.type(file, 'string'); t.type(json, 'object'); t.type(rt, 'object'); t.type(targets, 'object'); diff --git a/test/unit/serialization_sb2.js b/test/unit/serialization_sb2.js index 356e9d2d..4d8c906b 100644 --- a/test/unit/serialization_sb2.js +++ b/test/unit/serialization_sb2.js @@ -15,14 +15,12 @@ test('spec', t => { test('default', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/default.sb2'); - const file = extractProjectJson(uri); - const json = JSON.parse(file); + const json = extractProjectJson(uri); // Create runtime instance & load SB2 into it const rt = new Runtime(); sb2.deserialize(json, rt).then(({targets}) => { // Test - t.type(file, 'string'); t.type(json, 'object'); t.type(rt, 'object'); t.type(targets, 'object'); @@ -55,8 +53,7 @@ test('default', t => { test('data scoping', t => { // Get SB2 JSON (string) const uri = path.resolve(__dirname, '../fixtures/data.sb2'); - const file = extractProjectJson(uri); - const json = JSON.parse(file); + const json = extractProjectJson(uri); // Create runtime instance & load SB2 into it const rt = new Runtime(); @@ -72,8 +69,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 = extractProjectJson(uri); - const json = JSON.parse(file); + const json = extractProjectJson(uri); // Create runtime instance & load SB2 into it const rt = new Runtime();