Merge pull request from thisandagain/testing

Test Suite Adjustments
This commit is contained in:
Shane M. Clements 2014-04-10 14:46:21 -06:00
commit fa42953d58
25 changed files with 1195 additions and 1133 deletions

26
.jscsrc Normal file
View file

@ -0,0 +1,26 @@
{
"requireCurlyBraces": [
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"default"
],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowEmptyBlocks": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"validateIndentation": 4,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"safeContextKeyword": "self"
}

View file

@ -28,41 +28,18 @@ The tests are written using Karma and there should be a 100% passing rate in ord
The expectation is to add a unit test for any code that you contribute to the project.
Install Node (NPM) (https://npmjs.org/)
Install Node
---------------------------------------
Brew:
```
$ brew install npm
```
To install [Node.js](http://nodejs.org) and [NPM](http://npmjs.org) simply go to [http://nodejs.org](http://nodejs.org/), download the package for your operating system and install. Once installed, navigate to your local scratch directory and run:
Mac Ports:
```
$ port install npm
```
In your local scratch directory
```
$ npm install
```
Local copy of jQuery
--------------------
```
$ cd test/lib
$ curl http://code.jquery.com/jquery-1.11.0.min.js > jquery-1.11.0.min.js
```bash
npm install
```
To Run the tests
----------------
```bash
npm test
```
$ ./scripts/test.sh
```
To configure the unit tests
---------------------------
The karam.conf.js file is location in the config directory

View file

@ -37,12 +37,12 @@ var IO = function() {
};
IO.prototype.loadProject = function(project_id) {
var runningIO = this;
var self = this;
$.getJSON(this.project_base + project_id + this.project_suffix, function(data) {
runningIO.data = data;
runningIO.makeObjects();
runningIO.loadThreads();
runningIO.loadNotesDrums();
self.data = data;
self.makeObjects();
self.loadThreads();
self.loadNotesDrums();
runtime.loadStart(); // Try to run the project.
});
};

View file

@ -319,8 +319,11 @@ Interpreter.prototype.lookupPrim = function(op) {
Interpreter.prototype.primNoop = function(b) { console.log(b.op); };
Interpreter.prototype.primWait = function(b) {
if (interp.activeThread.firstTime) interp.startTimer(interp.numarg(b, 0));
else interp.checkTimer();
if (interp.activeThread.firstTime) {
interp.startTimer(interp.numarg(b, 0));
} else {
interp.checkTimer();
}
};
Interpreter.prototype.primRepeat = function(b) {
@ -348,7 +351,9 @@ Interpreter.prototype.broadcast = function(b, waitFlag) {
}
}
runtime.allStacksDo(findReceivers);
for (pair in receivers) interp.restartThread(receivers[pair][0], receivers[pair][1]);
for (pair in receivers) {
interp.restartThread(receivers[pair][0], receivers[pair][1]);
}
if (!waitFlag) return;
interp.activeThread.tmpObj = receivers;
interp.activeThread.firstTime = false;

View file

@ -38,14 +38,10 @@ var Reporter = function(data) {
};
Reporter.prototype.determineReporterLabel = function() {
if (this.target === 'Stage' && this.cmd === "getVar:") {
return this.param;
} else if (this.target === 'Stage' && this.param === null) {
return this.cmd;
} else {
if (this.target === 'Stage' && this.cmd === "getVar:") return this.param;
if (this.target === 'Stage' && this.param === null) return this.cmd;
return this.target + ': ' + this.param;
}
}
Reporter.prototype.attach = function(scene) {
switch (this.mode) {

View file

@ -173,9 +173,9 @@ Sprite.prototype.attach = function(scene) {
// Load sounds from the server and buffer them
Sprite.prototype.loadSounds = function() {
var spr = this;
var self = this;
$.each(this.sounds, function(index, sound) {
io.soundRequest(sound, spr);
io.soundRequest(sound, self);
});
};
@ -308,21 +308,27 @@ Sprite.prototype.updateTransform = function() {
// sign to the X scale.
}
$(this.mesh).css('transform',
'translatex(' + drawX + 'px) \
translatey(' + drawY + 'px) \
rotate(' + this.rotation + 'deg) \
scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')');
$(this.mesh).css('-moz-transform',
'translatex(' + drawX + 'px) \
translatey(' + drawY + 'px) \
rotate(' + this.rotation + 'deg) \
scaleX(' + scaleXprepend + this.scale + ') scaleY(' + this.scale / resolution + ')');
$(this.mesh).css('-webkit-transform',
'translatex(' + drawX + 'px) \
translatey(' + drawY + 'px) \
rotate(' + this.rotation + 'deg) \
scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')');
$(this.mesh).css(
'transform',
'translatex(' + drawX + 'px) ' +
'translatey(' + drawY + 'px) ' +
'rotate(' + this.rotation + 'deg) ' +
'scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'
);
$(this.mesh).css(
'-moz-transform',
'translatex(' + drawX + 'px) ' +
'translatey(' + drawY + 'px) ' +
'rotate(' + this.rotation + 'deg) ' +
'scaleX(' + scaleXprepend + this.scale + ') scaleY(' + this.scale / resolution + ')'
);
$(this.mesh).css(
'-webkit-transform',
'translatex(' + drawX + 'px) ' +
'translatey(' + drawY + 'px) ' +
'rotate(' + this.rotation + 'deg) ' +
'scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'
);
$(this.mesh).css('-webkit-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
$(this.mesh).css('-moz-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
@ -342,9 +348,11 @@ Sprite.prototype.updateTransform = function() {
Sprite.prototype.updateFilters = function() {
$(this.mesh).css('opacity', 1 - this.filters.ghost / 100);
$(this.mesh).css('-webkit-filter',
'hue-rotate(' + (this.filters.color * 1.8) + 'deg) \
brightness(' + (this.filters.brightness < 0 ? this.filters.brightness / 100 + 1 : Math.min(2.5, this.filters.brightness * .015 + 1)) + ')');
$(this.mesh).css(
'-webkit-filter',
'hue-rotate(' + (this.filters.color * 1.8) + 'deg) ' +
'brightness(' + (this.filters.brightness < 0 ? this.filters.brightness / 100 + 1 : Math.min(2.5, this.filters.brightness * .015 + 1)) + ')'
);
};
Sprite.prototype.getTalkBubbleXY = function() {

View file

@ -123,9 +123,13 @@ VarListPrims.prototype.primListDeleteLine = function(b) {
var list = findList(interp.targetSprite(), interp.arg(b, 1));
if (!list) return;
var line = interp.arg(b, 0);
if (line == 'all' || list.length == 0) list.length = 0;
else if (line == 'last') list.splice(list.length - 1, 1);
else if (parseInt(line, 10) - 1 in list) list.splice(parseInt(line, 10) - 1, 1);
if (line == 'all' || list.length == 0) {
list.length = 0;
} else if (line == 'last') {
list.splice(list.length - 1, 1);
} else if (parseInt(line, 10) - 1 in list) {
list.splice(parseInt(line, 10) - 1, 1);
}
};
VarListPrims.prototype.primListInsertAt = function(b) {
@ -134,9 +138,13 @@ VarListPrims.prototype.primListInsertAt = function(b) {
var newItem = interp.arg(b, 0);
var position = interp.arg(b, 1);
if (position == 'last') position = list.length;
else if (position == 'random') position = Math.round(Math.random() * list.length);
else position = parseInt(position, 10) - 1;
if (position == 'last') {
position = list.length;
} else if (position == 'random') {
position = Math.round(Math.random() * list.length);
} else {
position = parseInt(position, 10) - 1;
}
if (position > list.length) return;
list.splice(position, 0, newItem);
@ -148,12 +156,15 @@ VarListPrims.prototype.primListSetLine = function(b) {
var newItem = interp.arg(b, 2);
var position = interp.arg(b, 0);
if (position == 'last') position = list.length - 1;
else if (position == 'random') position = Math.floor(Math.random() * list.length);
else position = parseInt(position, 10) - 1;
if (position == 'last') {
position = list.length - 1;
} else if (position == 'random') {
position = Math.floor(Math.random() * list.length);
} else {
position = parseInt(position, 10) - 1;
}
if (position > list.length - 1) return;
list[position] = newItem;
};

View file

@ -107,8 +107,8 @@ NotePlayer.prototype.interpolatedSample = function() {
NotePlayer.prototype.rawSample = function(sampleIndex) {
if (sampleIndex >= this.endOffset) {
if (this.isLooped) sampleIndex = this.loopPoint;
else return 0;
if (!this.isLooped) return 0;
sampleIndex = this.loopPoint;
}
var byteIndex = 2 * sampleIndex;
var result = (this.soundData[byteIndex + 1] << 8) + this.soundData[byteIndex];

View file

@ -32,7 +32,8 @@ var SoundBank = function() {};
// The loop points are -1 if the sound is unlooped (e.g. Marimba).
// The three-element envelop array may be omitted if the instrument has no envelope.
SoundBank.instruments = [
[[38, 'AcousticPiano_As3', 58, 10266, 17053, [0, 100, 22]],
[
[38, 'AcousticPiano_As3', 58, 10266, 17053, [0, 100, 22]],
[44, 'AcousticPiano_C4', 60, 13968, 18975, [0, 100, 20]],
[51, 'AcousticPiano_G4', 67, 12200, 12370, [0, 80, 18]],
[62, 'AcousticPiano_C6', 84, 13042, 13276, [0, 80, 16]],
@ -41,105 +42,126 @@ SoundBank.instruments = [
[85, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 8]],
[90, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 6]],
[96, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 3]],
[128, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 2]]],
[[48, 'ElectricPiano_C2', 36, 15338, 17360, [0, 80, 10]],
[128, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 2]]
],
[
[48, 'ElectricPiano_C2', 36, 15338, 17360, [0, 80, 10]],
[74, 'ElectricPiano_C4', 60, 11426, 12016, [0, 40, 8]],
[128, 'ElectricPiano_C4', 60, 11426, 12016, [0, 0, 6]]],
[[128, 'Organ_G2', 43, 1306, 3330]],
[[40, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 15]],
[128, 'ElectricPiano_C4', 60, 11426, 12016, [0, 0, 6]]
],
[
[128, 'Organ_G2', 43, 1306, 3330]
],
[
[40, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 15]],
[56, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 13.5]],
[60, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 12]],
[67, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 8.5]],
[72, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 7]],
[83, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 5.5]],
[128, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 4.5]]],
[[40, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 15]],
[128, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 4.5]]
],
[
[40, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 15]],
[56, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 13.5]],
[60, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 12]],
[67, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 8.5]],
[72, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 7]],
[83, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 5.5]],
[128, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 4.5]]],
[[34, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 17]],
[128, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 4.5]]
],
[
[34, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 17]],
[48, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 14]],
[64, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 12]],
[128, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 10]]],
[[38, 'Pizz_G2', 43, 8554, 8782, [0, 0, 5]],
[128, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 10]]
],
[
[38, 'Pizz_G2', 43, 8554, 8782, [0, 0, 5]],
[45, 'Pizz_G2', 43, 8554, 8782, [0, 12, 4]],
[56, 'Pizz_A3', 57, 11460, 11659, [0, 0, 4]],
[64, 'Pizz_A3', 57, 11460, 11659, [0, 0, 3.2]],
[72, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.8]],
[80, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.2]],
[128, 'Pizz_E4', 64, 17525, 17592, [0, 0, 1.5]]],
[[41, 'Cello_C2', 36, 8548, 8885],
[128, 'Pizz_E4', 64, 17525, 17592, [0, 0, 1.5]]
],
[
[41, 'Cello_C2', 36, 8548, 8885],
[52, 'Cello_As2', 46, 7465, 7845],
[62, 'Violin_D4', 62, 10608, 11360],
[75, 'Violin_A4', 69, 3111, 3314, [70, 0, 0]],
[128, 'Violin_E5', 76, 2383, 2484]],
[[30, 'BassTrombone_A2_3', 45, 1357, 2360],
[128, 'Violin_E5', 76, 2383, 2484]
],
[
[30, 'BassTrombone_A2_3', 45, 1357, 2360],
[40, 'BassTrombone_A2_2', 45, 1893, 2896],
[55, 'Trombone_B3', 59, 2646, 3897],
[88, 'Trombone_B3', 59, 2646, 3897, [50, 0, 0]],
[128, 'Trumpet_E5', 76, 2884, 3152]],
[[128, 'Clarinet_C4', 60, 14540, 15468]],
[[40, 'TenorSax_C3', 48, 8939, 10794],
[128, 'Trumpet_E5', 76, 2884, 3152]
],
[
[128, 'Clarinet_C4', 60, 14540, 15468]
],
[
[40, 'TenorSax_C3', 48, 8939, 10794],
[50, 'TenorSax_C3', 48, 8939, 10794, [20, 0, 0]],
[59, 'TenorSax_C3', 48, 8939, 10794, [40, 0, 0]],
[67, 'AltoSax_A3', 57, 8546, 9049],
[75, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]],
[80, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]],
[128, 'AltoSax_C6', 84, 1258, 1848]],
[[61, 'Flute_B5_2', 83, 1859, 2259],
[128, 'Flute_B5_1', 83, 2418, 2818]],
[[128, 'WoodenFlute_C5', 72, 11426, 15724]],
[[57, 'Bassoon_C3', 48, 2428, 4284],
[128, 'AltoSax_C6', 84, 1258, 1848]
],
[
[61, 'Flute_B5_2', 83, 1859, 2259],
[128, 'Flute_B5_1', 83, 2418, 2818]
],
[
[128, 'WoodenFlute_C5', 72, 11426, 15724]
],
[
[57, 'Bassoon_C3', 48, 2428, 4284],
[67, 'Bassoon_C3', 48, 2428, 4284, [40, 0, 0]],
[76, 'Bassoon_C3', 48, 2428, 4284, [80, 0, 0]],
[84, 'EnglishHorn_F3', 53, 7538, 8930, [40, 0, 0]],
[128, 'EnglishHorn_D4', 62, 4857, 5231]],
[[39, 'Choir_F3', 53, 14007, 41281],
[128, 'EnglishHorn_D4', 62, 4857, 5231]
],
[
[39, 'Choir_F3', 53, 14007, 41281],
[50, 'Choir_F3', 53, 14007, 41281, [40, 0, 0]],
[61, 'Choir_F3', 53, 14007, 41281, [60, 0, 0]],
[72, 'Choir_F4', 65, 16351, 46436],
[128, 'Choir_F5', 77, 18440, 45391]],
[[38, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 8]],
[128, 'Choir_F5', 77, 18440, 45391]
],
[
[38, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 8]],
[48, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 7.5]],
[59, 'Vibraphone_C3', 48, 6202, 6370, [0, 60, 7]],
[70, 'Vibraphone_C3', 48, 6202, 6370, [0, 40, 6]],
[78, 'Vibraphone_C3', 48, 6202, 6370, [0, 20, 5]],
[86, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 4]],
[128, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 3]]],
[[128, 'MusicBox_C4', 60, 14278, 14700, [0, 0, 2]]],
[[128, 'SteelDrum_D5', 74.4, -1, -1, [0, 0, 2]]],
[[128, 'Marimba_C4', 60, -1, -1]],
[[80, 'SynthLead_C4', 60, 135, 1400],
[128, 'SynthLead_C6', 84, 124, 356]],
[[38, 'SynthPad_A3', 57, 4212, 88017, [50, 0, 0]],
[128, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 3]]
],
[
[128, 'MusicBox_C4', 60, 14278, 14700, [0, 0, 2]]
],
[
[128, 'SteelDrum_D5', 74.4, -1, -1, [0, 0, 2]]
],
[
[128, 'Marimba_C4', 60, -1, -1]
],
[
[80, 'SynthLead_C4', 60, 135, 1400],
[128, 'SynthLead_C6', 84, 124, 356]
],
[
[38, 'SynthPad_A3', 57, 4212, 88017, [50, 0, 0]],
[50, 'SynthPad_A3', 57, 4212, 88017, [80, 0, 0]],
[62, 'SynthPad_A3', 57, 4212, 88017, [110, 0, 0]],
[74, 'SynthPad_A3', 57, 4212, 88017, [150, 0, 0]],
[86, 'SynthPad_A3', 57, 4212, 88017, [200, 0, 0]],
[128, 'SynthPad_C6', 84, 2575, 9202]],
[128, 'SynthPad_C6', 84, 2575, 9202]
]
];
// -----------------------------

20
makefile Normal file
View file

@ -0,0 +1,20 @@
JSCS_PATH = ./node_modules/.bin/jscs
KARMA_PATH = ./node_modules/.bin/karma
KARMA_CONFIG = ./test/fixtures/karma.conf.js
# Performs code governance (lint + style) test
lint:
@$(JSCS_PATH) ./js/*
@$(JSCS_PATH) ./test/unit/*
# Performs unit tests
unit:
@$(KARMA_PATH) start $(KARMA_CONFIG) $*
# Run all test targets
test:
@make lint
@make unit
# Ignore directory structure
.PHONY: lint unit test

View file

@ -2,9 +2,18 @@
"name": "scratch-html5",
"description": "HTML 5 based Scratch project player",
"repository": "https://github.com/LLK/scratch-html5",
"scripts": {
"postinstall": "curl http://code.jquery.com/jquery-1.11.0.min.js > ./test/lib/jquery-1.11.0.min.js",
"test": "make test"
},
"engines": {
"node": ">=0.10"
},
"dependencies": {},
"devDependencies": {
"jasmine-jquery": "~1.3.3",
"jscs": "~1.3.0",
"karma": "~0.10",
"jasmine-jquery" : "1.3.3",
"karma-html2js-preprocessor": "~0.1.0",
"underscore": "~1.6.0"
}

View file

@ -1,9 +0,0 @@
#!/bin/bash
BASE_DIR=`dirname $0`
echo ""
echo "Starting Karma Server (http://karma-runner.github.io)"
echo "-------------------------------------------------------------------"
$BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*

View file

@ -1,6 +1,6 @@
module.exports = function(config){
config.set({
basePath : '../',
basePath : '../../',
files : [
'test/artifacts/**/*.js',

View file

@ -95,7 +95,6 @@ describe('SensingPrims', function() {
targetSpriteMock = targetMock();
askBlock = {'args': 'what to ask'};
interp = interpreterMock({'targetSprite': targetSpriteMock}, {'arg': askBlock});
});
it('should call the showBubble method on the targetedSprite', function() {
@ -107,6 +106,4 @@ describe('SensingPrims', function() {
expect(interp.activeThread.paused).toBe(true);
});
});
});