mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-04 09:33:57 -04:00
Improve integration test coverage
This commit is contained in:
parent
5daaaa4438
commit
6ee8959100
15 changed files with 202 additions and 6 deletions
BIN
test/fixtures/complex.sb2
vendored
Normal file
BIN
test/fixtures/complex.sb2
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/data.sb2
vendored
BIN
test/fixtures/data.sb2
vendored
Binary file not shown.
BIN
test/fixtures/looks.sb2
vendored
BIN
test/fixtures/looks.sb2
vendored
Binary file not shown.
BIN
test/fixtures/motion.sb2
vendored
BIN
test/fixtures/motion.sb2
vendored
Binary file not shown.
BIN
test/fixtures/procedure.sb2
vendored
Normal file
BIN
test/fixtures/procedure.sb2
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/sensing.sb2
vendored
Normal file
BIN
test/fixtures/sensing.sb2
vendored
Normal file
Binary file not shown.
38
test/fixtures/sprite.json
vendored
Executable file
38
test/fixtures/sprite.json
vendored
Executable 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": {
|
||||||
|
}
|
||||||
|
}
|
88
test/integration/complex.js
Normal file
88
test/integration/complex.js
Normal 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);
|
||||||
|
});
|
|
@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
|
||||||
var uri = path.resolve(__dirname, '../fixtures/control.sb2');
|
var uri = path.resolve(__dirname, '../fixtures/control.sb2');
|
||||||
var project = extract(uri);
|
var project = extract(uri);
|
||||||
|
|
||||||
test('control project', function (t) {
|
test('control', function (t) {
|
||||||
var vm = new VirtualMachine();
|
var vm = new VirtualMachine();
|
||||||
|
|
||||||
// Evaluate playground data and exit
|
// Evaluate playground data and exit
|
||||||
|
|
|
@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
|
||||||
var uri = path.resolve(__dirname, '../fixtures/data.sb2');
|
var uri = path.resolve(__dirname, '../fixtures/data.sb2');
|
||||||
var project = extract(uri);
|
var project = extract(uri);
|
||||||
|
|
||||||
test('data project', function (t) {
|
test('data', function (t) {
|
||||||
var vm = new VirtualMachine();
|
var vm = new VirtualMachine();
|
||||||
|
|
||||||
// Evaluate playground data and exit
|
// Evaluate playground data and exit
|
||||||
|
|
|
@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
|
||||||
var uri = path.resolve(__dirname, '../fixtures/event.sb2');
|
var uri = path.resolve(__dirname, '../fixtures/event.sb2');
|
||||||
var project = extract(uri);
|
var project = extract(uri);
|
||||||
|
|
||||||
test('event project', function (t) {
|
test('event', function (t) {
|
||||||
var vm = new VirtualMachine();
|
var vm = new VirtualMachine();
|
||||||
|
|
||||||
// Evaluate playground data and exit
|
// Evaluate playground data and exit
|
||||||
|
|
|
@ -6,7 +6,7 @@ var VirtualMachine = require('../../src/index');
|
||||||
var uri = path.resolve(__dirname, '../fixtures/looks.sb2');
|
var uri = path.resolve(__dirname, '../fixtures/looks.sb2');
|
||||||
var project = extract(uri);
|
var project = extract(uri);
|
||||||
|
|
||||||
test('looks project', function (t) {
|
test('looks', function (t) {
|
||||||
var vm = new VirtualMachine();
|
var vm = new VirtualMachine();
|
||||||
|
|
||||||
// Evaluate playground data and exit
|
// Evaluate playground data and exit
|
||||||
|
|
|
@ -6,13 +6,13 @@ var VirtualMachine = require('../../src/index');
|
||||||
var uri = path.resolve(__dirname, '../fixtures/motion.sb2');
|
var uri = path.resolve(__dirname, '../fixtures/motion.sb2');
|
||||||
var project = extract(uri);
|
var project = extract(uri);
|
||||||
|
|
||||||
test('motion project', function (t) {
|
test('motion', function (t) {
|
||||||
var vm = new VirtualMachine();
|
var vm = new VirtualMachine();
|
||||||
|
|
||||||
// Evaluate playground data and exit
|
// Evaluate playground data and exit
|
||||||
vm.on('playgroundData', function (e) {
|
vm.on('playgroundData', function (e) {
|
||||||
var threads = JSON.parse(e.threads);
|
var 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);
|
||||||
});
|
});
|
||||||
|
|
35
test/integration/procedure.js
Normal file
35
test/integration/procedure.js
Normal 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);
|
||||||
|
});
|
35
test/integration/sensing.js
Normal file
35
test/integration/sensing.js
Normal 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);
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue