Spaces:
Running
Running
File size: 2,454 Bytes
30c32c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
const path = require('path');
const tap = require('tap');
const {test} = tap;
const fs = require('fs');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const VirtualMachine = require('../../src/index');
tap.tearDown(() => process.nextTick(process.exit));
test('Load external extensions', async t => {
const vm = new VirtualMachine();
const testFiles = fs.readdirSync('./test/fixtures/load-extensions/confirm-load/');
// Test each example extension file
for (const file of testFiles) {
const ext = file.split('-')[0];
const uri = path.resolve(__dirname, `../fixtures/load-extensions/confirm-load/${file}`);
const project = readFileToBuffer(uri);
await t.test('Confirm expected extension is installed in example sb2 and sb3 projects', extTest => {
vm.loadProject(project)
.then(() => {
extTest.ok(vm.extensionManager.isExtensionLoaded(ext));
extTest.end();
});
});
}
t.end();
});
test('Load video sensing extension and video properties', async t => {
const vm = new VirtualMachine();
// An array of test projects and their expected video state values
const testProjects = [
{
file: 'videoState-off.sb2',
videoState: 'off',
videoTransparency: 50,
mirror: undefined
},
{
file: 'videoState-on-transparency-0.sb2',
videoState: 'on',
videoTransparency: 0,
mirror: true
}];
for (const project of testProjects) {
const uri = path.resolve(__dirname, `../fixtures/load-extensions/video-state/${project.file}`);
const projectData = readFileToBuffer(uri);
await vm.loadProject(projectData);
const stage = vm.runtime.getTargetForStage();
t.ok(vm.extensionManager.isExtensionLoaded('videoSensing'));
// Check that the stage target has the video state values we expect
// based on the test project files, then check that the video io device
// has the expected state as well
t.equal(stage.videoState, project.videoState);
t.equal(vm.runtime.ioDevices.video.mirror, project.mirror);
t.equal(stage.videoTransparency, project.videoTransparency);
t.equal(vm.runtime.ioDevices.video._ghost, project.videoTransparency);
}
t.end();
});
|