Skip to content

Commit

Permalink
Use ES6 linting rules in the project root
Browse files Browse the repository at this point in the history
Update all tests for `no-var` and `prefer-arrow-callback` (using `--fix`)
  • Loading branch information
Ray Schamp committed Apr 24, 2017
1 parent 5f59d1e commit bafdf8d
Show file tree
Hide file tree
Showing 36 changed files with 666 additions and 666 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['scratch', 'scratch/node']
extends: ['scratch', 'scratch/node', 'scratch/es6']
};
22 changes: 11 additions & 11 deletions test/fixtures/attach-test-storage.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var ScratchStorage = require('scratch-storage');
const ScratchStorage = require('scratch-storage');

var ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/';
var PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/';
const ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu/';
const PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/';

/**
* @param {Asset} asset - calculate a URL for this asset.
* @returns {string} a URL to download a project file.
*/
var getProjectUrl = function (asset) {
var assetIdParts = asset.assetId.split('.');
var assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/'];
const getProjectUrl = function (asset) {
const assetIdParts = asset.assetId.split('.');
const assetUrlParts = [PROJECT_SERVER, 'internalapi/project/', assetIdParts[0], '/get/'];
if (assetIdParts[1]) {
assetUrlParts.push(assetIdParts[1]);
}
Expand All @@ -20,8 +20,8 @@ var getProjectUrl = function (asset) {
* @param {Asset} asset - calculate a URL for this asset.
* @returns {string} a URL to download a project asset (PNG, WAV, etc.)
*/
var getAssetUrl = function (asset) {
var assetUrlParts = [
const getAssetUrl = function (asset) {
const assetUrlParts = [
ASSET_SERVER,
'internalapi/asset/',
asset.assetId,
Expand All @@ -36,9 +36,9 @@ var getAssetUrl = function (asset) {
* Construct a new instance of ScratchStorage, provide it with default web sources, and attach it to the provided VM.
* @param {VirtualMachine} vm - the VM which will own the new ScratchStorage instance.
*/
var attachTestStorage = function (vm) {
var storage = new ScratchStorage();
var AssetType = storage.AssetType;
const attachTestStorage = function (vm) {
const storage = new ScratchStorage();
const AssetType = storage.AssetType;
storage.addWebSource([AssetType.Project], getProjectUrl);
storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl);
vm.attachStorage(storage);
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/extract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var AdmZip = require('adm-zip');
const AdmZip = require('adm-zip');

module.exports = function (path) {
var zip = new AdmZip(path);
const zip = new AdmZip(path);
return zip.readAsText('project.json', 'utf8');
};
2 changes: 1 addition & 1 deletion test/fixtures/fake-renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var FakeRenderer = function () {
const FakeRenderer = function () {
this.unused = '';
this.x = 0;
this.y = 0;
Expand Down
40 changes: 20 additions & 20 deletions test/integration/complex.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
var fs = require('fs');
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
const fs = require('fs');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

var projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
var project = extract(projectUri);
const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
const project = extract(projectUri);

var spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
var sprite = fs.readFileSync(spriteUri, 'utf8');
const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
const sprite = fs.readFileSync(spriteUri, 'utf8');

test('complex', function (t) {
var vm = new VirtualMachine();
test('complex', t => {
const vm = new VirtualMachine();
attachTestStorage(vm);

// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var threads = JSON.parse(e.threads);
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length === 0);
t.end();
process.nextTick(process.exit);
});

// Manipulate each target
vm.on('targetsUpdate', function (data) {
var targets = data.targetList;
for (var i in targets) {
vm.on('targetsUpdate', data => {
const targets = data.targetList;
for (const i in targets) {
if (targets[i].isStage === true) continue;
if (targets[i].name.match(/test/)) continue;

Expand Down Expand Up @@ -55,12 +55,12 @@ test('complex', function (t) {
});

// Start VM, load project, and run
t.doesNotThrow(function () {
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(function () {
vm.loadProject(project).then(() => {
vm.greenFlag();

// Post IO data
Expand Down Expand Up @@ -89,7 +89,7 @@ test('complex', function (t) {
);

// After two seconds, get playground data and stop
setTimeout(function () {
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
Expand Down
28 changes: 14 additions & 14 deletions test/integration/control.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

var uri = path.resolve(__dirname, '../fixtures/control.sb2');
var project = extract(uri);
const uri = path.resolve(__dirname, '../fixtures/control.sb2');
const project = extract(uri);

test('control', function (t) {
var vm = new VirtualMachine();
test('control', t => {
const vm = new VirtualMachine();
attachTestStorage(vm);

// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var threads = JSON.parse(e.threads);
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length > 0);
t.end();
process.nextTick(process.exit);
});

// Start VM, load project, and run
t.doesNotThrow(function () {
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(function () {
vm.loadProject(project).then(() => {
vm.greenFlag();
});
});

// After two seconds, get playground data and stop
setTimeout(function () {
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
Expand Down
26 changes: 13 additions & 13 deletions test/integration/data.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

var uri = path.resolve(__dirname, '../fixtures/data.sb2');
var project = extract(uri);
const uri = path.resolve(__dirname, '../fixtures/data.sb2');
const project = extract(uri);

test('data', function (t) {
var vm = new VirtualMachine();
test('data', t => {
const vm = new VirtualMachine();
attachTestStorage(vm);

// Evaluate playground data and exit
vm.on('playgroundData', function () {
vm.on('playgroundData', () => {
// @todo Additional tests
t.end();
process.nextTick(process.exit);
});

// Start VM, load project, and run
t.doesNotThrow(function () {
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(function () {
vm.loadProject(project).then(() => {
vm.greenFlag();

// After two seconds, get playground data and stop
setTimeout(function () {
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
Expand Down
28 changes: 14 additions & 14 deletions test/integration/event.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

var uri = path.resolve(__dirname, '../fixtures/event.sb2');
var project = extract(uri);
const uri = path.resolve(__dirname, '../fixtures/event.sb2');
const project = extract(uri);

test('event', function (t) {
var vm = new VirtualMachine();
test('event', t => {
const vm = new VirtualMachine();
attachTestStorage(vm);

// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var threads = JSON.parse(e.threads);
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length > 0);
t.end();
process.nextTick(process.exit);
});

// Start VM, load project, and run
t.doesNotThrow(function () {
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(function () {
vm.loadProject(project).then(() => {
vm.greenFlag();

// After two seconds, get playground data and stop
setTimeout(function () {
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
Expand Down
30 changes: 15 additions & 15 deletions test/integration/hat-execution-order.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

var projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
var project = extract(projectUri);
const projectUri = path.resolve(__dirname, '../fixtures/hat-execution-order.sb2');
const project = extract(projectUri);

test('complex', function (t) {
var vm = new VirtualMachine();
test('complex', t => {
const vm = new VirtualMachine();
attachTestStorage(vm);

// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var threads = JSON.parse(e.threads);
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length === 0);

var results = vm.runtime.targets[0].lists.results.contents;
const results = vm.runtime.targets[0].lists.results.contents;
t.deepEqual(results, ['3', '2', '1', 'stage']);

t.end();
process.nextTick(process.exit);
});

// Start VM, load project, and run
t.doesNotThrow(function () {
t.doesNotThrow(() => {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project).then(function () {
vm.loadProject(project).then(() => {
vm.greenFlag();

// After two seconds, get playground data and stop
setTimeout(function () {
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
Expand Down
26 changes: 13 additions & 13 deletions test/integration/import_sb2.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
var path = require('path');
var test = require('tap').test;
var attachTestStorage = require('../fixtures/attach-test-storage');
var extract = require('../fixtures/extract');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');

var renderedTarget = require('../../src/sprites/rendered-target');
var runtime = require('../../src/engine/runtime');
var sb2 = require('../../src/import/sb2import');
const renderedTarget = require('../../src/sprites/rendered-target');
const runtime = require('../../src/engine/runtime');
const sb2 = require('../../src/import/sb2import');

test('spec', function (t) {
test('spec', t => {
t.type(sb2, 'function');
t.end();
});

test('default', function (t) {
test('default', t => {
// Get SB2 JSON (string)
var uri = path.resolve(__dirname, '../fixtures/default.sb2');
var file = extract(uri);
const uri = path.resolve(__dirname, '../fixtures/default.sb2');
const file = extract(uri);

// Create runtime instance & load SB2 into it
var rt = new runtime();
const rt = new runtime();
attachTestStorage(rt);
sb2(file, rt).then(function (targets) {
sb2(file, rt).then(targets => {
// Test
t.type(file, 'string');
t.type(rt, 'object');
Expand Down
Loading

0 comments on commit bafdf8d

Please sign in to comment.