Improve integration test coverage

This commit is contained in:
Andrew Sliwinski 2017-01-05 16:58:31 -05:00
parent 5daaaa4438
commit 6ee8959100
15 changed files with 202 additions and 6 deletions

BIN
test/fixtures/complex.sb2 vendored Normal file

Binary file not shown.

BIN
test/fixtures/data.sb2 vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
test/fixtures/procedure.sb2 vendored Normal file

Binary file not shown.

BIN
test/fixtures/sensing.sb2 vendored Normal file

Binary file not shown.

38
test/fixtures/sprite.json vendored Executable file
View file

@ -0,0 +1,38 @@
{
"objName": "Sprite1",
"sounds": [{
"soundName": "meow",
"soundID": 0,
"md5": "83c36d806dc92327b9e7049a565c6bff.wav",
"sampleCount": 18688,
"rate": 22050,
"format": ""
}],
"costumes": [{
"costumeName": "costume1",
"baseLayerID": 0,
"baseLayerMD5": "f9a1c175dbe2e5dee472858dd30d16bb.svg",
"bitmapResolution": 1,
"rotationCenterX": 47,
"rotationCenterY": 55
},
{
"costumeName": "costume2",
"baseLayerID": 1,
"baseLayerMD5": "6e8bd9ae68fdb02b7e1e3df656a75635.svg",
"bitmapResolution": 1,
"rotationCenterX": 47,
"rotationCenterY": 55
}],
"currentCostumeIndex": 0,
"scratchX": 0,
"scratchY": 0,
"scale": 1,
"direction": 90,
"rotationStyle": "normal",
"isDraggable": false,
"indexInLibrary": 100000,
"visible": true,
"spriteInfo": {
}
}

View file

@ -0,0 +1,88 @@
var fs = require('fs');
var path = require('path');
var test = require('tap').test;
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
var projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
var project = extract(projectUri);
var spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
var sprite = fs.readFileSync(spriteUri, 'utf8');
test('complex', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var 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) {
if (targets[i].isStage === true) continue;
if (targets[i].name === 'test') continue;
vm.setEditingTarget(targets[i].id);
vm.renameSprite(targets[i].id, 'test');
vm.postSpriteInfo({
x: 0,
y: 10,
direction: 90,
rotationStyle: 'all around',
visible: true
});
vm.addCostume({
costumeName: 'costume1',
baseLayerID: 0,
baseLayerMD5: 'f9a1c175dbe2e5dee472858dd30d16bb.svg',
bitmapResolution: 1,
rotationCenterX: 47,
rotationCenterY: 55
});
}
});
// Start VM, load project, and run
t.doesNotThrow(function () {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project);
vm.greenFlag();
// Post IO data
vm.postIOData('mouse', {
isDown: true,
x: 0,
y: 10,
canvasWidth: 100,
canvasHeight: 100
});
// Add sprite
vm.addSprite2(sprite);
// Add backdrop
vm.addBackdrop({
costumeName: 'baseball-field',
baseLayerID: 26,
baseLayerMD5: '6b3d87ba2a7f89be703163b6c1d4c964.png',
bitmapResolution: 2,
rotationCenterX: 480,
rotationCenterY: 360
});
});
// After two seconds, get playground data and stop
setTimeout(function () {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
});

View file

@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/control.sb2');
var project = extract(uri);
test('control project', function (t) {
test('control', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit

View file

@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/data.sb2');
var project = extract(uri);
test('data project', function (t) {
test('data', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit

View file

@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/event.sb2');
var project = extract(uri);
test('event project', function (t) {
test('event', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit

View file

@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/looks.sb2');
var project = extract(uri);
test('looks project', function (t) {
test('looks', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit

View file

@ -6,13 +6,13 @@ var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/motion.sb2');
var project = extract(uri);
test('motion project', function (t) {
test('motion', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var threads = JSON.parse(e.threads);
t.ok(threads.length === 0);
t.ok(threads.length > 0);
t.end();
process.nextTick(process.exit);
});

View file

@ -0,0 +1,35 @@
var path = require('path');
var test = require('tap').test;
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/procedure.sb2');
var project = extract(uri);
test('procedure', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var 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 () {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project);
vm.greenFlag();
});
// After two seconds, get playground data and stop
setTimeout(function () {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
});

View file

@ -0,0 +1,35 @@
var path = require('path');
var test = require('tap').test;
var extract = require('../fixtures/extract');
var VirtualMachine = require('../../src/index');
var uri = path.resolve(__dirname, '../fixtures/sensing.sb2');
var project = extract(uri);
test('sensing', function (t) {
var vm = new VirtualMachine();
// Evaluate playground data and exit
vm.on('playgroundData', function (e) {
var 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 () {
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
vm.loadProject(project);
vm.greenFlag();
});
// After two seconds, get playground data and stop
setTimeout(function () {
vm.getPlaygroundData();
vm.stopAll();
}, 2000);
});