diff --git a/.eslintrc.js b/.eslintrc.js index 36ff570d9..3010f60d3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,3 @@ module.exports = { - extends: ['scratch', 'scratch/node'] + extends: ['scratch', 'scratch/node', 'scratch/es6'] }; diff --git a/test/fixtures/attach-test-storage.js b/test/fixtures/attach-test-storage.js index 5b3dae086..3e75f5967 100644 --- a/test/fixtures/attach-test-storage.js +++ b/test/fixtures/attach-test-storage.js @@ -1,15 +1,15 @@ -var ScratchStorage = require('scratch-storage'); +const ScratchStorage = require('scratch-storage'); -var ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/'; -var PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/'; +const ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/'; +const PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/'; /** * @param {Asset} asset - calculate a URL for this asset. * @returns {string} a URL to download a project file. */ -var getProjectUrl = function (asset) { - var assetIdParts = asset.assetId.split('.'); - var assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/']; +const getProjectUrl = function (asset) { + const assetIdParts = asset.assetId.split('.'); + const assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/']; if (assetIdParts[1]) { assetUrlParts.push(assetIdParts[1]); } @@ -20,8 +20,8 @@ var getProjectUrl = function (asset) { * @param {Asset} asset - calculate a URL for this asset. * @returns {string} a URL to download a project asset (PNG, WAV, etc.) */ -var getAssetUrl = function (asset) { - var assetUrlParts = [ +const getAssetUrl = function (asset) { + const assetUrlParts = [ ASSET_SERVER, 'internalapi/asset/', asset.assetId, @@ -36,9 +36,9 @@ var getAssetUrl = function (asset) { * Construct a new instance of ScratchStorage, provide it with default web sources, and attach it to the provided VM. * @param {VirtualMachine} vm - the VM which will own the new ScratchStorage instance. */ -var attachTestStorage = function (vm) { - var storage = new ScratchStorage(); - var AssetType = storage.AssetType; +const attachTestStorage = function (vm) { + const storage = new ScratchStorage(); + const AssetType = storage.AssetType; storage.addWebSource([AssetType.Project], getProjectUrl); storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl); vm.attachStorage(storage); diff --git a/test/fixtures/extract.js b/test/fixtures/extract.js index fc33cf9ae..098261308 100644 --- a/test/fixtures/extract.js +++ b/test/fixtures/extract.js @@ -1,6 +1,6 @@ -var AdmZip = require('adm-zip'); +const AdmZip = require('adm-zip'); module.exports = function (path) { - var zip = new AdmZip(path); + const zip = new AdmZip(path); return zip.readAsText('project.json', 'utf8'); }; diff --git a/test/fixtures/fake-renderer.js b/test/fixtures/fake-renderer.js index 2865b483a..a6cc9fc32 100644 --- a/test/fixtures/fake-renderer.js +++ b/test/fixtures/fake-renderer.js @@ -1,4 +1,4 @@ -var FakeRenderer = function () { +const FakeRenderer = function () { this.unused = ''; this.x = 0; this.y = 0; diff --git a/test/integration/complex.js b/test/integration/complex.js index b8777fe14..39bc0c667 100644 --- a/test/integration/complex.js +++ b/test/integration/complex.js @@ -1,32 +1,32 @@ -var fs = require('fs'); -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const fs = require('fs'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var projectUri = path.resolve(__dirname, '../fixtures/complex.sb2'); -var project = extract(projectUri); +const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2'); +const project = extract(projectUri); -var spriteUri = path.resolve(__dirname, '../fixtures/sprite.json'); -var sprite = fs.readFileSync(spriteUri, 'utf8'); +const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json'); +const sprite = fs.readFileSync(spriteUri, 'utf8'); -test('complex', function (t) { - var vm = new VirtualMachine(); +test('complex', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length === 0); t.end(); process.nextTick(process.exit); }); // Manipulate each target - vm.on('targetsUpdate', function (data) { - var targets = data.targetList; - for (var i in targets) { + vm.on('targetsUpdate', data => { + const targets = data.targetList; + for (const i in targets) { if (targets[i].isStage === true) continue; if (targets[i].name.match(/test/)) continue; @@ -55,12 +55,12 @@ test('complex', function (t) { }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // Post IO data @@ -89,7 +89,7 @@ test('complex', function (t) { ); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/control.js b/test/integration/control.js index 0d0dbfae7..4b65a0166 100644 --- a/test/integration/control.js +++ b/test/integration/control.js @@ -1,37 +1,37 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/control.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/control.sb2'); +const project = extract(uri); -test('control', function (t) { - var vm = new VirtualMachine(); +test('control', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length > 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); }); }); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/data.js b/test/integration/data.js index 52b528c5d..ba263fec1 100644 --- a/test/integration/data.js +++ b/test/integration/data.js @@ -1,34 +1,34 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/data.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/data.sb2'); +const project = extract(uri); -test('data', function (t) { - var vm = new VirtualMachine(); +test('data', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function () { + vm.on('playgroundData', () => { // @todo Additional tests t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/event.js b/test/integration/event.js index f404b2b58..34e21c63b 100644 --- a/test/integration/event.js +++ b/test/integration/event.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/event.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/event.sb2'); +const project = extract(uri); -test('event', function (t) { - var vm = new VirtualMachine(); +test('event', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length > 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/hat-execution-order.js b/test/integration/hat-execution-order.js index 8a04d9428..44efcfa02 100644 --- a/test/integration/hat-execution-order.js +++ b/test/integration/hat-execution-order.js @@ -1,22 +1,22 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2'); -var project = extract(projectUri); +const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2'); +const project = extract(projectUri); -test('complex', function (t) { - var vm = new VirtualMachine(); +test('complex', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length === 0); - var results = vm.runtime.targets[0].lists.results.contents; + const results = vm.runtime.targets[0].lists.results.contents; t.deepEqual(results, ['3', '2', '1', 'stage']); t.end(); @@ -24,16 +24,16 @@ test('complex', function (t) { }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/import_sb2.js b/test/integration/import_sb2.js index 010148cfd..547b645ea 100644 --- a/test/integration/import_sb2.js +++ b/test/integration/import_sb2.js @@ -1,26 +1,26 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); -var renderedTarget = require('../../src/sprites/rendered-target'); -var runtime = require('../../src/engine/runtime'); -var sb2 = require('../../src/import/sb2import'); +const renderedTarget = require('../../src/sprites/rendered-target'); +const runtime = require('../../src/engine/runtime'); +const sb2 = require('../../src/import/sb2import'); -test('spec', function (t) { +test('spec', t => { t.type(sb2, 'function'); t.end(); }); -test('default', function (t) { +test('default', t => { // Get SB2 JSON (string) - var uri = path.resolve(__dirname, '../fixtures/default.sb2'); - var file = extract(uri); + const uri = path.resolve(__dirname, '../fixtures/default.sb2'); + const file = extract(uri); // Create runtime instance & load SB2 into it - var rt = new runtime(); + const rt = new runtime(); attachTestStorage(rt); - sb2(file, rt).then(function (targets) { + sb2(file, rt).then(targets => { // Test t.type(file, 'string'); t.type(rt, 'object'); diff --git a/test/integration/looks.js b/test/integration/looks.js index 5f5313e9c..d251d4f85 100644 --- a/test/integration/looks.js +++ b/test/integration/looks.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/looks.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/looks.sb2'); +const project = extract(uri); -test('looks', function (t) { - var vm = new VirtualMachine(); +test('looks', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length === 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/motion.js b/test/integration/motion.js index cbf0880e9..d8b1fc8d7 100644 --- a/test/integration/motion.js +++ b/test/integration/motion.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/motion.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/motion.sb2'); +const project = extract(uri); -test('motion', function (t) { - var vm = new VirtualMachine(); +test('motion', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length > 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/pen.js b/test/integration/pen.js index fde8a52c4..f4da55fd1 100644 --- a/test/integration/pen.js +++ b/test/integration/pen.js @@ -1,34 +1,34 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/pen.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/pen.sb2'); +const project = extract(uri); -test('pen', function (t) { - var vm = new VirtualMachine(); +test('pen', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function () { + vm.on('playgroundData', () => { // @todo Additional tests t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/procedure.js b/test/integration/procedure.js index 177b24613..4abcf1e41 100644 --- a/test/integration/procedure.js +++ b/test/integration/procedure.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/procedure.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/procedure.sb2'); +const project = extract(uri); -test('procedure', function (t) { - var vm = new VirtualMachine(); +test('procedure', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length === 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/sensing.js b/test/integration/sensing.js index f90d26d00..ca8fa1bb5 100644 --- a/test/integration/sensing.js +++ b/test/integration/sensing.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/sensing.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/sensing.sb2'); +const project = extract(uri); -test('sensing', function (t) { - var vm = new VirtualMachine(); +test('sensing', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length > 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/integration/sound.js b/test/integration/sound.js index f1f46419a..7ab101593 100644 --- a/test/integration/sound.js +++ b/test/integration/sound.js @@ -1,35 +1,35 @@ -var path = require('path'); -var test = require('tap').test; -var attachTestStorage = require('../fixtures/attach-test-storage'); -var extract = require('../fixtures/extract'); -var VirtualMachine = require('../../src/index'); +const path = require('path'); +const test = require('tap').test; +const attachTestStorage = require('../fixtures/attach-test-storage'); +const extract = require('../fixtures/extract'); +const VirtualMachine = require('../../src/index'); -var uri = path.resolve(__dirname, '../fixtures/sound.sb2'); -var project = extract(uri); +const uri = path.resolve(__dirname, '../fixtures/sound.sb2'); +const project = extract(uri); -test('sound', function (t) { - var vm = new VirtualMachine(); +test('sound', t => { + const vm = new VirtualMachine(); attachTestStorage(vm); // Evaluate playground data and exit - vm.on('playgroundData', function (e) { - var threads = JSON.parse(e.threads); + vm.on('playgroundData', e => { + const threads = JSON.parse(e.threads); t.ok(threads.length > 0); t.end(); process.nextTick(process.exit); }); // Start VM, load project, and run - t.doesNotThrow(function () { + t.doesNotThrow(() => { vm.start(); vm.clear(); vm.setCompatibilityMode(false); vm.setTurboMode(false); - vm.loadProject(project).then(function () { + vm.loadProject(project).then(() => { vm.greenFlag(); // After two seconds, get playground data and stop - setTimeout(function () { + setTimeout(() => { vm.getPlaygroundData(); vm.stopAll(); }, 2000); diff --git a/test/unit/blocks_control.js b/test/unit/blocks_control.js index 7867524ce..ddb4d9f17 100644 --- a/test/unit/blocks_control.js +++ b/test/unit/blocks_control.js @@ -1,21 +1,21 @@ -var test = require('tap').test; -var Control = require('../../src/blocks/scratch3_control'); -var Runtime = require('../../src/engine/runtime'); +const test = require('tap').test; +const Control = require('../../src/blocks/scratch3_control'); +const Runtime = require('../../src/engine/runtime'); -test('getPrimitives', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('getPrimitives', t => { + const rt = new Runtime(); + const c = new Control(rt); t.type(c.getPrimitives(), 'object'); t.end(); }); -test('repeat', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('repeat', t => { + const rt = new Runtime(); + const c = new Control(rt); // Test harness (mocks `util`) - var i = 0; - var repeat = 10; + let i = 0; + const repeat = 10; var util = { stackFrame: Object.create(null), startBranch: function () { @@ -31,13 +31,13 @@ test('repeat', function (t) { t.end(); }); -test('repeatUntil', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('repeatUntil', t => { + const rt = new Runtime(); + const c = new Control(rt); // Test harness (mocks `util`) - var i = 0; - var repeat = 10; + let i = 0; + const repeat = 10; var util = { stackFrame: Object.create(null), startBranch: function () { @@ -52,13 +52,13 @@ test('repeatUntil', function (t) { t.end(); }); -test('forever', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('forever', t => { + const rt = new Runtime(); + const c = new Control(rt); // Test harness (mocks `util`) - var i = 0; - var util = { + let i = 0; + const util = { startBranch: function (branchNum, isLoop) { i++; t.strictEqual(branchNum, 1); @@ -72,13 +72,13 @@ test('forever', function (t) { t.end(); }); -test('if / ifElse', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('if / ifElse', t => { + const rt = new Runtime(); + const c = new Control(rt); // Test harness (mocks `util`) - var i = 0; - var util = { + let i = 0; + const util = { startBranch: function (branchNum) { i += branchNum; } @@ -96,17 +96,17 @@ test('if / ifElse', function (t) { t.end(); }); -test('stop', function (t) { - var rt = new Runtime(); - var c = new Control(rt); +test('stop', t => { + const rt = new Runtime(); + const c = new Control(rt); // Test harness (mocks `util`) - var state = { + const state = { stopAll: 0, stopOtherTargetThreads: 0, stopThisScript: 0 }; - var util = { + const util = { stopAll: function () { state.stopAll++; }, diff --git a/test/unit/blocks_operators.js b/test/unit/blocks_operators.js index dc4110d25..2caf71bca 100644 --- a/test/unit/blocks_operators.js +++ b/test/unit/blocks_operators.js @@ -1,129 +1,129 @@ -var test = require('tap').test; -var Operators = require('../../src/blocks/scratch3_operators'); +const test = require('tap').test; +const Operators = require('../../src/blocks/scratch3_operators'); -var blocks = new Operators(null); +const blocks = new Operators(null); -test('getPrimitives', function (t) { +test('getPrimitives', t => { t.type(blocks.getPrimitives(), 'object'); t.end(); }); -test('add', function (t) { +test('add', t => { t.strictEqual(blocks.add({NUM1: '1', NUM2: '1'}), 2); t.strictEqual(blocks.add({NUM1: 'foo', NUM2: 'bar'}), 0); t.end(); }); -test('subtract', function (t) { +test('subtract', t => { t.strictEqual(blocks.subtract({NUM1: '1', NUM2: '1'}), 0); t.strictEqual(blocks.subtract({NUM1: 'foo', NUM2: 'bar'}), 0); t.end(); }); -test('multiply', function (t) { +test('multiply', t => { t.strictEqual(blocks.multiply({NUM1: '2', NUM2: '2'}), 4); t.strictEqual(blocks.multiply({NUM1: 'foo', NUM2: 'bar'}), 0); t.end(); }); -test('divide', function (t) { +test('divide', t => { t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1); t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo t.end(); }); -test('lt', function (t) { +test('lt', t => { t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true); t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false); t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '1'}), false); t.end(); }); -test('equals', function (t) { +test('equals', t => { t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '2'}), false); t.strictEqual(blocks.equals({OPERAND1: '2', OPERAND2: '1'}), false); t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '1'}), true); t.end(); }); -test('gt', function (t) { +test('gt', t => { t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '2'}), false); t.strictEqual(blocks.gt({OPERAND1: '2', OPERAND2: '1'}), true); t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '1'}), false); t.end(); }); -test('and', function (t) { +test('and', t => { t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: true}), true); t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: false}), false); t.strictEqual(blocks.and({OPERAND1: false, OPERAND2: false}), false); t.end(); }); -test('or', function (t) { +test('or', t => { t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: true}), true); t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: false}), true); t.strictEqual(blocks.or({OPERAND1: false, OPERAND2: false}), false); t.end(); }); -test('not', function (t) { +test('not', t => { t.strictEqual(blocks.not({OPERAND: true}), false); t.strictEqual(blocks.not({OPERAND: false}), true); t.end(); }); -test('random', function (t) { - var min = 0; - var max = 100; - var result = blocks.random({FROM: min, TO: max}); +test('random', t => { + const min = 0; + const max = 100; + const result = blocks.random({FROM: min, TO: max}); t.ok(result >= min); t.ok(result <= max); t.end(); }); -test('random - equal', function (t) { - var min = 1; - var max = 1; +test('random - equal', t => { + const min = 1; + const max = 1; t.strictEqual(blocks.random({FROM: min, TO: max}), min); t.end(); }); -test('random - decimal', function (t) { - var min = 0.1; - var max = 10; - var result = blocks.random({FROM: min, TO: max}); +test('random - decimal', t => { + const min = 0.1; + const max = 10; + const result = blocks.random({FROM: min, TO: max}); t.ok(result >= min); t.ok(result <= max); t.end(); }); -test('random - int', function (t) { - var min = 0; - var max = 10; - var result = blocks.random({FROM: min, TO: max}); +test('random - int', t => { + const min = 0; + const max = 10; + const result = blocks.random({FROM: min, TO: max}); t.ok(result >= min); t.ok(result <= max); t.end(); }); -test('random - reverse', function (t) { - var min = 0; - var max = 10; - var result = blocks.random({FROM: max, TO: min}); +test('random - reverse', t => { + const min = 0; + const max = 10; + const result = blocks.random({FROM: max, TO: min}); t.ok(result >= min); t.ok(result <= max); t.end(); }); -test('join', function (t) { +test('join', t => { t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar'); t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12'); t.end(); }); -test('letterOf', function (t) { +test('letterOf', t => { t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 0}), ''); t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 1}), 'f'); t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 2}), 'o'); @@ -133,7 +133,7 @@ test('letterOf', function (t) { t.end(); }); -test('length', function (t) { +test('length', t => { t.strictEqual(blocks.length({STRING: ''}), 0); t.strictEqual(blocks.length({STRING: 'foo'}), 3); t.strictEqual(blocks.length({STRING: '1'}), 1); @@ -141,21 +141,21 @@ test('length', function (t) { t.end(); }); -test('mod', function (t) { +test('mod', t => { t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0); t.strictEqual(blocks.mod({NUM1: 3, NUM2: 6}), 3); t.strictEqual(blocks.mod({NUM1: -3, NUM2: 6}), 3); t.end(); }); -test('round', function (t) { +test('round', t => { t.strictEqual(blocks.round({NUM: 1}), 1); t.strictEqual(blocks.round({NUM: 1.1}), 1); t.strictEqual(blocks.round({NUM: 1.5}), 2); t.end(); }); -test('mathop', function (t) { +test('mathop', t => { t.strictEqual(blocks.mathop({OPERATOR: 'abs', NUM: -1}), 1); t.strictEqual(blocks.mathop({OPERATOR: 'floor', NUM: 1.5}), 1); t.strictEqual(blocks.mathop({OPERATOR: 'ceiling', NUM: 0.1}), 1); diff --git a/test/unit/engine_adapter.js b/test/unit/engine_adapter.js index 7c6cd2da1..37ad1ea39 100644 --- a/test/unit/engine_adapter.js +++ b/test/unit/engine_adapter.js @@ -1,22 +1,22 @@ -var test = require('tap').test; -var adapter = require('../../src/engine/adapter'); -var events = require('../fixtures/events.json'); +const test = require('tap').test; +const adapter = require('../../src/engine/adapter'); +const events = require('../fixtures/events.json'); -test('spec', function (t) { +test('spec', t => { t.type(adapter, 'function'); t.end(); }); -test('invalid inputs', function (t) { - var nothing = adapter('not an object'); +test('invalid inputs', t => { + let nothing = adapter('not an object'); t.type(nothing, 'undefined'); nothing = adapter({noxmlproperty: true}); t.type(nothing, 'undefined'); t.end(); }); -test('create event', function (t) { - var result = adapter(events.create); +test('create event', t => { + const result = adapter(events.create); t.ok(Array.isArray(result)); t.equal(result.length, 2); @@ -43,8 +43,8 @@ test('create event', function (t) { t.end(); }); -test('create with branch', function (t) { - var result = adapter(events.createbranch); +test('create with branch', t => { + const result = adapter(events.createbranch); // Outer block t.type(result[0].id, 'string'); t.type(result[0].opcode, 'string'); @@ -54,13 +54,13 @@ test('create with branch', function (t) { t.type(result[0].topLevel, 'boolean'); t.equal(result[0].topLevel, true); // In branch - var branchBlockId = result[0].inputs.SUBSTACK.block; - var branchShadowId = result[0].inputs.SUBSTACK.shadow; + const branchBlockId = result[0].inputs.SUBSTACK.block; + const branchShadowId = result[0].inputs.SUBSTACK.shadow; t.type(branchBlockId, 'string'); t.equal(branchShadowId, null); // Find actual branch block - var branchBlock = null; - for (var i = 0; i < result.length; i++) { + let branchBlock = null; + for (let i = 0; i < result.length; i++) { if (result[i].id === branchBlockId) { branchBlock = result[i]; } @@ -69,8 +69,8 @@ test('create with branch', function (t) { t.end(); }); -test('create with two branches', function (t) { - var result = adapter(events.createtwobranches); +test('create with two branches', t => { + const result = adapter(events.createtwobranches); // Outer block t.type(result[0].id, 'string'); t.type(result[0].opcode, 'string'); @@ -81,18 +81,18 @@ test('create with two branches', function (t) { t.type(result[0].topLevel, 'boolean'); t.equal(result[0].topLevel, true); // In branchs - var firstBranchBlockId = result[0].inputs.SUBSTACK.block; - var secondBranchBlockId = result[0].inputs.SUBSTACK2.block; + const firstBranchBlockId = result[0].inputs.SUBSTACK.block; + const secondBranchBlockId = result[0].inputs.SUBSTACK2.block; t.type(firstBranchBlockId, 'string'); t.type(secondBranchBlockId, 'string'); - var firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow; - var secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow; + const firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow; + const secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow; t.equal(firstBranchShadowBlockId, null); t.equal(secondBranchShadowBlockId, null); // Find actual branch blocks - var firstBranchBlock = null; - var secondBranchBlock = null; - for (var i = 0; i < result.length; i++) { + let firstBranchBlock = null; + let secondBranchBlock = null; + for (let i = 0; i < result.length; i++) { if (result[i].id === firstBranchBlockId) { firstBranchBlock = result[i]; } @@ -105,8 +105,8 @@ test('create with two branches', function (t) { t.end(); }); -test('create with top-level shadow', function (t) { - var result = adapter(events.createtoplevelshadow); +test('create with top-level shadow', t => { + const result = adapter(events.createtoplevelshadow); t.ok(Array.isArray(result)); t.equal(result.length, 1); @@ -120,8 +120,8 @@ test('create with top-level shadow', function (t) { t.end(); }); -test('create with next connection', function (t) { - var result = adapter(events.createwithnext); +test('create with next connection', t => { + const result = adapter(events.createwithnext); t.ok(Array.isArray(result)); t.equal(result.length, 2); @@ -148,21 +148,21 @@ test('create with next connection', function (t) { t.end(); }); -test('create with obscured shadow', function (t) { - var result = adapter(events.createobscuredshadow); +test('create with obscured shadow', t => { + const result = adapter(events.createobscuredshadow); t.ok(Array.isArray(result)); t.equal(result.length, 4); t.end(); }); -test('create with invalid block xml', function (t) { +test('create with invalid block xml', t => { // Entirely invalid block XML - var result = adapter(events.createinvalid); + const result = adapter(events.createinvalid); t.ok(Array.isArray(result)); t.equal(result.length, 0); // Invalid grandchild tag - var result2 = adapter(events.createinvalidgrandchild); + const result2 = adapter(events.createinvalidgrandchild); t.ok(Array.isArray(result2)); t.equal(result2.length, 1); t.type(result2[0].id, 'string'); @@ -172,15 +172,15 @@ test('create with invalid block xml', function (t) { t.end(); }); -test('create with invalid xml', function (t) { - var result = adapter(events.createbadxml); +test('create with invalid xml', t => { + const result = adapter(events.createbadxml); t.ok(Array.isArray(result)); t.equal(result.length, 0); t.end(); }); -test('create with empty field', function (t) { - var result = adapter(events.createemptyfield); +test('create with empty field', t => { + const result = adapter(events.createemptyfield); t.ok(Array.isArray(result)); t.equal(result.length, 3); t.end(); diff --git a/test/unit/engine_blocks.js b/test/unit/engine_blocks.js index cfb3cdd9c..1055cda68 100644 --- a/test/unit/engine_blocks.js +++ b/test/unit/engine_blocks.js @@ -1,8 +1,8 @@ -var test = require('tap').test; -var Blocks = require('../../src/engine/blocks'); +const test = require('tap').test; +const Blocks = require('../../src/engine/blocks'); -test('spec', function (t) { - var b = new Blocks(); +test('spec', t => { + const b = new Blocks(); t.type(Blocks, 'function'); t.type(b, 'object'); @@ -27,8 +27,8 @@ test('spec', function (t) { }); // Getter tests -test('getBlock', function (t) { - var b = new Blocks(); +test('getBlock', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -37,16 +37,16 @@ test('getBlock', function (t) { inputs: {}, topLevel: true }); - var block = b.getBlock('foo'); + const block = b.getBlock('foo'); t.type(block, 'object'); - var notBlock = b.getBlock('?'); + const notBlock = b.getBlock('?'); t.type(notBlock, 'undefined'); t.end(); }); -test('getScripts', function (t) { - var b = new Blocks(); - var scripts = b.getScripts(); +test('getScripts', t => { + const b = new Blocks(); + let scripts = b.getScripts(); t.type(scripts, 'object'); t.equals(scripts.length, 0); // Create two top-level blocks and one not. @@ -85,8 +85,8 @@ test('getScripts', function (t) { }); -test('getNextBlock', function (t) { - var b = new Blocks(); +test('getNextBlock', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -96,7 +96,7 @@ test('getNextBlock', function (t) { topLevel: true }); - var next = b.getNextBlock('foo'); + let next = b.getNextBlock('foo'); t.equals(next, null); // Add a block with "foo" as its next. @@ -113,14 +113,14 @@ test('getNextBlock', function (t) { t.equals(next, 'foo'); // Block that doesn't exist. - var noBlock = b.getNextBlock('?'); + const noBlock = b.getNextBlock('?'); t.equals(noBlock, null); t.end(); }); -test('getBranch', function (t) { - var b = new Blocks(); +test('getBranch', t => { + const b = new Blocks(); // Single branch b.createBlock({ id: 'foo', @@ -145,17 +145,17 @@ test('getBranch', function (t) { topLevel: false }); - var branch = b.getBranch('foo'); + const branch = b.getBranch('foo'); t.equals(branch, 'foo2'); - var notBranch = b.getBranch('?'); + const notBranch = b.getBranch('?'); t.equals(notBranch, null); t.end(); }); -test('getBranch2', function (t) { - var b = new Blocks(); +test('getBranch2', t => { + const b = new Blocks(); // Second branch b.createBlock({ id: 'foo', @@ -193,16 +193,16 @@ test('getBranch2', function (t) { topLevel: false }); - var branch1 = b.getBranch('foo', 1); - var branch2 = b.getBranch('foo', 2); + const branch1 = b.getBranch('foo', 1); + const branch2 = b.getBranch('foo', 2); t.equals(branch1, 'foo2'); t.equals(branch2, 'foo3'); t.end(); }); -test('getBranch with none', function (t) { - var b = new Blocks(); +test('getBranch with none', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -211,14 +211,14 @@ test('getBranch with none', function (t) { inputs: {}, topLevel: true }); - var noBranch = b.getBranch('foo'); + const noBranch = b.getBranch('foo'); t.equals(noBranch, null); t.end(); }); -test('getOpcode', function (t) { - var b = new Blocks(); - var block = { +test('getOpcode', t => { + const b = new Blocks(); + const block = { id: 'foo', opcode: 'TEST_BLOCK', next: null, @@ -227,17 +227,17 @@ test('getOpcode', function (t) { topLevel: true }; b.createBlock(block); - var opcode = b.getOpcode(block); + const opcode = b.getOpcode(block); t.equals(opcode, 'TEST_BLOCK'); - var undefinedBlock = b.getBlock('?'); - var undefinedOpcode = b.getOpcode(undefinedBlock); + const undefinedBlock = b.getBlock('?'); + const undefinedOpcode = b.getOpcode(undefinedBlock); t.equals(undefinedOpcode, null); t.end(); }); // Block events tests -test('create', function (t) { - var b = new Blocks(); +test('create', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -253,8 +253,8 @@ test('create', function (t) { t.end(); }); -test('move', function (t) { - var b = new Blocks(); +test('move', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -293,8 +293,8 @@ test('move', function (t) { t.end(); }); -test('move into empty', function (t) { - var b = new Blocks(); +test('move into empty', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -320,8 +320,8 @@ test('move into empty', function (t) { t.end(); }); -test('move no obscure shadow', function (t) { - var b = new Blocks(); +test('move no obscure shadow', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -354,8 +354,8 @@ test('move no obscure shadow', function (t) { t.end(); }); -test('change', function (t) { - var b = new Blocks(); +test('change', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -411,8 +411,8 @@ test('change', function (t) { t.end(); }); -test('delete', function (t) { - var b = new Blocks(); +test('delete', t => { + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -430,10 +430,10 @@ test('delete', function (t) { t.end(); }); -test('delete chain', function (t) { +test('delete chain', t => { // Create a chain of connected blocks and delete the top one. // All of them should be deleted. - var b = new Blocks(); + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', @@ -470,10 +470,10 @@ test('delete chain', function (t) { t.end(); }); -test('delete inputs', function (t) { +test('delete inputs', t => { // Create a block with two inputs, one of which has its own input. // Delete the block - all of them should be deleted. - var b = new Blocks(); + const b = new Blocks(); b.createBlock({ id: 'foo', opcode: 'TEST_BLOCK', diff --git a/test/unit/engine_runtime.js b/test/unit/engine_runtime.js index 40757c054..be431186d 100644 --- a/test/unit/engine_runtime.js +++ b/test/unit/engine_runtime.js @@ -1,8 +1,8 @@ -var test = require('tap').test; -var Runtime = require('../../src/engine/runtime'); +const test = require('tap').test; +const Runtime = require('../../src/engine/runtime'); -test('spec', function (t) { - var r = new Runtime(); +test('spec', t => { + const r = new Runtime(); t.type(Runtime, 'function'); t.type(r, 'object'); diff --git a/test/unit/engine_sequencer.js b/test/unit/engine_sequencer.js index 1e000ad36..e5dcd0be7 100644 --- a/test/unit/engine_sequencer.js +++ b/test/unit/engine_sequencer.js @@ -1,15 +1,15 @@ -var test = require('tap').test; -var Sequencer = require('../../src/engine/sequencer'); -var Runtime = require('../../src/engine/runtime'); -var Thread = require('../../src/engine/thread'); -var RenderedTarget = require('../../src/sprites/rendered-target'); -var Sprite = require('../../src/sprites/sprite'); +const test = require('tap').test; +const Sequencer = require('../../src/engine/sequencer'); +const Runtime = require('../../src/engine/runtime'); +const Thread = require('../../src/engine/thread'); +const RenderedTarget = require('../../src/sprites/rendered-target'); +const Sprite = require('../../src/sprites/sprite'); -test('spec', function (t) { +test('spec', t => { t.type(Sequencer, 'function'); - var r = new Runtime(); - var s = new Sequencer(r); + const r = new Runtime(); + const s = new Sequencer(r); t.type(s, 'object'); t.ok(s instanceof Sequencer); @@ -23,13 +23,13 @@ test('spec', function (t) { t.end(); }); -var randomString = function () { - var top = Math.random().toString(36); +const randomString = function () { + const top = Math.random().toString(36); return top.substring(7); }; -var generateBlock = function (id) { - var block = {fields: Object, +const generateBlock = function (id) { + const block = {fields: Object, id: id, inputs: {}, STEPS: Object, @@ -47,8 +47,8 @@ var generateBlock = function (id) { return block; }; -var generateBlockInput = function (id, next, inp) { - var block = {fields: Object, +const generateBlockInput = function (id, next, inp) { + const block = {fields: Object, id: id, inputs: {SUBSTACK: {block: inp, name: 'SUBSTACK'}}, STEPS: Object, @@ -66,20 +66,20 @@ var generateBlockInput = function (id, next, inp) { return block; }; -var generateThread = function (runtime) { - var s = new Sprite(); - var rt = new RenderedTarget(s, runtime); - var th = new Thread(randomString()); +const generateThread = function (runtime) { + const s = new Sprite(); + const rt = new RenderedTarget(s, runtime); + const th = new Thread(randomString()); - var next = randomString(); - var inp = randomString(); - var name = th.topBlock; + let next = randomString(); + let inp = randomString(); + let name = th.topBlock; rt.blocks.createBlock(generateBlockInput(name, next, inp)); th.pushStack(name); rt.blocks.createBlock(generateBlock(inp)); - for (var i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { name = next; next = randomString(); inp = randomString(); @@ -97,10 +97,10 @@ var generateThread = function (runtime) { return th; }; -test('stepThread', function (t) { - var r = new Runtime(); - var s = new Sequencer(r); - var th = generateThread(r); +test('stepThread', t => { + const r = new Runtime(); + const s = new Sequencer(r); + let th = generateThread(r); t.notEquals(th.status, Thread.STATUS_DONE); s.stepThread(th); t.strictEquals(th.status, Thread.STATUS_DONE); @@ -115,10 +115,10 @@ test('stepThread', function (t) { t.end(); }); -test('stepToBranch', function (t) { - var r = new Runtime(); - var s = new Sequencer(r); - var th = generateThread(r); +test('stepToBranch', t => { + const r = new Runtime(); + const s = new Sequencer(r); + const th = generateThread(r); s.stepToBranch(th, 2, false); t.strictEquals(th.peekStack(), null); th.popStack(); @@ -132,10 +132,10 @@ test('stepToBranch', function (t) { t.end(); }); -test('retireThread', function (t) { - var r = new Runtime(); - var s = new Sequencer(r); - var th = generateThread(r); +test('retireThread', t => { + const r = new Runtime(); + const s = new Sequencer(r); + const th = generateThread(r); t.strictEquals(th.stack.length, 12); s.retireThread(th); t.strictEquals(th.stack.length, 0); @@ -144,11 +144,11 @@ test('retireThread', function (t) { t.end(); }); -test('stepToProcedure', function (t) { - var r = new Runtime(); - var s = new Sequencer(r); - var th = generateThread(r); - var expectedBlock = th.peekStack(); +test('stepToProcedure', t => { + const r = new Runtime(); + const s = new Sequencer(r); + const th = generateThread(r); + let expectedBlock = th.peekStack(); s.stepToProcedure(th, ''); t.strictEquals(th.peekStack(), expectedBlock); s.stepToProcedure(th, 'faceCode'); @@ -163,10 +163,10 @@ test('stepToProcedure', function (t) { t.end(); }); -test('stepThreads', function (t) { - var r = new Runtime(); +test('stepThreads', t => { + const r = new Runtime(); r.currentStepTime = Infinity; - var s = new Sequencer(r); + const s = new Sequencer(r); t.strictEquals(s.stepThreads().length, 0); generateThread(r); t.strictEquals(r.threads.length, 1); diff --git a/test/unit/engine_thread.js b/test/unit/engine_thread.js index 815de5ca3..60419d360 100644 --- a/test/unit/engine_thread.js +++ b/test/unit/engine_thread.js @@ -1,12 +1,12 @@ -var test = require('tap').test; -var Thread = require('../../src/engine/thread'); -var RenderedTarget = require('../../src/sprites/rendered-target'); -var Sprite = require('../../src/sprites/sprite'); +const test = require('tap').test; +const Thread = require('../../src/engine/thread'); +const RenderedTarget = require('../../src/sprites/rendered-target'); +const Sprite = require('../../src/sprites/sprite'); -test('spec', function (t) { +test('spec', t => { t.type(Thread, 'function'); - var th = new Thread('arbitraryString'); + const th = new Thread('arbitraryString'); t.type(th, 'object'); t.ok(th instanceof Thread); t.type(th.pushStack, 'function'); @@ -27,15 +27,15 @@ test('spec', function (t) { t.end(); }); -test('pushStack', function (t) { - var th = new Thread('arbitraryString'); +test('pushStack', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); t.end(); }); -test('popStack', function (t) { - var th = new Thread('arbitraryString'); +test('popStack', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); t.strictEquals(th.popStack(), 'arbitraryString'); t.strictEquals(th.popStack(), undefined); @@ -43,8 +43,8 @@ test('popStack', function (t) { t.end(); }); -test('atStackTop', function (t) { - var th = new Thread('arbitraryString'); +test('atStackTop', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); th.pushStack('secondString'); t.strictEquals(th.atStackTop(), false); @@ -54,8 +54,8 @@ test('atStackTop', function (t) { t.end(); }); -test('reuseStackForNextBlock', function (t) { - var th = new Thread('arbitraryString'); +test('reuseStackForNextBlock', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); th.reuseStackForNextBlock('secondString'); t.strictEquals(th.popStack(), 'secondString'); @@ -63,8 +63,8 @@ test('reuseStackForNextBlock', function (t) { t.end(); }); -test('peekStackFrame', function (t) { - var th = new Thread('arbitraryString'); +test('peekStackFrame', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); t.strictEquals(th.peekStackFrame().warpMode, false); th.popStack(); @@ -73,8 +73,8 @@ test('peekStackFrame', function (t) { t.end(); }); -test('peekParentStackFrame', function (t) { - var th = new Thread('arbitraryString'); +test('peekParentStackFrame', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); th.peekStackFrame().warpMode = true; t.strictEquals(th.peekParentStackFrame(), null); @@ -84,8 +84,8 @@ test('peekParentStackFrame', function (t) { t.end(); }); -test('pushReportedValue', function (t) { - var th = new Thread('arbitraryString'); +test('pushReportedValue', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); th.pushStack('secondString'); th.pushReportedValue('value'); @@ -94,8 +94,8 @@ test('pushReportedValue', function (t) { t.end(); }); -test('peekStack', function (t) { - var th = new Thread('arbitraryString'); +test('peekStack', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); t.strictEquals(th.peekStack(), 'arbitraryString'); th.popStack(); @@ -104,8 +104,8 @@ test('peekStack', function (t) { t.end(); }); -test('PushGetParam', function (t) { - var th = new Thread('arbitraryString'); +test('PushGetParam', t => { + const th = new Thread('arbitraryString'); th.pushStack('arbitraryString'); th.pushParam('testParam', 'testValue'); t.strictEquals(th.peekStackFrame().params.testParam, 'testValue'); @@ -114,11 +114,11 @@ test('PushGetParam', function (t) { t.end(); }); -test('goToNextBlock', function (t) { - var th = new Thread('arbitraryString'); - var s = new Sprite(); - var rt = new RenderedTarget(s, null); - var block1 = {fields: Object, +test('goToNextBlock', t => { + const th = new Thread('arbitraryString'); + const s = new Sprite(); + const rt = new RenderedTarget(s, null); + const block1 = {fields: Object, id: 'arbitraryString', inputs: Object, STEPS: Object, @@ -132,7 +132,7 @@ test('goToNextBlock', function (t) { x: 0, y: 0 }; - var block2 = {fields: Object, + const block2 = {fields: Object, id: 'secondString', inputs: Object, STEPS: Object, @@ -169,11 +169,11 @@ test('goToNextBlock', function (t) { t.end(); }); -test('stopThisScript', function (t) { - var th = new Thread('arbitraryString'); - var s = new Sprite(); - var rt = new RenderedTarget(s, null); - var block1 = {fields: Object, +test('stopThisScript', t => { + const th = new Thread('arbitraryString'); + const s = new Sprite(); + const rt = new RenderedTarget(s, null); + const block1 = {fields: Object, id: 'arbitraryString', inputs: Object, STEPS: Object, @@ -187,7 +187,7 @@ test('stopThisScript', function (t) { x: 0, y: 0 }; - var block2 = {fields: Object, + const block2 = {fields: Object, id: 'secondString', inputs: Object, STEPS: Object, @@ -221,11 +221,11 @@ test('stopThisScript', function (t) { t.end(); }); -test('isRecursiveCall', function (t) { - var th = new Thread('arbitraryString'); - var s = new Sprite(); - var rt = new RenderedTarget(s, null); - var block1 = {fields: Object, +test('isRecursiveCall', t => { + const th = new Thread('arbitraryString'); + const s = new Sprite(); + const rt = new RenderedTarget(s, null); + const block1 = {fields: Object, id: 'arbitraryString', inputs: Object, STEPS: Object, @@ -239,7 +239,7 @@ test('isRecursiveCall', function (t) { x: 0, y: 0 }; - var block2 = {fields: Object, + const block2 = {fields: Object, id: 'secondString', inputs: Object, STEPS: Object, diff --git a/test/unit/io_clock.js b/test/unit/io_clock.js index 12989fcff..1978911e6 100644 --- a/test/unit/io_clock.js +++ b/test/unit/io_clock.js @@ -1,10 +1,10 @@ -var test = require('tap').test; -var Clock = require('../../src/io/clock'); -var Runtime = require('../../src/engine/runtime'); +const test = require('tap').test; +const Clock = require('../../src/io/clock'); +const Runtime = require('../../src/engine/runtime'); -test('spec', function (t) { - var rt = new Runtime(); - var c = new Clock(rt); +test('spec', t => { + const rt = new Runtime(); + const c = new Clock(rt); t.type(Clock, 'function'); t.type(c, 'object'); @@ -15,14 +15,14 @@ test('spec', function (t) { t.end(); }); -test('cycle', function (t) { - var rt = new Runtime(); - var c = new Clock(rt); +test('cycle', t => { + const rt = new Runtime(); + const c = new Clock(rt); t.ok(c.projectTimer() <= 0.1); - setTimeout(function () { + setTimeout(() => { c.resetProjectTimer(); - setTimeout(function () { + setTimeout(() => { t.ok(c.projectTimer() > 0); c.pause(); t.ok(c.projectTimer() > 0); diff --git a/test/unit/io_keyboard.js b/test/unit/io_keyboard.js index ad3a65c6d..a0a38f746 100644 --- a/test/unit/io_keyboard.js +++ b/test/unit/io_keyboard.js @@ -1,10 +1,10 @@ -var test = require('tap').test; -var Keyboard = require('../../src/io/keyboard'); -var Runtime = require('../../src/engine/runtime'); +const test = require('tap').test; +const Keyboard = require('../../src/io/keyboard'); +const Runtime = require('../../src/engine/runtime'); -test('spec', function (t) { - var rt = new Runtime(); - var k = new Keyboard(rt); +test('spec', t => { + const rt = new Runtime(); + const k = new Keyboard(rt); t.type(k, 'object'); t.type(k.postData, 'function'); @@ -12,9 +12,9 @@ test('spec', function (t) { t.end(); }); -test('space', function (t) { - var rt = new Runtime(); - var k = new Keyboard(rt); +test('space', t => { + const rt = new Runtime(); + const k = new Keyboard(rt); k.postData({ keyCode: 32, @@ -26,9 +26,9 @@ test('space', function (t) { t.end(); }); -test('letter', function (t) { - var rt = new Runtime(); - var k = new Keyboard(rt); +test('letter', t => { + const rt = new Runtime(); + const k = new Keyboard(rt); k.postData({ keyCode: 65, @@ -40,9 +40,9 @@ test('letter', function (t) { t.end(); }); -test('number', function (t) { - var rt = new Runtime(); - var k = new Keyboard(rt); +test('number', t => { + const rt = new Runtime(); + const k = new Keyboard(rt); k.postData({ keyCode: 49, @@ -54,9 +54,9 @@ test('number', function (t) { t.end(); }); -test('keyup', function (t) { - var rt = new Runtime(); - var k = new Keyboard(rt); +test('keyup', t => { + const rt = new Runtime(); + const k = new Keyboard(rt); k.postData({ keyCode: 37, diff --git a/test/unit/io_mouse.js b/test/unit/io_mouse.js index ae4f3fe63..919786663 100644 --- a/test/unit/io_mouse.js +++ b/test/unit/io_mouse.js @@ -1,10 +1,10 @@ -var test = require('tap').test; -var Mouse = require('../../src/io/mouse'); -var Runtime = require('../../src/engine/runtime'); +const test = require('tap').test; +const Mouse = require('../../src/io/mouse'); +const Runtime = require('../../src/engine/runtime'); -test('spec', function (t) { - var rt = new Runtime(); - var m = new Mouse(rt); +test('spec', t => { + const rt = new Runtime(); + const m = new Mouse(rt); t.type(m, 'object'); t.type(m.postData, 'function'); @@ -14,9 +14,9 @@ test('spec', function (t) { t.end(); }); -test('mouseUp', function (t) { - var rt = new Runtime(); - var m = new Mouse(rt); +test('mouseUp', t => { + const rt = new Runtime(); + const m = new Mouse(rt); m.postData({ x: 1, @@ -31,9 +31,9 @@ test('mouseUp', function (t) { t.end(); }); -test('mouseDown', function (t) { - var rt = new Runtime(); - var m = new Mouse(rt); +test('mouseDown', t => { + const rt = new Runtime(); + const m = new Mouse(rt); m.postData({ x: 10, diff --git a/test/unit/spec.js b/test/unit/spec.js index b16f181f0..7e2115567 100644 --- a/test/unit/spec.js +++ b/test/unit/spec.js @@ -1,8 +1,8 @@ -var test = require('tap').test; -var VirtualMachine = require('../../src/index'); +const test = require('tap').test; +const VirtualMachine = require('../../src/index'); -test('interface', function (t) { - var vm = new VirtualMachine(); +test('interface', t => { + const vm = new VirtualMachine(); t.type(vm, 'object'); t.type(vm.start, 'function'); t.type(vm.greenFlag, 'function'); diff --git a/test/unit/sprites_rendered-target.js b/test/unit/sprites_rendered-target.js index e22f364ba..3f8ee2c37 100644 --- a/test/unit/sprites_rendered-target.js +++ b/test/unit/sprites_rendered-target.js @@ -1,24 +1,24 @@ -var test = require('tap').test; -var RenderedTarget = require('../../src/sprites/rendered-target'); -var Sprite = require('../../src/sprites/sprite'); -var Runtime = require('../../src/engine/runtime'); -var FakeRenderer = require('../fixtures/fake-renderer'); +const test = require('tap').test; +const RenderedTarget = require('../../src/sprites/rendered-target'); +const Sprite = require('../../src/sprites/sprite'); +const Runtime = require('../../src/engine/runtime'); +const FakeRenderer = require('../fixtures/fake-renderer'); -test('clone effects', function (t) { +test('clone effects', t => { // Create two clones and ensure they have different graphic effect objects. // Regression test for Github issue #224 - var spr = new Sprite(); - var a = new RenderedTarget(spr, null); - var b = new RenderedTarget(spr, null); + const spr = new Sprite(); + const a = new RenderedTarget(spr, null); + const b = new RenderedTarget(spr, null); t.ok(a.effects !== b.effects); t.end(); }); -test('setxy', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('setxy', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setXY(123, 321, true); t.equals(a.x, 123); @@ -26,54 +26,54 @@ test('setxy', function (t) { t.end(); }); -test('direction', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('direction', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setDirection(123); t.equals(a._getRenderedDirectionAndScale().direction, 123); t.end(); }); -test('setSay', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('setSay', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setSay(); a.setSay('types not specified', 'message'); t.end(); }); -test('setVisible', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('setVisible', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setVisible(true); t.end(); }); -test('setSize', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('setSize', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setSize(123); t.equals(a._getRenderedDirectionAndScale().scale[0], 123); t.end(); }); -test('set and clear effects', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('set and clear effects', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; for (var effect in a.effects) { a.setEffect(effect, 1); @@ -86,34 +86,34 @@ test('set and clear effects', function (t) { t.end(); }); -test('setCostume', function (t) { - var o = new Object(); - var s = new Sprite(); - var r = new Runtime(); +test('setCostume', t => { + const o = new Object(); + const s = new Sprite(); + const r = new Runtime(); s.costumes = [o]; - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setCostume(0); t.end(); }); -test('setRotationStyle', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var renderer = new FakeRenderer(); +test('setRotationStyle', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const renderer = new FakeRenderer(); a.renderer = renderer; a.setRotationStyle(RenderedTarget.ROTATION_STYLE_NONE); t.end(); }); -test('getBounds', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('getBounds', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.getBounds().top, 0); a.setXY(241, 241); @@ -121,23 +121,23 @@ test('getBounds', function (t) { t.end(); }); -test('isTouchingPoint', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('isTouchingPoint', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.isTouchingPoint(), true); t.end(); }); -test('isTouchingEdge', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('isTouchingEdge', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.isTouchingEdge(), false); a.setXY(1000, 1000); @@ -145,46 +145,46 @@ test('isTouchingEdge', function (t) { t.end(); }); -test('isTouchingSprite', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('isTouchingSprite', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.isTouchingSprite('fake'), false); t.end(); }); -test('isTouchingColor', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('isTouchingColor', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.isTouchingColor(), false); t.end(); }); -test('colorIsTouchingColor', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('colorIsTouchingColor', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.colorIsTouchingColor(), false); t.end(); }); -test('layers', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); - var o = new Object(); +test('layers', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); + const o = new Object(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; a.goToFront(); t.equals(a.renderer.order, 5); @@ -196,12 +196,12 @@ test('layers', function (t) { t.end(); }); -test('keepInFence', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var renderer = new FakeRenderer(); +test('keepInFence', t => { + const s = new Sprite(); + const r = new Runtime(); + const renderer = new FakeRenderer(); r.attachRenderer(renderer); - var a = new RenderedTarget(s, r); + const a = new RenderedTarget(s, r); a.renderer = renderer; t.equals(a.keepInFence(1000, 1000)[0], 240); t.equals(a.keepInFence(-1000, 1000)[0], -240); @@ -210,40 +210,40 @@ test('keepInFence', function (t) { t.end(); }); -test('#stopAll clears graphics effects', function (t) { - var s = new Sprite(); - var r = new Runtime(); - var a = new RenderedTarget(s, r); - var effectName = 'brightness'; +test('#stopAll clears graphics effects', t => { + const s = new Sprite(); + const r = new Runtime(); + const a = new RenderedTarget(s, r); + const effectName = 'brightness'; a.setEffect(effectName, 100); a.onStopAll(); t.equals(a.effects[effectName], 0); t.end(); }); -test('#getCostumes returns the costumes', function (t) { - var spr = new Sprite(); - var a = new RenderedTarget(spr, null); - var costumes = [1, 2, 3]; +test('#getCostumes returns the costumes', t => { + const spr = new Sprite(); + const a = new RenderedTarget(spr, null); + const costumes = [1, 2, 3]; a.sprite.costumes = costumes; t.equals(a.getCostumes(), costumes); t.end(); }); -test('#getSounds returns the sounds', function (t) { - var spr = new Sprite(); - var a = new RenderedTarget(spr, null); - var sounds = [1, 2, 3]; +test('#getSounds returns the sounds', t => { + const spr = new Sprite(); + const a = new RenderedTarget(spr, null); + const sounds = [1, 2, 3]; a.sprite.sounds = sounds; t.equals(a.getSounds(), sounds); t.end(); }); -test('#toJSON returns the sounds and costumes', function (t) { - var spr = new Sprite(); - var a = new RenderedTarget(spr, null); - var sounds = [1, 2, 3]; - var costumes = ['a', 'b', 'c']; +test('#toJSON returns the sounds and costumes', t => { + const spr = new Sprite(); + const a = new RenderedTarget(spr, null); + const sounds = [1, 2, 3]; + const costumes = ['a', 'b', 'c']; a.sprite.sounds = sounds; a.sprite.costumes = costumes; t.same(a.toJSON().sounds, sounds); diff --git a/test/unit/util_cast.js b/test/unit/util_cast.js index 861373bb2..8d30df368 100644 --- a/test/unit/util_cast.js +++ b/test/unit/util_cast.js @@ -1,7 +1,7 @@ -var test = require('tap').test; -var cast = require('../../src/util/cast'); +const test = require('tap').test; +const cast = require('../../src/util/cast'); -test('toNumber', function (t) { +test('toNumber', t => { // Numeric t.strictEqual(cast.toNumber(0), 0); t.strictEqual(cast.toNumber(1), 1); @@ -27,7 +27,7 @@ test('toNumber', function (t) { t.end(); }); -test('toBoolean', function (t) { +test('toBoolean', t => { // Numeric t.strictEqual(cast.toBoolean(0), false); t.strictEqual(cast.toBoolean(1), true); @@ -50,7 +50,7 @@ test('toBoolean', function (t) { t.end(); }); -test('toString', function (t) { +test('toString', t => { // Numeric t.strictEqual(cast.toString(0), '0'); t.strictEqual(cast.toString(1), '1'); @@ -73,7 +73,7 @@ test('toString', function (t) { t.end(); }); -test('toRbgColorList', function (t) { +test('toRbgColorList', t => { // Hex (minimal, see "color" util tests) t.deepEqual(cast.toRgbColorList('#000'), [0, 0, 0]); t.deepEqual(cast.toRgbColorList('#000000'), [0, 0, 0]); @@ -91,7 +91,7 @@ test('toRbgColorList', function (t) { t.end(); }); -test('toRbgColorObject', function (t) { +test('toRbgColorObject', t => { // Hex (minimal, see "color" util tests) t.deepEqual(cast.toRgbColorObject('#000'), {r: 0, g: 0, b: 0}); t.deepEqual(cast.toRgbColorObject('#000000'), {r: 0, g: 0, b: 0}); @@ -110,7 +110,7 @@ test('toRbgColorObject', function (t) { t.end(); }); -test('compare', function (t) { +test('compare', t => { // Numeric t.strictEqual(cast.compare(0, 0), 0); t.strictEqual(cast.compare(1, 0), 1); @@ -137,7 +137,7 @@ test('compare', function (t) { t.end(); }); -test('isInt', function (t) { +test('isInt', t => { // Numeric t.strictEqual(cast.isInt(0), true); t.strictEqual(cast.isInt(1), true); @@ -162,9 +162,9 @@ test('isInt', function (t) { t.end(); }); -test('toListIndex', function (t) { - var list = [0, 1, 2, 3, 4, 5]; - var empty = []; +test('toListIndex', t => { + const list = [0, 1, 2, 3, 4, 5]; + const empty = []; // Valid t.strictEqual(cast.toListIndex(1, list.length), 1); @@ -184,13 +184,13 @@ test('toListIndex', function (t) { t.strictEqual(cast.toListIndex('last', empty.length), cast.LIST_INVALID); // "random" - var random = cast.toListIndex('random', list.length); + const random = cast.toListIndex('random', list.length); t.ok(random <= list.length); t.ok(random > 0); t.strictEqual(cast.toListIndex('random', empty.length), cast.LIST_INVALID); // "any" (alias for "random") - var any = cast.toListIndex('any', list.length); + const any = cast.toListIndex('any', list.length); t.ok(any <= list.length); t.ok(any > 0); t.strictEqual(cast.toListIndex('any', empty.length), cast.LIST_INVALID); diff --git a/test/unit/util_color.js b/test/unit/util_color.js index ea68b786d..61fc04a61 100644 --- a/test/unit/util_color.js +++ b/test/unit/util_color.js @@ -1,5 +1,5 @@ -var test = require('tap').test; -var color = require('../../src/util/color'); +const test = require('tap').test; +const color = require('../../src/util/color'); /** * Assert that two HSV colors are similar to each other, within a tolerance. @@ -7,7 +7,7 @@ var color = require('../../src/util/color'); * @param {HSVObject} actual - the first HSV color to compare. * @param {HSVObject} expected - the other HSV color to compare. */ -var hsvSimilar = function (t, actual, expected) { +const hsvSimilar = function (t, actual, expected) { if ((Math.abs(actual.h - expected.h) >= 1) || (Math.abs(actual.s - expected.s) >= 0.01) || (Math.abs(actual.v - expected.v) >= 0.01) @@ -25,7 +25,7 @@ var hsvSimilar = function (t, actual, expected) { * @param {RGBObject} actual - the first RGB color to compare. * @param {RGBObject} expected - the other RGB color to compare. */ -var rgbSimilar = function (t, actual, expected) { +const rgbSimilar = function (t, actual, expected) { if ((Math.abs(actual.r - expected.r) >= 1) || (Math.abs(actual.g - expected.g) >= 1) || (Math.abs(actual.b - expected.b) >= 1) @@ -37,7 +37,7 @@ var rgbSimilar = function (t, actual, expected) { } }; -test('decimalToHex', function (t) { +test('decimalToHex', t => { t.strictEqual(color.decimalToHex(0), '#000000'); t.strictEqual(color.decimalToHex(1), '#000001'); t.strictEqual(color.decimalToHex(16777215), '#ffffff'); @@ -46,7 +46,7 @@ test('decimalToHex', function (t) { t.end(); }); -test('decimalToRgb', function (t) { +test('decimalToRgb', t => { t.deepEqual(color.decimalToRgb(0), {a: 255, r: 0, g: 0, b: 0}); t.deepEqual(color.decimalToRgb(1), {a: 255, r: 0, g: 0, b: 1}); t.deepEqual(color.decimalToRgb(16777215), {a: 255, r: 255, g: 255, b: 255}); @@ -55,7 +55,7 @@ test('decimalToRgb', function (t) { t.end(); }); -test('hexToRgb', function (t) { +test('hexToRgb', t => { t.deepEqual(color.hexToRgb('#000'), {r: 0, g: 0, b: 0}); t.deepEqual(color.hexToRgb('#000000'), {r: 0, g: 0, b: 0}); t.deepEqual(color.hexToRgb('#fff'), {r: 255, g: 255, b: 255}); @@ -73,21 +73,21 @@ test('hexToRgb', function (t) { t.end(); }); -test('rgbToHex', function (t) { +test('rgbToHex', t => { t.strictEqual(color.rgbToHex({r: 0, g: 0, b: 0}), '#000000'); t.strictEqual(color.rgbToHex({r: 255, g: 255, b: 255}), '#ffffff'); t.strictEqual(color.rgbToHex({r: 0, g: 255, b: 170}), '#00ffaa'); t.end(); }); -test('rgbToDecimal', function (t) { +test('rgbToDecimal', t => { t.strictEqual(color.rgbToDecimal({r: 0, g: 0, b: 0}), 0); t.strictEqual(color.rgbToDecimal({r: 255, g: 255, b: 255}), 16777215); t.strictEqual(color.rgbToDecimal({r: 0, g: 255, b: 170}), 65450); t.end(); }); -test('hexToDecimal', function (t) { +test('hexToDecimal', t => { t.strictEqual(color.hexToDecimal('#000'), 0); t.strictEqual(color.hexToDecimal('#000000'), 0); t.strictEqual(color.hexToDecimal('#fff'), 16777215); @@ -97,7 +97,7 @@ test('hexToDecimal', function (t) { t.end(); }); -test('hsvToRgb', function (t) { +test('hsvToRgb', t => { rgbSimilar(t, color.hsvToRgb({h: 0, s: 0, v: 0}), {r: 0, g: 0, b: 0}); rgbSimilar(t, color.hsvToRgb({h: 123, s: 0.1234, v: 0}), {r: 0, g: 0, b: 0}); rgbSimilar(t, color.hsvToRgb({h: 0, s: 0, v: 1}), {r: 255, g: 255, b: 255}); @@ -108,7 +108,7 @@ test('hsvToRgb', function (t) { t.end(); }); -test('rgbToHsv', function (t) { +test('rgbToHsv', t => { hsvSimilar(t, color.rgbToHsv({r: 0, g: 0, b: 0}), {h: 0, s: 0, v: 0}); hsvSimilar(t, color.rgbToHsv({r: 64, g: 64, b: 64}), {h: 0, s: 0, v: 0.25}); hsvSimilar(t, color.rgbToHsv({r: 128, g: 128, b: 128}), {h: 0, s: 0, v: 0.5}); @@ -120,7 +120,7 @@ test('rgbToHsv', function (t) { t.end(); }); -test('mixRgb', function (t) { +test('mixRgb', t => { rgbSimilar(t, color.mixRgb({r: 10, g: 20, b: 30}, {r: 30, g: 40, b: 50}, -1), {r: 10, g: 20, b: 30}); rgbSimilar(t, color.mixRgb({r: 10, g: 20, b: 30}, {r: 30, g: 40, b: 50}, 0), {r: 10, g: 20, b: 30}); rgbSimilar(t, color.mixRgb({r: 10, g: 20, b: 30}, {r: 30, g: 40, b: 50}, 0.25), {r: 15, g: 25, b: 35}); diff --git a/test/unit/util_math.js b/test/unit/util_math.js index 4c728dce1..d5a1c32fc 100644 --- a/test/unit/util_math.js +++ b/test/unit/util_math.js @@ -1,7 +1,7 @@ -var test = require('tap').test; -var math = require('../../src/util/math-util'); +const test = require('tap').test; +const math = require('../../src/util/math-util'); -test('degToRad', function (t) { +test('degToRad', t => { t.strictEqual(math.degToRad(0), 0); t.strictEqual(math.degToRad(1), 0.017453292519943295); t.strictEqual(math.degToRad(180), Math.PI); @@ -10,7 +10,7 @@ test('degToRad', function (t) { t.end(); }); -test('radToDeg', function (t) { +test('radToDeg', t => { t.strictEqual(math.radToDeg(0), 0); t.strictEqual(math.radToDeg(1), 57.29577951308232); t.strictEqual(math.radToDeg(180), 10313.240312354817); @@ -19,7 +19,7 @@ test('radToDeg', function (t) { t.end(); }); -test('clamp', function (t) { +test('clamp', t => { t.strictEqual(math.clamp(0, 0, 10), 0); t.strictEqual(math.clamp(1, 0, 10), 1); t.strictEqual(math.clamp(-10, 0, 10), 0); @@ -27,7 +27,7 @@ test('clamp', function (t) { t.end(); }); -test('wrapClamp', function (t) { +test('wrapClamp', t => { t.strictEqual(math.wrapClamp(0, 0, 10), 0); t.strictEqual(math.wrapClamp(1, 0, 10), 1); t.strictEqual(math.wrapClamp(-10, 0, 10), 1); @@ -35,7 +35,7 @@ test('wrapClamp', function (t) { t.end(); }); -test('tan', function (t) { +test('tan', t => { t.strictEqual(math.tan(90), Infinity); t.strictEqual(math.tan(180), 0); t.strictEqual(math.tan(-90), -Infinity); diff --git a/test/unit/util_string.js b/test/unit/util_string.js index fdcd439d3..741336258 100644 --- a/test/unit/util_string.js +++ b/test/unit/util_string.js @@ -1,7 +1,7 @@ -var test = require('tap').test; -var StringUtil = require('../../src/util/string-util'); +const test = require('tap').test; +const StringUtil = require('../../src/util/string-util'); -test('withoutTrailingDigits', function (t) { +test('withoutTrailingDigits', t => { t.strictEqual(StringUtil.withoutTrailingDigits('boeing747'), 'boeing'); t.strictEqual(StringUtil.withoutTrailingDigits('boeing747 '), 'boeing747 '); t.strictEqual(StringUtil.withoutTrailingDigits('boeing𝟨'), 'boeing𝟨'); @@ -10,7 +10,7 @@ test('withoutTrailingDigits', function (t) { t.end(); }); -test('unusedName', function (t) { +test('unusedName', t => { t.strictEqual( StringUtil.unusedName( 'name', diff --git a/test/unit/util_timer.js b/test/unit/util_timer.js index 4780ec44a..5c0f21790 100644 --- a/test/unit/util_timer.js +++ b/test/unit/util_timer.js @@ -1,8 +1,8 @@ -var test = require('tap').test; -var Timer = require('../../src/util/timer'); +const test = require('tap').test; +const Timer = require('../../src/util/timer'); -test('spec', function (t) { - var timer = new Timer(); +test('spec', t => { + const timer = new Timer(); t.type(Timer, 'function'); t.type(timer, 'object'); @@ -15,25 +15,25 @@ test('spec', function (t) { t.end(); }); -test('time', function (t) { - var timer = new Timer(); - var time = timer.time(); +test('time', t => { + const timer = new Timer(); + const time = timer.time(); t.ok(Date.now() >= time); t.end(); }); -test('start / timeElapsed', function (t) { - var timer = new Timer(); - var delay = 100; - var threshold = 1000 / 60; // 60 hz +test('start / timeElapsed', t => { + const timer = new Timer(); + const delay = 100; + const threshold = 1000 / 60; // 60 hz // Start timer timer.start(); // Wait and measure timer - setTimeout(function () { - var timeElapsed = timer.timeElapsed(); + setTimeout(() => { + const timeElapsed = timer.timeElapsed(); t.ok(timeElapsed >= 0); t.ok(timeElapsed >= (delay - threshold) && timeElapsed <= (delay + threshold)); diff --git a/test/unit/util_xml.js b/test/unit/util_xml.js index 1906a2ab6..d22f37b61 100644 --- a/test/unit/util_xml.js +++ b/test/unit/util_xml.js @@ -1,9 +1,9 @@ -var test = require('tap').test; -var xml = require('../../src/util/xml-escape'); +const test = require('tap').test; +const xml = require('../../src/util/xml-escape'); -test('escape', function (t) { - var input = ''; - var output = '<foo bar="he & llo '"></foo>'; +test('escape', t => { + const input = ''; + const output = '<foo bar="he & llo '"></foo>'; t.strictEqual(xml(input), output); t.end(); }); diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index eed537dd3..73cefb8a2 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -1,8 +1,8 @@ -var test = require('tap').test; -var VirtualMachine = require('../../src/virtual-machine.js'); +const test = require('tap').test; +const VirtualMachine = require('../../src/virtual-machine.js'); -test('renameSprite throws when there is no sprite with that id', function (t) { - var vm = new VirtualMachine(); +test('renameSprite throws when there is no sprite with that id', t => { + const vm = new VirtualMachine(); vm.runtime.getTargetById = () => null; t.throws( (() => vm.renameSprite('id', 'name')), @@ -11,9 +11,9 @@ test('renameSprite throws when there is no sprite with that id', function (t) { t.end(); }); -test('renameSprite throws when used on a non-sprite target', function (t) { - var vm = new VirtualMachine(); - var fakeTarget = { +test('renameSprite throws when used on a non-sprite target', t => { + const vm = new VirtualMachine(); + const fakeTarget = { isSprite: () => false }; vm.runtime.getTargetById = () => (fakeTarget); @@ -24,9 +24,9 @@ test('renameSprite throws when used on a non-sprite target', function (t) { t.end(); }); -test('renameSprite throws when there is no sprite for given target', function (t) { - var vm = new VirtualMachine(); - var fakeTarget = { +test('renameSprite throws when there is no sprite for given target', t => { + const vm = new VirtualMachine(); + const fakeTarget = { sprite: null, isSprite: () => true }; @@ -38,9 +38,9 @@ test('renameSprite throws when there is no sprite for given target', function (t t.end(); }); -test('renameSprite sets the sprite name', function (t) { - var vm = new VirtualMachine(); - var fakeTarget = { +test('renameSprite sets the sprite name', t => { + const vm = new VirtualMachine(); + const fakeTarget = { sprite: {name: 'original'}, isSprite: () => true }; @@ -50,9 +50,9 @@ test('renameSprite sets the sprite name', function (t) { t.end(); }); -test('renameSprite does not set sprite names to an empty string', function (t) { - var vm = new VirtualMachine(); - var fakeTarget = { +test('renameSprite does not set sprite names to an empty string', t => { + const vm = new VirtualMachine(); + const fakeTarget = { sprite: {name: 'original'}, isSprite: () => true }; @@ -62,9 +62,9 @@ test('renameSprite does not set sprite names to an empty string', function (t) { t.end(); }); -test('renameSprite does not set sprite names to reserved names', function (t) { - var vm = new VirtualMachine(); - var fakeTarget = { +test('renameSprite does not set sprite names to reserved names', t => { + const vm = new VirtualMachine(); + const fakeTarget = { sprite: {name: 'original'}, isSprite: () => true }; @@ -74,8 +74,8 @@ test('renameSprite does not set sprite names to reserved names', function (t) { t.end(); }); -test('renameSprite increments from existing sprite names', function (t) { - var vm = new VirtualMachine(); +test('renameSprite increments from existing sprite names', t => { + const vm = new VirtualMachine(); vm.emitTargetsUpdate = () => {}; vm.runtime.targets = [{ id: 'id1', diff --git a/webpack.config.js b/webpack.config.js index b014e88ce..571256800 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,9 +1,9 @@ -var CopyWebpackPlugin = require('copy-webpack-plugin'); -var defaultsDeep = require('lodash.defaultsdeep'); -var path = require('path'); -var webpack = require('webpack'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const defaultsDeep = require('lodash.defaultsdeep'); +const path = require('path'); +const webpack = require('webpack'); -var base = { +const base = { devServer: { contentBase: false, host: '0.0.0.0',