Merge pull request #539 from rschamp/root-es6

Use ES6 linting rules in the project root
This commit is contained in:
Ray Schamp 2017-04-26 10:08:06 -04:00 committed by GitHub
commit b5f5c3592a
36 changed files with 666 additions and 666 deletions

View file

@ -1,3 +1,3 @@
module.exports = { module.exports = {
extends: ['scratch', 'scratch/node'] extends: ['scratch', 'scratch/node', 'scratch/es6']
}; };

View file

@ -1,15 +1,15 @@
var ScratchStorage = require('scratch-storage'); const ScratchStorage = require('scratch-storage');
var ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/'; const ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/';
var PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/'; const PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/';
/** /**
* @param {Asset} asset - calculate a URL for this asset. * @param {Asset} asset - calculate a URL for this asset.
* @returns {string} a URL to download a project file. * @returns {string} a URL to download a project file.
*/ */
var getProjectUrl = function (asset) { const getProjectUrl = function (asset) {
var assetIdParts = asset.assetId.split('.'); const assetIdParts = asset.assetId.split('.');
var assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/']; const assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/'];
if (assetIdParts[1]) { if (assetIdParts[1]) {
assetUrlParts.push(assetIdParts[1]); assetUrlParts.push(assetIdParts[1]);
} }
@ -20,8 +20,8 @@ var getProjectUrl = function (asset) {
* @param {Asset} asset - calculate a URL for this asset. * @param {Asset} asset - calculate a URL for this asset.
* @returns {string} a URL to download a project asset (PNG, WAV, etc.) * @returns {string} a URL to download a project asset (PNG, WAV, etc.)
*/ */
var getAssetUrl = function (asset) { const getAssetUrl = function (asset) {
var assetUrlParts = [ const assetUrlParts = [
ASSET_SERVER, ASSET_SERVER,
'internalapi/asset/', 'internalapi/asset/',
asset.assetId, 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. * 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. * @param {VirtualMachine} vm - the VM which will own the new ScratchStorage instance.
*/ */
var attachTestStorage = function (vm) { const attachTestStorage = function (vm) {
var storage = new ScratchStorage(); const storage = new ScratchStorage();
var AssetType = storage.AssetType; const AssetType = storage.AssetType;
storage.addWebSource([AssetType.Project], getProjectUrl); storage.addWebSource([AssetType.Project], getProjectUrl);
storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl); storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl);
vm.attachStorage(storage); vm.attachStorage(storage);

View file

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

View file

@ -1,4 +1,4 @@
var FakeRenderer = function () { const FakeRenderer = function () {
this.unused = ''; this.unused = '';
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;

View file

@ -1,32 +1,32 @@
var fs = require('fs'); const fs = require('fs');
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var projectUri = path.resolve(__dirname, '../fixtures/complex.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
var project = extract(projectUri); const project = extract(projectUri);
var spriteUri = path.resolve(__dirname, '../fixtures/sprite.json'); const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
var sprite = fs.readFileSync(spriteUri, 'utf8'); const sprite = fs.readFileSync(spriteUri, 'utf8');
test('complex', function (t) { test('complex', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length === 0); t.ok(threads.length === 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Manipulate each target // Manipulate each target
vm.on('targetsUpdate', function (data) { vm.on('targetsUpdate', data => {
var targets = data.targetList; const targets = data.targetList;
for (var i in targets) { for (const i in targets) {
if (targets[i].isStage === true) continue; if (targets[i].isStage === true) continue;
if (targets[i].name.match(/test/)) continue; if (targets[i].name.match(/test/)) continue;
@ -55,12 +55,12 @@ test('complex', function (t) {
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// Post IO data // Post IO data
@ -89,7 +89,7 @@ test('complex', function (t) {
); );
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,37 +1,37 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/control.sb2'); const uri = path.resolve(__dirname, '../fixtures/control.sb2');
var project = extract(uri); const project = extract(uri);
test('control', function (t) { test('control', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length > 0); t.ok(threads.length > 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
}); });
}); });
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,34 +1,34 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/data.sb2'); const uri = path.resolve(__dirname, '../fixtures/data.sb2');
var project = extract(uri); const project = extract(uri);
test('data', function (t) { test('data', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function () { vm.on('playgroundData', () => {
// @todo Additional tests // @todo Additional tests
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/event.sb2'); const uri = path.resolve(__dirname, '../fixtures/event.sb2');
var project = extract(uri); const project = extract(uri);
test('event', function (t) { test('event', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length > 0); t.ok(threads.length > 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,22 +1,22 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2'); const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
var project = extract(projectUri); const project = extract(projectUri);
test('complex', function (t) { test('complex', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length === 0); 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.deepEqual(results, ['3', '2', '1', 'stage']);
t.end(); t.end();
@ -24,16 +24,16 @@ test('complex', function (t) {
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,26 +1,26 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var renderedTarget = require('../../src/sprites/rendered-target'); const renderedTarget = require('../../src/sprites/rendered-target');
var runtime = require('../../src/engine/runtime'); const runtime = require('../../src/engine/runtime');
var sb2 = require('../../src/import/sb2import'); const sb2 = require('../../src/import/sb2import');
test('spec', function (t) { test('spec', t => {
t.type(sb2, 'function'); t.type(sb2, 'function');
t.end(); t.end();
}); });
test('default', function (t) { test('default', t => {
// Get SB2 JSON (string) // Get SB2 JSON (string)
var uri = path.resolve(__dirname, '../fixtures/default.sb2'); const uri = path.resolve(__dirname, '../fixtures/default.sb2');
var file = extract(uri); const file = extract(uri);
// Create runtime instance & load SB2 into it // Create runtime instance & load SB2 into it
var rt = new runtime(); const rt = new runtime();
attachTestStorage(rt); attachTestStorage(rt);
sb2(file, rt).then(function (targets) { sb2(file, rt).then(targets => {
// Test // Test
t.type(file, 'string'); t.type(file, 'string');
t.type(rt, 'object'); t.type(rt, 'object');

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/looks.sb2'); const uri = path.resolve(__dirname, '../fixtures/looks.sb2');
var project = extract(uri); const project = extract(uri);
test('looks', function (t) { test('looks', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length === 0); t.ok(threads.length === 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/motion.sb2'); const uri = path.resolve(__dirname, '../fixtures/motion.sb2');
var project = extract(uri); const project = extract(uri);
test('motion', function (t) { test('motion', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length > 0); t.ok(threads.length > 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,34 +1,34 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/pen.sb2'); const uri = path.resolve(__dirname, '../fixtures/pen.sb2');
var project = extract(uri); const project = extract(uri);
test('pen', function (t) { test('pen', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function () { vm.on('playgroundData', () => {
// @todo Additional tests // @todo Additional tests
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/procedure.sb2'); const uri = path.resolve(__dirname, '../fixtures/procedure.sb2');
var project = extract(uri); const project = extract(uri);
test('procedure', function (t) { test('procedure', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length === 0); t.ok(threads.length === 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/sensing.sb2'); const uri = path.resolve(__dirname, '../fixtures/sensing.sb2');
var project = extract(uri); const project = extract(uri);
test('sensing', function (t) { test('sensing', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length > 0); t.ok(threads.length > 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,35 +1,35 @@
var path = require('path'); const path = require('path');
var test = require('tap').test; const test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage'); const attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract'); const extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/sound.sb2'); const uri = path.resolve(__dirname, '../fixtures/sound.sb2');
var project = extract(uri); const project = extract(uri);
test('sound', function (t) { test('sound', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
attachTestStorage(vm); attachTestStorage(vm);
// Evaluate playground data and exit // Evaluate playground data and exit
vm.on('playgroundData', function (e) { vm.on('playgroundData', e => {
var threads = JSON.parse(e.threads); const threads = JSON.parse(e.threads);
t.ok(threads.length > 0); t.ok(threads.length > 0);
t.end(); t.end();
process.nextTick(process.exit); process.nextTick(process.exit);
}); });
// Start VM, load project, and run // Start VM, load project, and run
t.doesNotThrow(function () { t.doesNotThrow(() => {
vm.start(); vm.start();
vm.clear(); vm.clear();
vm.setCompatibilityMode(false); vm.setCompatibilityMode(false);
vm.setTurboMode(false); vm.setTurboMode(false);
vm.loadProject(project).then(function () { vm.loadProject(project).then(() => {
vm.greenFlag(); vm.greenFlag();
// After two seconds, get playground data and stop // After two seconds, get playground data and stop
setTimeout(function () { setTimeout(() => {
vm.getPlaygroundData(); vm.getPlaygroundData();
vm.stopAll(); vm.stopAll();
}, 2000); }, 2000);

View file

@ -1,21 +1,21 @@
var test = require('tap').test; const test = require('tap').test;
var Control = require('../../src/blocks/scratch3_control'); const Control = require('../../src/blocks/scratch3_control');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
test('getPrimitives', function (t) { test('getPrimitives', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
t.type(c.getPrimitives(), 'object'); t.type(c.getPrimitives(), 'object');
t.end(); t.end();
}); });
test('repeat', function (t) { test('repeat', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
// Test harness (mocks `util`) // Test harness (mocks `util`)
var i = 0; let i = 0;
var repeat = 10; const repeat = 10;
var util = { var util = {
stackFrame: Object.create(null), stackFrame: Object.create(null),
startBranch: function () { startBranch: function () {
@ -31,13 +31,13 @@ test('repeat', function (t) {
t.end(); t.end();
}); });
test('repeatUntil', function (t) { test('repeatUntil', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
// Test harness (mocks `util`) // Test harness (mocks `util`)
var i = 0; let i = 0;
var repeat = 10; const repeat = 10;
var util = { var util = {
stackFrame: Object.create(null), stackFrame: Object.create(null),
startBranch: function () { startBranch: function () {
@ -52,13 +52,13 @@ test('repeatUntil', function (t) {
t.end(); t.end();
}); });
test('forever', function (t) { test('forever', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
// Test harness (mocks `util`) // Test harness (mocks `util`)
var i = 0; let i = 0;
var util = { const util = {
startBranch: function (branchNum, isLoop) { startBranch: function (branchNum, isLoop) {
i++; i++;
t.strictEqual(branchNum, 1); t.strictEqual(branchNum, 1);
@ -72,13 +72,13 @@ test('forever', function (t) {
t.end(); t.end();
}); });
test('if / ifElse', function (t) { test('if / ifElse', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
// Test harness (mocks `util`) // Test harness (mocks `util`)
var i = 0; let i = 0;
var util = { const util = {
startBranch: function (branchNum) { startBranch: function (branchNum) {
i += branchNum; i += branchNum;
} }
@ -96,17 +96,17 @@ test('if / ifElse', function (t) {
t.end(); t.end();
}); });
test('stop', function (t) { test('stop', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Control(rt); const c = new Control(rt);
// Test harness (mocks `util`) // Test harness (mocks `util`)
var state = { const state = {
stopAll: 0, stopAll: 0,
stopOtherTargetThreads: 0, stopOtherTargetThreads: 0,
stopThisScript: 0 stopThisScript: 0
}; };
var util = { const util = {
stopAll: function () { stopAll: function () {
state.stopAll++; state.stopAll++;
}, },

View file

@ -1,129 +1,129 @@
var test = require('tap').test; const test = require('tap').test;
var Operators = require('../../src/blocks/scratch3_operators'); 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.type(blocks.getPrimitives(), 'object');
t.end(); t.end();
}); });
test('add', function (t) { test('add', t => {
t.strictEqual(blocks.add({NUM1: '1', NUM2: '1'}), 2); t.strictEqual(blocks.add({NUM1: '1', NUM2: '1'}), 2);
t.strictEqual(blocks.add({NUM1: 'foo', NUM2: 'bar'}), 0); t.strictEqual(blocks.add({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end(); t.end();
}); });
test('subtract', function (t) { test('subtract', t => {
t.strictEqual(blocks.subtract({NUM1: '1', NUM2: '1'}), 0); t.strictEqual(blocks.subtract({NUM1: '1', NUM2: '1'}), 0);
t.strictEqual(blocks.subtract({NUM1: 'foo', NUM2: 'bar'}), 0); t.strictEqual(blocks.subtract({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end(); t.end();
}); });
test('multiply', function (t) { test('multiply', t => {
t.strictEqual(blocks.multiply({NUM1: '2', NUM2: '2'}), 4); t.strictEqual(blocks.multiply({NUM1: '2', NUM2: '2'}), 4);
t.strictEqual(blocks.multiply({NUM1: 'foo', NUM2: 'bar'}), 0); t.strictEqual(blocks.multiply({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end(); t.end();
}); });
test('divide', function (t) { test('divide', t => {
t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1); t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1);
t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo
t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo
t.end(); t.end();
}); });
test('lt', function (t) { test('lt', t => {
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true); t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true);
t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false); t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false);
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '1'}), false); t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '1'}), false);
t.end(); t.end();
}); });
test('equals', function (t) { test('equals', t => {
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '2'}), false); t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '2'}), false);
t.strictEqual(blocks.equals({OPERAND1: '2', OPERAND2: '1'}), false); t.strictEqual(blocks.equals({OPERAND1: '2', OPERAND2: '1'}), false);
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '1'}), true); t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '1'}), true);
t.end(); t.end();
}); });
test('gt', function (t) { test('gt', t => {
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '2'}), false); t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '2'}), false);
t.strictEqual(blocks.gt({OPERAND1: '2', OPERAND2: '1'}), true); t.strictEqual(blocks.gt({OPERAND1: '2', OPERAND2: '1'}), true);
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '1'}), false); t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '1'}), false);
t.end(); 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: true}), true);
t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: false}), false); t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: false}), false);
t.strictEqual(blocks.and({OPERAND1: false, OPERAND2: false}), false); t.strictEqual(blocks.and({OPERAND1: false, OPERAND2: false}), false);
t.end(); 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: true}), true);
t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: false}), true); t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: false}), true);
t.strictEqual(blocks.or({OPERAND1: false, OPERAND2: false}), false); t.strictEqual(blocks.or({OPERAND1: false, OPERAND2: false}), false);
t.end(); t.end();
}); });
test('not', function (t) { test('not', t => {
t.strictEqual(blocks.not({OPERAND: true}), false); t.strictEqual(blocks.not({OPERAND: true}), false);
t.strictEqual(blocks.not({OPERAND: false}), true); t.strictEqual(blocks.not({OPERAND: false}), true);
t.end(); t.end();
}); });
test('random', function (t) { test('random', t => {
var min = 0; const min = 0;
var max = 100; const max = 100;
var result = blocks.random({FROM: min, TO: max}); const result = blocks.random({FROM: min, TO: max});
t.ok(result >= min); t.ok(result >= min);
t.ok(result <= max); t.ok(result <= max);
t.end(); t.end();
}); });
test('random - equal', function (t) { test('random - equal', t => {
var min = 1; const min = 1;
var max = 1; const max = 1;
t.strictEqual(blocks.random({FROM: min, TO: max}), min); t.strictEqual(blocks.random({FROM: min, TO: max}), min);
t.end(); t.end();
}); });
test('random - decimal', function (t) { test('random - decimal', t => {
var min = 0.1; const min = 0.1;
var max = 10; const max = 10;
var result = blocks.random({FROM: min, TO: max}); const result = blocks.random({FROM: min, TO: max});
t.ok(result >= min); t.ok(result >= min);
t.ok(result <= max); t.ok(result <= max);
t.end(); t.end();
}); });
test('random - int', function (t) { test('random - int', t => {
var min = 0; const min = 0;
var max = 10; const max = 10;
var result = blocks.random({FROM: min, TO: max}); const result = blocks.random({FROM: min, TO: max});
t.ok(result >= min); t.ok(result >= min);
t.ok(result <= max); t.ok(result <= max);
t.end(); t.end();
}); });
test('random - reverse', function (t) { test('random - reverse', t => {
var min = 0; const min = 0;
var max = 10; const max = 10;
var result = blocks.random({FROM: max, TO: min}); const result = blocks.random({FROM: max, TO: min});
t.ok(result >= min); t.ok(result >= min);
t.ok(result <= max); t.ok(result <= max);
t.end(); t.end();
}); });
test('join', function (t) { test('join', t => {
t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar'); t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar');
t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12'); t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12');
t.end(); t.end();
}); });
test('letterOf', function (t) { test('letterOf', t => {
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 0}), ''); t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 0}), '');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 1}), 'f'); t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 1}), 'f');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 2}), 'o'); t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 2}), 'o');
@ -133,7 +133,7 @@ test('letterOf', function (t) {
t.end(); t.end();
}); });
test('length', function (t) { test('length', t => {
t.strictEqual(blocks.length({STRING: ''}), 0); t.strictEqual(blocks.length({STRING: ''}), 0);
t.strictEqual(blocks.length({STRING: 'foo'}), 3); t.strictEqual(blocks.length({STRING: 'foo'}), 3);
t.strictEqual(blocks.length({STRING: '1'}), 1); t.strictEqual(blocks.length({STRING: '1'}), 1);
@ -141,21 +141,21 @@ test('length', function (t) {
t.end(); t.end();
}); });
test('mod', function (t) { test('mod', t => {
t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0); 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.strictEqual(blocks.mod({NUM1: -3, NUM2: 6}), 3); t.strictEqual(blocks.mod({NUM1: -3, NUM2: 6}), 3);
t.end(); t.end();
}); });
test('round', function (t) { test('round', t => {
t.strictEqual(blocks.round({NUM: 1}), 1); t.strictEqual(blocks.round({NUM: 1}), 1);
t.strictEqual(blocks.round({NUM: 1.1}), 1); t.strictEqual(blocks.round({NUM: 1.1}), 1);
t.strictEqual(blocks.round({NUM: 1.5}), 2); t.strictEqual(blocks.round({NUM: 1.5}), 2);
t.end(); t.end();
}); });
test('mathop', function (t) { test('mathop', t => {
t.strictEqual(blocks.mathop({OPERATOR: 'abs', NUM: -1}), 1); t.strictEqual(blocks.mathop({OPERATOR: 'abs', NUM: -1}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'floor', NUM: 1.5}), 1); t.strictEqual(blocks.mathop({OPERATOR: 'floor', NUM: 1.5}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'ceiling', NUM: 0.1}), 1); t.strictEqual(blocks.mathop({OPERATOR: 'ceiling', NUM: 0.1}), 1);

View file

@ -1,22 +1,22 @@
var test = require('tap').test; const test = require('tap').test;
var adapter = require('../../src/engine/adapter'); const adapter = require('../../src/engine/adapter');
var events = require('../fixtures/events.json'); const events = require('../fixtures/events.json');
test('spec', function (t) { test('spec', t => {
t.type(adapter, 'function'); t.type(adapter, 'function');
t.end(); t.end();
}); });
test('invalid inputs', function (t) { test('invalid inputs', t => {
var nothing = adapter('not an object'); let nothing = adapter('not an object');
t.type(nothing, 'undefined'); t.type(nothing, 'undefined');
nothing = adapter({noxmlproperty: true}); nothing = adapter({noxmlproperty: true});
t.type(nothing, 'undefined'); t.type(nothing, 'undefined');
t.end(); t.end();
}); });
test('create event', function (t) { test('create event', t => {
var result = adapter(events.create); const result = adapter(events.create);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 2); t.equal(result.length, 2);
@ -43,8 +43,8 @@ test('create event', function (t) {
t.end(); t.end();
}); });
test('create with branch', function (t) { test('create with branch', t => {
var result = adapter(events.createbranch); const result = adapter(events.createbranch);
// Outer block // Outer block
t.type(result[0].id, 'string'); t.type(result[0].id, 'string');
t.type(result[0].opcode, 'string'); t.type(result[0].opcode, 'string');
@ -54,13 +54,13 @@ test('create with branch', function (t) {
t.type(result[0].topLevel, 'boolean'); t.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true); t.equal(result[0].topLevel, true);
// In branch // In branch
var branchBlockId = result[0].inputs.SUBSTACK.block; const branchBlockId = result[0].inputs.SUBSTACK.block;
var branchShadowId = result[0].inputs.SUBSTACK.shadow; const branchShadowId = result[0].inputs.SUBSTACK.shadow;
t.type(branchBlockId, 'string'); t.type(branchBlockId, 'string');
t.equal(branchShadowId, null); t.equal(branchShadowId, null);
// Find actual branch block // Find actual branch block
var branchBlock = null; let branchBlock = null;
for (var i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
if (result[i].id === branchBlockId) { if (result[i].id === branchBlockId) {
branchBlock = result[i]; branchBlock = result[i];
} }
@ -69,8 +69,8 @@ test('create with branch', function (t) {
t.end(); t.end();
}); });
test('create with two branches', function (t) { test('create with two branches', t => {
var result = adapter(events.createtwobranches); const result = adapter(events.createtwobranches);
// Outer block // Outer block
t.type(result[0].id, 'string'); t.type(result[0].id, 'string');
t.type(result[0].opcode, '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.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true); t.equal(result[0].topLevel, true);
// In branchs // In branchs
var firstBranchBlockId = result[0].inputs.SUBSTACK.block; const firstBranchBlockId = result[0].inputs.SUBSTACK.block;
var secondBranchBlockId = result[0].inputs.SUBSTACK2.block; const secondBranchBlockId = result[0].inputs.SUBSTACK2.block;
t.type(firstBranchBlockId, 'string'); t.type(firstBranchBlockId, 'string');
t.type(secondBranchBlockId, 'string'); t.type(secondBranchBlockId, 'string');
var firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow; const firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow;
var secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow; const secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow;
t.equal(firstBranchShadowBlockId, null); t.equal(firstBranchShadowBlockId, null);
t.equal(secondBranchShadowBlockId, null); t.equal(secondBranchShadowBlockId, null);
// Find actual branch blocks // Find actual branch blocks
var firstBranchBlock = null; let firstBranchBlock = null;
var secondBranchBlock = null; let secondBranchBlock = null;
for (var i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
if (result[i].id === firstBranchBlockId) { if (result[i].id === firstBranchBlockId) {
firstBranchBlock = result[i]; firstBranchBlock = result[i];
} }
@ -105,8 +105,8 @@ test('create with two branches', function (t) {
t.end(); t.end();
}); });
test('create with top-level shadow', function (t) { test('create with top-level shadow', t => {
var result = adapter(events.createtoplevelshadow); const result = adapter(events.createtoplevelshadow);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 1); t.equal(result.length, 1);
@ -120,8 +120,8 @@ test('create with top-level shadow', function (t) {
t.end(); t.end();
}); });
test('create with next connection', function (t) { test('create with next connection', t => {
var result = adapter(events.createwithnext); const result = adapter(events.createwithnext);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 2); t.equal(result.length, 2);
@ -148,21 +148,21 @@ test('create with next connection', function (t) {
t.end(); t.end();
}); });
test('create with obscured shadow', function (t) { test('create with obscured shadow', t => {
var result = adapter(events.createobscuredshadow); const result = adapter(events.createobscuredshadow);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 4); t.equal(result.length, 4);
t.end(); t.end();
}); });
test('create with invalid block xml', function (t) { test('create with invalid block xml', t => {
// Entirely invalid block XML // Entirely invalid block XML
var result = adapter(events.createinvalid); const result = adapter(events.createinvalid);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 0); t.equal(result.length, 0);
// Invalid grandchild tag // Invalid grandchild tag
var result2 = adapter(events.createinvalidgrandchild); const result2 = adapter(events.createinvalidgrandchild);
t.ok(Array.isArray(result2)); t.ok(Array.isArray(result2));
t.equal(result2.length, 1); t.equal(result2.length, 1);
t.type(result2[0].id, 'string'); t.type(result2[0].id, 'string');
@ -172,15 +172,15 @@ test('create with invalid block xml', function (t) {
t.end(); t.end();
}); });
test('create with invalid xml', function (t) { test('create with invalid xml', t => {
var result = adapter(events.createbadxml); const result = adapter(events.createbadxml);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 0); t.equal(result.length, 0);
t.end(); t.end();
}); });
test('create with empty field', function (t) { test('create with empty field', t => {
var result = adapter(events.createemptyfield); const result = adapter(events.createemptyfield);
t.ok(Array.isArray(result)); t.ok(Array.isArray(result));
t.equal(result.length, 3); t.equal(result.length, 3);
t.end(); t.end();

View file

@ -1,8 +1,8 @@
var test = require('tap').test; const test = require('tap').test;
var Blocks = require('../../src/engine/blocks'); const Blocks = require('../../src/engine/blocks');
test('spec', function (t) { test('spec', t => {
var b = new Blocks(); const b = new Blocks();
t.type(Blocks, 'function'); t.type(Blocks, 'function');
t.type(b, 'object'); t.type(b, 'object');
@ -27,8 +27,8 @@ test('spec', function (t) {
}); });
// Getter tests // Getter tests
test('getBlock', function (t) { test('getBlock', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -37,16 +37,16 @@ test('getBlock', function (t) {
inputs: {}, inputs: {},
topLevel: true topLevel: true
}); });
var block = b.getBlock('foo'); const block = b.getBlock('foo');
t.type(block, 'object'); t.type(block, 'object');
var notBlock = b.getBlock('?'); const notBlock = b.getBlock('?');
t.type(notBlock, 'undefined'); t.type(notBlock, 'undefined');
t.end(); t.end();
}); });
test('getScripts', function (t) { test('getScripts', t => {
var b = new Blocks(); const b = new Blocks();
var scripts = b.getScripts(); let scripts = b.getScripts();
t.type(scripts, 'object'); t.type(scripts, 'object');
t.equals(scripts.length, 0); t.equals(scripts.length, 0);
// Create two top-level blocks and one not. // Create two top-level blocks and one not.
@ -85,8 +85,8 @@ test('getScripts', function (t) {
}); });
test('getNextBlock', function (t) { test('getNextBlock', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -96,7 +96,7 @@ test('getNextBlock', function (t) {
topLevel: true topLevel: true
}); });
var next = b.getNextBlock('foo'); let next = b.getNextBlock('foo');
t.equals(next, null); t.equals(next, null);
// Add a block with "foo" as its next. // Add a block with "foo" as its next.
@ -113,14 +113,14 @@ test('getNextBlock', function (t) {
t.equals(next, 'foo'); t.equals(next, 'foo');
// Block that doesn't exist. // Block that doesn't exist.
var noBlock = b.getNextBlock('?'); const noBlock = b.getNextBlock('?');
t.equals(noBlock, null); t.equals(noBlock, null);
t.end(); t.end();
}); });
test('getBranch', function (t) { test('getBranch', t => {
var b = new Blocks(); const b = new Blocks();
// Single branch // Single branch
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
@ -145,17 +145,17 @@ test('getBranch', function (t) {
topLevel: false topLevel: false
}); });
var branch = b.getBranch('foo'); const branch = b.getBranch('foo');
t.equals(branch, 'foo2'); t.equals(branch, 'foo2');
var notBranch = b.getBranch('?'); const notBranch = b.getBranch('?');
t.equals(notBranch, null); t.equals(notBranch, null);
t.end(); t.end();
}); });
test('getBranch2', function (t) { test('getBranch2', t => {
var b = new Blocks(); const b = new Blocks();
// Second branch // Second branch
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
@ -193,16 +193,16 @@ test('getBranch2', function (t) {
topLevel: false topLevel: false
}); });
var branch1 = b.getBranch('foo', 1); const branch1 = b.getBranch('foo', 1);
var branch2 = b.getBranch('foo', 2); const branch2 = b.getBranch('foo', 2);
t.equals(branch1, 'foo2'); t.equals(branch1, 'foo2');
t.equals(branch2, 'foo3'); t.equals(branch2, 'foo3');
t.end(); t.end();
}); });
test('getBranch with none', function (t) { test('getBranch with none', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -211,14 +211,14 @@ test('getBranch with none', function (t) {
inputs: {}, inputs: {},
topLevel: true topLevel: true
}); });
var noBranch = b.getBranch('foo'); const noBranch = b.getBranch('foo');
t.equals(noBranch, null); t.equals(noBranch, null);
t.end(); t.end();
}); });
test('getOpcode', function (t) { test('getOpcode', t => {
var b = new Blocks(); const b = new Blocks();
var block = { const block = {
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
next: null, next: null,
@ -227,17 +227,17 @@ test('getOpcode', function (t) {
topLevel: true topLevel: true
}; };
b.createBlock(block); b.createBlock(block);
var opcode = b.getOpcode(block); const opcode = b.getOpcode(block);
t.equals(opcode, 'TEST_BLOCK'); t.equals(opcode, 'TEST_BLOCK');
var undefinedBlock = b.getBlock('?'); const undefinedBlock = b.getBlock('?');
var undefinedOpcode = b.getOpcode(undefinedBlock); const undefinedOpcode = b.getOpcode(undefinedBlock);
t.equals(undefinedOpcode, null); t.equals(undefinedOpcode, null);
t.end(); t.end();
}); });
// Block events tests // Block events tests
test('create', function (t) { test('create', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -253,8 +253,8 @@ test('create', function (t) {
t.end(); t.end();
}); });
test('move', function (t) { test('move', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -293,8 +293,8 @@ test('move', function (t) {
t.end(); t.end();
}); });
test('move into empty', function (t) { test('move into empty', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -320,8 +320,8 @@ test('move into empty', function (t) {
t.end(); t.end();
}); });
test('move no obscure shadow', function (t) { test('move no obscure shadow', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -354,8 +354,8 @@ test('move no obscure shadow', function (t) {
t.end(); t.end();
}); });
test('change', function (t) { test('change', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -411,8 +411,8 @@ test('change', function (t) {
t.end(); t.end();
}); });
test('delete', function (t) { test('delete', t => {
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -430,10 +430,10 @@ test('delete', function (t) {
t.end(); t.end();
}); });
test('delete chain', function (t) { test('delete chain', t => {
// Create a chain of connected blocks and delete the top one. // Create a chain of connected blocks and delete the top one.
// All of them should be deleted. // All of them should be deleted.
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',
@ -470,10 +470,10 @@ test('delete chain', function (t) {
t.end(); t.end();
}); });
test('delete inputs', function (t) { test('delete inputs', t => {
// Create a block with two inputs, one of which has its own input. // Create a block with two inputs, one of which has its own input.
// Delete the block - all of them should be deleted. // Delete the block - all of them should be deleted.
var b = new Blocks(); const b = new Blocks();
b.createBlock({ b.createBlock({
id: 'foo', id: 'foo',
opcode: 'TEST_BLOCK', opcode: 'TEST_BLOCK',

View file

@ -1,8 +1,8 @@
var test = require('tap').test; const test = require('tap').test;
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
test('spec', function (t) { test('spec', t => {
var r = new Runtime(); const r = new Runtime();
t.type(Runtime, 'function'); t.type(Runtime, 'function');
t.type(r, 'object'); t.type(r, 'object');

View file

@ -1,15 +1,15 @@
var test = require('tap').test; const test = require('tap').test;
var Sequencer = require('../../src/engine/sequencer'); const Sequencer = require('../../src/engine/sequencer');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
var Thread = require('../../src/engine/thread'); const Thread = require('../../src/engine/thread');
var RenderedTarget = require('../../src/sprites/rendered-target'); const RenderedTarget = require('../../src/sprites/rendered-target');
var Sprite = require('../../src/sprites/sprite'); const Sprite = require('../../src/sprites/sprite');
test('spec', function (t) { test('spec', t => {
t.type(Sequencer, 'function'); t.type(Sequencer, 'function');
var r = new Runtime(); const r = new Runtime();
var s = new Sequencer(r); const s = new Sequencer(r);
t.type(s, 'object'); t.type(s, 'object');
t.ok(s instanceof Sequencer); t.ok(s instanceof Sequencer);
@ -23,13 +23,13 @@ test('spec', function (t) {
t.end(); t.end();
}); });
var randomString = function () { const randomString = function () {
var top = Math.random().toString(36); const top = Math.random().toString(36);
return top.substring(7); return top.substring(7);
}; };
var generateBlock = function (id) { const generateBlock = function (id) {
var block = {fields: Object, const block = {fields: Object,
id: id, id: id,
inputs: {}, inputs: {},
STEPS: Object, STEPS: Object,
@ -47,8 +47,8 @@ var generateBlock = function (id) {
return block; return block;
}; };
var generateBlockInput = function (id, next, inp) { const generateBlockInput = function (id, next, inp) {
var block = {fields: Object, const block = {fields: Object,
id: id, id: id,
inputs: {SUBSTACK: {block: inp, name: 'SUBSTACK'}}, inputs: {SUBSTACK: {block: inp, name: 'SUBSTACK'}},
STEPS: Object, STEPS: Object,
@ -66,20 +66,20 @@ var generateBlockInput = function (id, next, inp) {
return block; return block;
}; };
var generateThread = function (runtime) { const generateThread = function (runtime) {
var s = new Sprite(); const s = new Sprite();
var rt = new RenderedTarget(s, runtime); const rt = new RenderedTarget(s, runtime);
var th = new Thread(randomString()); const th = new Thread(randomString());
var next = randomString(); let next = randomString();
var inp = randomString(); let inp = randomString();
var name = th.topBlock; let name = th.topBlock;
rt.blocks.createBlock(generateBlockInput(name, next, inp)); rt.blocks.createBlock(generateBlockInput(name, next, inp));
th.pushStack(name); th.pushStack(name);
rt.blocks.createBlock(generateBlock(inp)); rt.blocks.createBlock(generateBlock(inp));
for (var i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
name = next; name = next;
next = randomString(); next = randomString();
inp = randomString(); inp = randomString();
@ -97,10 +97,10 @@ var generateThread = function (runtime) {
return th; return th;
}; };
test('stepThread', function (t) { test('stepThread', t => {
var r = new Runtime(); const r = new Runtime();
var s = new Sequencer(r); const s = new Sequencer(r);
var th = generateThread(r); let th = generateThread(r);
t.notEquals(th.status, Thread.STATUS_DONE); t.notEquals(th.status, Thread.STATUS_DONE);
s.stepThread(th); s.stepThread(th);
t.strictEquals(th.status, Thread.STATUS_DONE); t.strictEquals(th.status, Thread.STATUS_DONE);
@ -115,10 +115,10 @@ test('stepThread', function (t) {
t.end(); t.end();
}); });
test('stepToBranch', function (t) { test('stepToBranch', t => {
var r = new Runtime(); const r = new Runtime();
var s = new Sequencer(r); const s = new Sequencer(r);
var th = generateThread(r); const th = generateThread(r);
s.stepToBranch(th, 2, false); s.stepToBranch(th, 2, false);
t.strictEquals(th.peekStack(), null); t.strictEquals(th.peekStack(), null);
th.popStack(); th.popStack();
@ -132,10 +132,10 @@ test('stepToBranch', function (t) {
t.end(); t.end();
}); });
test('retireThread', function (t) { test('retireThread', t => {
var r = new Runtime(); const r = new Runtime();
var s = new Sequencer(r); const s = new Sequencer(r);
var th = generateThread(r); const th = generateThread(r);
t.strictEquals(th.stack.length, 12); t.strictEquals(th.stack.length, 12);
s.retireThread(th); s.retireThread(th);
t.strictEquals(th.stack.length, 0); t.strictEquals(th.stack.length, 0);
@ -144,11 +144,11 @@ test('retireThread', function (t) {
t.end(); t.end();
}); });
test('stepToProcedure', function (t) { test('stepToProcedure', t => {
var r = new Runtime(); const r = new Runtime();
var s = new Sequencer(r); const s = new Sequencer(r);
var th = generateThread(r); const th = generateThread(r);
var expectedBlock = th.peekStack(); let expectedBlock = th.peekStack();
s.stepToProcedure(th, ''); s.stepToProcedure(th, '');
t.strictEquals(th.peekStack(), expectedBlock); t.strictEquals(th.peekStack(), expectedBlock);
s.stepToProcedure(th, 'faceCode'); s.stepToProcedure(th, 'faceCode');
@ -163,10 +163,10 @@ test('stepToProcedure', function (t) {
t.end(); t.end();
}); });
test('stepThreads', function (t) { test('stepThreads', t => {
var r = new Runtime(); const r = new Runtime();
r.currentStepTime = Infinity; r.currentStepTime = Infinity;
var s = new Sequencer(r); const s = new Sequencer(r);
t.strictEquals(s.stepThreads().length, 0); t.strictEquals(s.stepThreads().length, 0);
generateThread(r); generateThread(r);
t.strictEquals(r.threads.length, 1); t.strictEquals(r.threads.length, 1);

View file

@ -1,12 +1,12 @@
var test = require('tap').test; const test = require('tap').test;
var Thread = require('../../src/engine/thread'); const Thread = require('../../src/engine/thread');
var RenderedTarget = require('../../src/sprites/rendered-target'); const RenderedTarget = require('../../src/sprites/rendered-target');
var Sprite = require('../../src/sprites/sprite'); const Sprite = require('../../src/sprites/sprite');
test('spec', function (t) { test('spec', t => {
t.type(Thread, 'function'); t.type(Thread, 'function');
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
t.type(th, 'object'); t.type(th, 'object');
t.ok(th instanceof Thread); t.ok(th instanceof Thread);
t.type(th.pushStack, 'function'); t.type(th.pushStack, 'function');
@ -27,15 +27,15 @@ test('spec', function (t) {
t.end(); t.end();
}); });
test('pushStack', function (t) { test('pushStack', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
t.end(); t.end();
}); });
test('popStack', function (t) { test('popStack', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
t.strictEquals(th.popStack(), 'arbitraryString'); t.strictEquals(th.popStack(), 'arbitraryString');
t.strictEquals(th.popStack(), undefined); t.strictEquals(th.popStack(), undefined);
@ -43,8 +43,8 @@ test('popStack', function (t) {
t.end(); t.end();
}); });
test('atStackTop', function (t) { test('atStackTop', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
th.pushStack('secondString'); th.pushStack('secondString');
t.strictEquals(th.atStackTop(), false); t.strictEquals(th.atStackTop(), false);
@ -54,8 +54,8 @@ test('atStackTop', function (t) {
t.end(); t.end();
}); });
test('reuseStackForNextBlock', function (t) { test('reuseStackForNextBlock', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
th.reuseStackForNextBlock('secondString'); th.reuseStackForNextBlock('secondString');
t.strictEquals(th.popStack(), 'secondString'); t.strictEquals(th.popStack(), 'secondString');
@ -63,8 +63,8 @@ test('reuseStackForNextBlock', function (t) {
t.end(); t.end();
}); });
test('peekStackFrame', function (t) { test('peekStackFrame', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
t.strictEquals(th.peekStackFrame().warpMode, false); t.strictEquals(th.peekStackFrame().warpMode, false);
th.popStack(); th.popStack();
@ -73,8 +73,8 @@ test('peekStackFrame', function (t) {
t.end(); t.end();
}); });
test('peekParentStackFrame', function (t) { test('peekParentStackFrame', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
th.peekStackFrame().warpMode = true; th.peekStackFrame().warpMode = true;
t.strictEquals(th.peekParentStackFrame(), null); t.strictEquals(th.peekParentStackFrame(), null);
@ -84,8 +84,8 @@ test('peekParentStackFrame', function (t) {
t.end(); t.end();
}); });
test('pushReportedValue', function (t) { test('pushReportedValue', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
th.pushStack('secondString'); th.pushStack('secondString');
th.pushReportedValue('value'); th.pushReportedValue('value');
@ -94,8 +94,8 @@ test('pushReportedValue', function (t) {
t.end(); t.end();
}); });
test('peekStack', function (t) { test('peekStack', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
t.strictEquals(th.peekStack(), 'arbitraryString'); t.strictEquals(th.peekStack(), 'arbitraryString');
th.popStack(); th.popStack();
@ -104,8 +104,8 @@ test('peekStack', function (t) {
t.end(); t.end();
}); });
test('PushGetParam', function (t) { test('PushGetParam', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
th.pushStack('arbitraryString'); th.pushStack('arbitraryString');
th.pushParam('testParam', 'testValue'); th.pushParam('testParam', 'testValue');
t.strictEquals(th.peekStackFrame().params.testParam, 'testValue'); t.strictEquals(th.peekStackFrame().params.testParam, 'testValue');
@ -114,11 +114,11 @@ test('PushGetParam', function (t) {
t.end(); t.end();
}); });
test('goToNextBlock', function (t) { test('goToNextBlock', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
var s = new Sprite(); const s = new Sprite();
var rt = new RenderedTarget(s, null); const rt = new RenderedTarget(s, null);
var block1 = {fields: Object, const block1 = {fields: Object,
id: 'arbitraryString', id: 'arbitraryString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,
@ -132,7 +132,7 @@ test('goToNextBlock', function (t) {
x: 0, x: 0,
y: 0 y: 0
}; };
var block2 = {fields: Object, const block2 = {fields: Object,
id: 'secondString', id: 'secondString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,
@ -169,11 +169,11 @@ test('goToNextBlock', function (t) {
t.end(); t.end();
}); });
test('stopThisScript', function (t) { test('stopThisScript', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
var s = new Sprite(); const s = new Sprite();
var rt = new RenderedTarget(s, null); const rt = new RenderedTarget(s, null);
var block1 = {fields: Object, const block1 = {fields: Object,
id: 'arbitraryString', id: 'arbitraryString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,
@ -187,7 +187,7 @@ test('stopThisScript', function (t) {
x: 0, x: 0,
y: 0 y: 0
}; };
var block2 = {fields: Object, const block2 = {fields: Object,
id: 'secondString', id: 'secondString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,
@ -221,11 +221,11 @@ test('stopThisScript', function (t) {
t.end(); t.end();
}); });
test('isRecursiveCall', function (t) { test('isRecursiveCall', t => {
var th = new Thread('arbitraryString'); const th = new Thread('arbitraryString');
var s = new Sprite(); const s = new Sprite();
var rt = new RenderedTarget(s, null); const rt = new RenderedTarget(s, null);
var block1 = {fields: Object, const block1 = {fields: Object,
id: 'arbitraryString', id: 'arbitraryString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,
@ -239,7 +239,7 @@ test('isRecursiveCall', function (t) {
x: 0, x: 0,
y: 0 y: 0
}; };
var block2 = {fields: Object, const block2 = {fields: Object,
id: 'secondString', id: 'secondString',
inputs: Object, inputs: Object,
STEPS: Object, STEPS: Object,

View file

@ -1,10 +1,10 @@
var test = require('tap').test; const test = require('tap').test;
var Clock = require('../../src/io/clock'); const Clock = require('../../src/io/clock');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
test('spec', function (t) { test('spec', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Clock(rt); const c = new Clock(rt);
t.type(Clock, 'function'); t.type(Clock, 'function');
t.type(c, 'object'); t.type(c, 'object');
@ -15,14 +15,14 @@ test('spec', function (t) {
t.end(); t.end();
}); });
test('cycle', function (t) { test('cycle', t => {
var rt = new Runtime(); const rt = new Runtime();
var c = new Clock(rt); const c = new Clock(rt);
t.ok(c.projectTimer() <= 0.1); t.ok(c.projectTimer() <= 0.1);
setTimeout(function () { setTimeout(() => {
c.resetProjectTimer(); c.resetProjectTimer();
setTimeout(function () { setTimeout(() => {
t.ok(c.projectTimer() > 0); t.ok(c.projectTimer() > 0);
c.pause(); c.pause();
t.ok(c.projectTimer() > 0); t.ok(c.projectTimer() > 0);

View file

@ -1,10 +1,10 @@
var test = require('tap').test; const test = require('tap').test;
var Keyboard = require('../../src/io/keyboard'); const Keyboard = require('../../src/io/keyboard');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
test('spec', function (t) { test('spec', t => {
var rt = new Runtime(); const rt = new Runtime();
var k = new Keyboard(rt); const k = new Keyboard(rt);
t.type(k, 'object'); t.type(k, 'object');
t.type(k.postData, 'function'); t.type(k.postData, 'function');
@ -12,9 +12,9 @@ test('spec', function (t) {
t.end(); t.end();
}); });
test('space', function (t) { test('space', t => {
var rt = new Runtime(); const rt = new Runtime();
var k = new Keyboard(rt); const k = new Keyboard(rt);
k.postData({ k.postData({
keyCode: 32, keyCode: 32,
@ -26,9 +26,9 @@ test('space', function (t) {
t.end(); t.end();
}); });
test('letter', function (t) { test('letter', t => {
var rt = new Runtime(); const rt = new Runtime();
var k = new Keyboard(rt); const k = new Keyboard(rt);
k.postData({ k.postData({
keyCode: 65, keyCode: 65,
@ -40,9 +40,9 @@ test('letter', function (t) {
t.end(); t.end();
}); });
test('number', function (t) { test('number', t => {
var rt = new Runtime(); const rt = new Runtime();
var k = new Keyboard(rt); const k = new Keyboard(rt);
k.postData({ k.postData({
keyCode: 49, keyCode: 49,
@ -54,9 +54,9 @@ test('number', function (t) {
t.end(); t.end();
}); });
test('keyup', function (t) { test('keyup', t => {
var rt = new Runtime(); const rt = new Runtime();
var k = new Keyboard(rt); const k = new Keyboard(rt);
k.postData({ k.postData({
keyCode: 37, keyCode: 37,

View file

@ -1,10 +1,10 @@
var test = require('tap').test; const test = require('tap').test;
var Mouse = require('../../src/io/mouse'); const Mouse = require('../../src/io/mouse');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
test('spec', function (t) { test('spec', t => {
var rt = new Runtime(); const rt = new Runtime();
var m = new Mouse(rt); const m = new Mouse(rt);
t.type(m, 'object'); t.type(m, 'object');
t.type(m.postData, 'function'); t.type(m.postData, 'function');
@ -14,9 +14,9 @@ test('spec', function (t) {
t.end(); t.end();
}); });
test('mouseUp', function (t) { test('mouseUp', t => {
var rt = new Runtime(); const rt = new Runtime();
var m = new Mouse(rt); const m = new Mouse(rt);
m.postData({ m.postData({
x: 1, x: 1,
@ -31,9 +31,9 @@ test('mouseUp', function (t) {
t.end(); t.end();
}); });
test('mouseDown', function (t) { test('mouseDown', t => {
var rt = new Runtime(); const rt = new Runtime();
var m = new Mouse(rt); const m = new Mouse(rt);
m.postData({ m.postData({
x: 10, x: 10,

View file

@ -1,8 +1,8 @@
var test = require('tap').test; const test = require('tap').test;
var VirtualMachine = require('../../src/index'); const VirtualMachine = require('../../src/index');
test('interface', function (t) { test('interface', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
t.type(vm, 'object'); t.type(vm, 'object');
t.type(vm.start, 'function'); t.type(vm.start, 'function');
t.type(vm.greenFlag, 'function'); t.type(vm.greenFlag, 'function');

View file

@ -1,24 +1,24 @@
var test = require('tap').test; const test = require('tap').test;
var RenderedTarget = require('../../src/sprites/rendered-target'); const RenderedTarget = require('../../src/sprites/rendered-target');
var Sprite = require('../../src/sprites/sprite'); const Sprite = require('../../src/sprites/sprite');
var Runtime = require('../../src/engine/runtime'); const Runtime = require('../../src/engine/runtime');
var FakeRenderer = require('../fixtures/fake-renderer'); 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. // Create two clones and ensure they have different graphic effect objects.
// Regression test for Github issue #224 // Regression test for Github issue #224
var spr = new Sprite(); const spr = new Sprite();
var a = new RenderedTarget(spr, null); const a = new RenderedTarget(spr, null);
var b = new RenderedTarget(spr, null); const b = new RenderedTarget(spr, null);
t.ok(a.effects !== b.effects); t.ok(a.effects !== b.effects);
t.end(); t.end();
}); });
test('setxy', function (t) { test('setxy', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setXY(123, 321, true); a.setXY(123, 321, true);
t.equals(a.x, 123); t.equals(a.x, 123);
@ -26,54 +26,54 @@ test('setxy', function (t) {
t.end(); t.end();
}); });
test('direction', function (t) { test('direction', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setDirection(123); a.setDirection(123);
t.equals(a._getRenderedDirectionAndScale().direction, 123); t.equals(a._getRenderedDirectionAndScale().direction, 123);
t.end(); t.end();
}); });
test('setSay', function (t) { test('setSay', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setSay(); a.setSay();
a.setSay('types not specified', 'message'); a.setSay('types not specified', 'message');
t.end(); t.end();
}); });
test('setVisible', function (t) { test('setVisible', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setVisible(true); a.setVisible(true);
t.end(); t.end();
}); });
test('setSize', function (t) { test('setSize', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setSize(123); a.setSize(123);
t.equals(a._getRenderedDirectionAndScale().scale[0], 123); t.equals(a._getRenderedDirectionAndScale().scale[0], 123);
t.end(); t.end();
}); });
test('set and clear effects', function (t) { test('set and clear effects', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
for (var effect in a.effects) { for (var effect in a.effects) {
a.setEffect(effect, 1); a.setEffect(effect, 1);
@ -86,34 +86,34 @@ test('set and clear effects', function (t) {
t.end(); t.end();
}); });
test('setCostume', function (t) { test('setCostume', t => {
var o = new Object(); const o = new Object();
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
s.costumes = [o]; s.costumes = [o];
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setCostume(0); a.setCostume(0);
t.end(); t.end();
}); });
test('setRotationStyle', function (t) { test('setRotationStyle', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
a.renderer = renderer; a.renderer = renderer;
a.setRotationStyle(RenderedTarget.ROTATION_STYLE_NONE); a.setRotationStyle(RenderedTarget.ROTATION_STYLE_NONE);
t.end(); t.end();
}); });
test('getBounds', function (t) { test('getBounds', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.getBounds().top, 0); t.equals(a.getBounds().top, 0);
a.setXY(241, 241); a.setXY(241, 241);
@ -121,23 +121,23 @@ test('getBounds', function (t) {
t.end(); t.end();
}); });
test('isTouchingPoint', function (t) { test('isTouchingPoint', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.isTouchingPoint(), true); t.equals(a.isTouchingPoint(), true);
t.end(); t.end();
}); });
test('isTouchingEdge', function (t) { test('isTouchingEdge', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.isTouchingEdge(), false); t.equals(a.isTouchingEdge(), false);
a.setXY(1000, 1000); a.setXY(1000, 1000);
@ -145,46 +145,46 @@ test('isTouchingEdge', function (t) {
t.end(); t.end();
}); });
test('isTouchingSprite', function (t) { test('isTouchingSprite', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.isTouchingSprite('fake'), false); t.equals(a.isTouchingSprite('fake'), false);
t.end(); t.end();
}); });
test('isTouchingColor', function (t) { test('isTouchingColor', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.isTouchingColor(), false); t.equals(a.isTouchingColor(), false);
t.end(); t.end();
}); });
test('colorIsTouchingColor', function (t) { test('colorIsTouchingColor', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.colorIsTouchingColor(), false); t.equals(a.colorIsTouchingColor(), false);
t.end(); t.end();
}); });
test('layers', function (t) { test('layers', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
var o = new Object(); const o = new Object();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
a.goToFront(); a.goToFront();
t.equals(a.renderer.order, 5); t.equals(a.renderer.order, 5);
@ -196,12 +196,12 @@ test('layers', function (t) {
t.end(); t.end();
}); });
test('keepInFence', function (t) { test('keepInFence', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var renderer = new FakeRenderer(); const renderer = new FakeRenderer();
r.attachRenderer(renderer); r.attachRenderer(renderer);
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
a.renderer = renderer; a.renderer = renderer;
t.equals(a.keepInFence(1000, 1000)[0], 240); t.equals(a.keepInFence(1000, 1000)[0], 240);
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(); t.end();
}); });
test('#stopAll clears graphics effects', function (t) { test('#stopAll clears graphics effects', t => {
var s = new Sprite(); const s = new Sprite();
var r = new Runtime(); const r = new Runtime();
var a = new RenderedTarget(s, r); const a = new RenderedTarget(s, r);
var effectName = 'brightness'; const effectName = 'brightness';
a.setEffect(effectName, 100); a.setEffect(effectName, 100);
a.onStopAll(); a.onStopAll();
t.equals(a.effects[effectName], 0); t.equals(a.effects[effectName], 0);
t.end(); t.end();
}); });
test('#getCostumes returns the costumes', function (t) { test('#getCostumes returns the costumes', t => {
var spr = new Sprite(); const spr = new Sprite();
var a = new RenderedTarget(spr, null); const a = new RenderedTarget(spr, null);
var costumes = [1, 2, 3]; const costumes = [1, 2, 3];
a.sprite.costumes = costumes; a.sprite.costumes = costumes;
t.equals(a.getCostumes(), costumes); t.equals(a.getCostumes(), costumes);
t.end(); t.end();
}); });
test('#getSounds returns the sounds', function (t) { test('#getSounds returns the sounds', t => {
var spr = new Sprite(); const spr = new Sprite();
var a = new RenderedTarget(spr, null); const a = new RenderedTarget(spr, null);
var sounds = [1, 2, 3]; const sounds = [1, 2, 3];
a.sprite.sounds = sounds; a.sprite.sounds = sounds;
t.equals(a.getSounds(), sounds); t.equals(a.getSounds(), sounds);
t.end(); t.end();
}); });
test('#toJSON returns the sounds and costumes', function (t) { test('#toJSON returns the sounds and costumes', t => {
var spr = new Sprite(); const spr = new Sprite();
var a = new RenderedTarget(spr, null); const a = new RenderedTarget(spr, null);
var sounds = [1, 2, 3]; const sounds = [1, 2, 3];
var costumes = ['a', 'b', 'c']; const costumes = ['a', 'b', 'c'];
a.sprite.sounds = sounds; a.sprite.sounds = sounds;
a.sprite.costumes = costumes; a.sprite.costumes = costumes;
t.same(a.toJSON().sounds, sounds); t.same(a.toJSON().sounds, sounds);

View file

@ -1,7 +1,7 @@
var test = require('tap').test; const test = require('tap').test;
var cast = require('../../src/util/cast'); const cast = require('../../src/util/cast');
test('toNumber', function (t) { test('toNumber', t => {
// Numeric // Numeric
t.strictEqual(cast.toNumber(0), 0); t.strictEqual(cast.toNumber(0), 0);
t.strictEqual(cast.toNumber(1), 1); t.strictEqual(cast.toNumber(1), 1);
@ -27,7 +27,7 @@ test('toNumber', function (t) {
t.end(); t.end();
}); });
test('toBoolean', function (t) { test('toBoolean', t => {
// Numeric // Numeric
t.strictEqual(cast.toBoolean(0), false); t.strictEqual(cast.toBoolean(0), false);
t.strictEqual(cast.toBoolean(1), true); t.strictEqual(cast.toBoolean(1), true);
@ -50,7 +50,7 @@ test('toBoolean', function (t) {
t.end(); t.end();
}); });
test('toString', function (t) { test('toString', t => {
// Numeric // Numeric
t.strictEqual(cast.toString(0), '0'); t.strictEqual(cast.toString(0), '0');
t.strictEqual(cast.toString(1), '1'); t.strictEqual(cast.toString(1), '1');
@ -73,7 +73,7 @@ test('toString', function (t) {
t.end(); t.end();
}); });
test('toRbgColorList', function (t) { test('toRbgColorList', t => {
// Hex (minimal, see "color" util tests) // Hex (minimal, see "color" util tests)
t.deepEqual(cast.toRgbColorList('#000'), [0, 0, 0]); t.deepEqual(cast.toRgbColorList('#000'), [0, 0, 0]);
t.deepEqual(cast.toRgbColorList('#000000'), [0, 0, 0]); t.deepEqual(cast.toRgbColorList('#000000'), [0, 0, 0]);
@ -91,7 +91,7 @@ test('toRbgColorList', function (t) {
t.end(); t.end();
}); });
test('toRbgColorObject', function (t) { test('toRbgColorObject', t => {
// Hex (minimal, see "color" util tests) // Hex (minimal, see "color" util tests)
t.deepEqual(cast.toRgbColorObject('#000'), {r: 0, g: 0, b: 0}); t.deepEqual(cast.toRgbColorObject('#000'), {r: 0, g: 0, b: 0});
t.deepEqual(cast.toRgbColorObject('#000000'), {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(); t.end();
}); });
test('compare', function (t) { test('compare', t => {
// Numeric // Numeric
t.strictEqual(cast.compare(0, 0), 0); t.strictEqual(cast.compare(0, 0), 0);
t.strictEqual(cast.compare(1, 0), 1); t.strictEqual(cast.compare(1, 0), 1);
@ -137,7 +137,7 @@ test('compare', function (t) {
t.end(); t.end();
}); });
test('isInt', function (t) { test('isInt', t => {
// Numeric // Numeric
t.strictEqual(cast.isInt(0), true); t.strictEqual(cast.isInt(0), true);
t.strictEqual(cast.isInt(1), true); t.strictEqual(cast.isInt(1), true);
@ -162,9 +162,9 @@ test('isInt', function (t) {
t.end(); t.end();
}); });
test('toListIndex', function (t) { test('toListIndex', t => {
var list = [0, 1, 2, 3, 4, 5]; const list = [0, 1, 2, 3, 4, 5];
var empty = []; const empty = [];
// Valid // Valid
t.strictEqual(cast.toListIndex(1, list.length), 1); 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); t.strictEqual(cast.toListIndex('last', empty.length), cast.LIST_INVALID);
// "random" // "random"
var random = cast.toListIndex('random', list.length); const random = cast.toListIndex('random', list.length);
t.ok(random <= list.length); t.ok(random <= list.length);
t.ok(random > 0); t.ok(random > 0);
t.strictEqual(cast.toListIndex('random', empty.length), cast.LIST_INVALID); t.strictEqual(cast.toListIndex('random', empty.length), cast.LIST_INVALID);
// "any" (alias for "random") // "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 <= list.length);
t.ok(any > 0); t.ok(any > 0);
t.strictEqual(cast.toListIndex('any', empty.length), cast.LIST_INVALID); t.strictEqual(cast.toListIndex('any', empty.length), cast.LIST_INVALID);

View file

@ -1,5 +1,5 @@
var test = require('tap').test; const test = require('tap').test;
var color = require('../../src/util/color'); const color = require('../../src/util/color');
/** /**
* Assert that two HSV colors are similar to each other, within a tolerance. * 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} actual - the first HSV color to compare.
* @param {HSVObject} expected - the other 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) || if ((Math.abs(actual.h - expected.h) >= 1) ||
(Math.abs(actual.s - expected.s) >= 0.01) || (Math.abs(actual.s - expected.s) >= 0.01) ||
(Math.abs(actual.v - expected.v) >= 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} actual - the first RGB color to compare.
* @param {RGBObject} expected - the other 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) || if ((Math.abs(actual.r - expected.r) >= 1) ||
(Math.abs(actual.g - expected.g) >= 1) || (Math.abs(actual.g - expected.g) >= 1) ||
(Math.abs(actual.b - expected.b) >= 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(0), '#000000');
t.strictEqual(color.decimalToHex(1), '#000001'); t.strictEqual(color.decimalToHex(1), '#000001');
t.strictEqual(color.decimalToHex(16777215), '#ffffff'); t.strictEqual(color.decimalToHex(16777215), '#ffffff');
@ -46,7 +46,7 @@ test('decimalToHex', function (t) {
t.end(); 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(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(1), {a: 255, r: 0, g: 0, b: 1});
t.deepEqual(color.decimalToRgb(16777215), {a: 255, r: 255, g: 255, b: 255}); t.deepEqual(color.decimalToRgb(16777215), {a: 255, r: 255, g: 255, b: 255});
@ -55,7 +55,7 @@ test('decimalToRgb', function (t) {
t.end(); t.end();
}); });
test('hexToRgb', function (t) { test('hexToRgb', t => {
t.deepEqual(color.hexToRgb('#000'), {r: 0, g: 0, b: 0}); 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('#000000'), {r: 0, g: 0, b: 0});
t.deepEqual(color.hexToRgb('#fff'), {r: 255, g: 255, b: 255}); t.deepEqual(color.hexToRgb('#fff'), {r: 255, g: 255, b: 255});
@ -73,21 +73,21 @@ test('hexToRgb', function (t) {
t.end(); 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: 0, g: 0, b: 0}), '#000000');
t.strictEqual(color.rgbToHex({r: 255, g: 255, b: 255}), '#ffffff'); t.strictEqual(color.rgbToHex({r: 255, g: 255, b: 255}), '#ffffff');
t.strictEqual(color.rgbToHex({r: 0, g: 255, b: 170}), '#00ffaa'); t.strictEqual(color.rgbToHex({r: 0, g: 255, b: 170}), '#00ffaa');
t.end(); 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: 0, g: 0, b: 0}), 0);
t.strictEqual(color.rgbToDecimal({r: 255, g: 255, b: 255}), 16777215); t.strictEqual(color.rgbToDecimal({r: 255, g: 255, b: 255}), 16777215);
t.strictEqual(color.rgbToDecimal({r: 0, g: 255, b: 170}), 65450); t.strictEqual(color.rgbToDecimal({r: 0, g: 255, b: 170}), 65450);
t.end(); t.end();
}); });
test('hexToDecimal', function (t) { test('hexToDecimal', t => {
t.strictEqual(color.hexToDecimal('#000'), 0); t.strictEqual(color.hexToDecimal('#000'), 0);
t.strictEqual(color.hexToDecimal('#000000'), 0); t.strictEqual(color.hexToDecimal('#000000'), 0);
t.strictEqual(color.hexToDecimal('#fff'), 16777215); t.strictEqual(color.hexToDecimal('#fff'), 16777215);
@ -97,7 +97,7 @@ test('hexToDecimal', function (t) {
t.end(); 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: 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: 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}); 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(); 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: 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: 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}); 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(); 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}, -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), {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}); rgbSimilar(t, color.mixRgb({r: 10, g: 20, b: 30}, {r: 30, g: 40, b: 50}, 0.25), {r: 15, g: 25, b: 35});

View file

@ -1,7 +1,7 @@
var test = require('tap').test; const test = require('tap').test;
var math = require('../../src/util/math-util'); const math = require('../../src/util/math-util');
test('degToRad', function (t) { test('degToRad', t => {
t.strictEqual(math.degToRad(0), 0); t.strictEqual(math.degToRad(0), 0);
t.strictEqual(math.degToRad(1), 0.017453292519943295); t.strictEqual(math.degToRad(1), 0.017453292519943295);
t.strictEqual(math.degToRad(180), Math.PI); t.strictEqual(math.degToRad(180), Math.PI);
@ -10,7 +10,7 @@ test('degToRad', function (t) {
t.end(); t.end();
}); });
test('radToDeg', function (t) { test('radToDeg', t => {
t.strictEqual(math.radToDeg(0), 0); t.strictEqual(math.radToDeg(0), 0);
t.strictEqual(math.radToDeg(1), 57.29577951308232); t.strictEqual(math.radToDeg(1), 57.29577951308232);
t.strictEqual(math.radToDeg(180), 10313.240312354817); t.strictEqual(math.radToDeg(180), 10313.240312354817);
@ -19,7 +19,7 @@ test('radToDeg', function (t) {
t.end(); t.end();
}); });
test('clamp', function (t) { test('clamp', t => {
t.strictEqual(math.clamp(0, 0, 10), 0); t.strictEqual(math.clamp(0, 0, 10), 0);
t.strictEqual(math.clamp(1, 0, 10), 1); t.strictEqual(math.clamp(1, 0, 10), 1);
t.strictEqual(math.clamp(-10, 0, 10), 0); t.strictEqual(math.clamp(-10, 0, 10), 0);
@ -27,7 +27,7 @@ test('clamp', function (t) {
t.end(); t.end();
}); });
test('wrapClamp', function (t) { test('wrapClamp', t => {
t.strictEqual(math.wrapClamp(0, 0, 10), 0); t.strictEqual(math.wrapClamp(0, 0, 10), 0);
t.strictEqual(math.wrapClamp(1, 0, 10), 1); t.strictEqual(math.wrapClamp(1, 0, 10), 1);
t.strictEqual(math.wrapClamp(-10, 0, 10), 1); t.strictEqual(math.wrapClamp(-10, 0, 10), 1);
@ -35,7 +35,7 @@ test('wrapClamp', function (t) {
t.end(); t.end();
}); });
test('tan', function (t) { test('tan', t => {
t.strictEqual(math.tan(90), Infinity); t.strictEqual(math.tan(90), Infinity);
t.strictEqual(math.tan(180), 0); t.strictEqual(math.tan(180), 0);
t.strictEqual(math.tan(-90), -Infinity); t.strictEqual(math.tan(-90), -Infinity);

View file

@ -1,7 +1,7 @@
var test = require('tap').test; const test = require('tap').test;
var StringUtil = require('../../src/util/string-util'); 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'), 'boeing');
t.strictEqual(StringUtil.withoutTrailingDigits('boeing747 '), 'boeing747 '); t.strictEqual(StringUtil.withoutTrailingDigits('boeing747 '), 'boeing747 ');
t.strictEqual(StringUtil.withoutTrailingDigits('boeing𝟨'), 'boeing𝟨'); t.strictEqual(StringUtil.withoutTrailingDigits('boeing𝟨'), 'boeing𝟨');
@ -10,7 +10,7 @@ test('withoutTrailingDigits', function (t) {
t.end(); t.end();
}); });
test('unusedName', function (t) { test('unusedName', t => {
t.strictEqual( t.strictEqual(
StringUtil.unusedName( StringUtil.unusedName(
'name', 'name',

View file

@ -1,8 +1,8 @@
var test = require('tap').test; const test = require('tap').test;
var Timer = require('../../src/util/timer'); const Timer = require('../../src/util/timer');
test('spec', function (t) { test('spec', t => {
var timer = new Timer(); const timer = new Timer();
t.type(Timer, 'function'); t.type(Timer, 'function');
t.type(timer, 'object'); t.type(timer, 'object');
@ -15,25 +15,25 @@ test('spec', function (t) {
t.end(); t.end();
}); });
test('time', function (t) { test('time', t => {
var timer = new Timer(); const timer = new Timer();
var time = timer.time(); const time = timer.time();
t.ok(Date.now() >= time); t.ok(Date.now() >= time);
t.end(); t.end();
}); });
test('start / timeElapsed', function (t) { test('start / timeElapsed', t => {
var timer = new Timer(); const timer = new Timer();
var delay = 100; const delay = 100;
var threshold = 1000 / 60; // 60 hz const threshold = 1000 / 60; // 60 hz
// Start timer // Start timer
timer.start(); timer.start();
// Wait and measure timer // Wait and measure timer
setTimeout(function () { setTimeout(() => {
var timeElapsed = timer.timeElapsed(); const timeElapsed = timer.timeElapsed();
t.ok(timeElapsed >= 0); t.ok(timeElapsed >= 0);
t.ok(timeElapsed >= (delay - threshold) && t.ok(timeElapsed >= (delay - threshold) &&
timeElapsed <= (delay + threshold)); timeElapsed <= (delay + threshold));

View file

@ -1,9 +1,9 @@
var test = require('tap').test; const test = require('tap').test;
var xml = require('../../src/util/xml-escape'); const xml = require('../../src/util/xml-escape');
test('escape', function (t) { test('escape', t => {
var input = '<foo bar="he & llo \'"></foo>'; const input = '<foo bar="he & llo \'"></foo>';
var output = '&lt;foo bar=&quot;he &amp; llo &apos;&quot;&gt;&lt;/foo&gt;'; const output = '&lt;foo bar=&quot;he &amp; llo &apos;&quot;&gt;&lt;/foo&gt;';
t.strictEqual(xml(input), output); t.strictEqual(xml(input), output);
t.end(); t.end();
}); });

View file

@ -1,8 +1,8 @@
var test = require('tap').test; const test = require('tap').test;
var VirtualMachine = require('../../src/virtual-machine.js'); const VirtualMachine = require('../../src/virtual-machine.js');
test('renameSprite throws when there is no sprite with that id', function (t) { test('renameSprite throws when there is no sprite with that id', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
vm.runtime.getTargetById = () => null; vm.runtime.getTargetById = () => null;
t.throws( t.throws(
(() => vm.renameSprite('id', 'name')), (() => vm.renameSprite('id', 'name')),
@ -11,9 +11,9 @@ test('renameSprite throws when there is no sprite with that id', function (t) {
t.end(); t.end();
}); });
test('renameSprite throws when used on a non-sprite target', function (t) { test('renameSprite throws when used on a non-sprite target', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
var fakeTarget = { const fakeTarget = {
isSprite: () => false isSprite: () => false
}; };
vm.runtime.getTargetById = () => (fakeTarget); vm.runtime.getTargetById = () => (fakeTarget);
@ -24,9 +24,9 @@ test('renameSprite throws when used on a non-sprite target', function (t) {
t.end(); t.end();
}); });
test('renameSprite throws when there is no sprite for given target', function (t) { test('renameSprite throws when there is no sprite for given target', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
var fakeTarget = { const fakeTarget = {
sprite: null, sprite: null,
isSprite: () => true isSprite: () => true
}; };
@ -38,9 +38,9 @@ test('renameSprite throws when there is no sprite for given target', function (t
t.end(); t.end();
}); });
test('renameSprite sets the sprite name', function (t) { test('renameSprite sets the sprite name', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
var fakeTarget = { const fakeTarget = {
sprite: {name: 'original'}, sprite: {name: 'original'},
isSprite: () => true isSprite: () => true
}; };
@ -50,9 +50,9 @@ test('renameSprite sets the sprite name', function (t) {
t.end(); t.end();
}); });
test('renameSprite does not set sprite names to an empty string', function (t) { test('renameSprite does not set sprite names to an empty string', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
var fakeTarget = { const fakeTarget = {
sprite: {name: 'original'}, sprite: {name: 'original'},
isSprite: () => true isSprite: () => true
}; };
@ -62,9 +62,9 @@ test('renameSprite does not set sprite names to an empty string', function (t) {
t.end(); t.end();
}); });
test('renameSprite does not set sprite names to reserved names', function (t) { test('renameSprite does not set sprite names to reserved names', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
var fakeTarget = { const fakeTarget = {
sprite: {name: 'original'}, sprite: {name: 'original'},
isSprite: () => true isSprite: () => true
}; };
@ -74,8 +74,8 @@ test('renameSprite does not set sprite names to reserved names', function (t) {
t.end(); t.end();
}); });
test('renameSprite increments from existing sprite names', function (t) { test('renameSprite increments from existing sprite names', t => {
var vm = new VirtualMachine(); const vm = new VirtualMachine();
vm.emitTargetsUpdate = () => {}; vm.emitTargetsUpdate = () => {};
vm.runtime.targets = [{ vm.runtime.targets = [{
id: 'id1', id: 'id1',

View file

@ -1,9 +1,9 @@
var CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
var defaultsDeep = require('lodash.defaultsdeep'); const defaultsDeep = require('lodash.defaultsdeep');
var path = require('path'); const path = require('path');
var webpack = require('webpack'); const webpack = require('webpack');
var base = { const base = {
devServer: { devServer: {
contentBase: false, contentBase: false,
host: '0.0.0.0', host: '0.0.0.0',