mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-04 01:24:58 -04:00
Merge pull request #1741 from ktbee/load-video-state
Set video state after project load and after adding extension through UI
This commit is contained in:
commit
9d3d53537d
20 changed files with 91 additions and 25 deletions
test
fixtures/load-extensions
README.md
confirm-load
ev3-simple-project.sb3microbit-simple-project.sb3music-simple-project.sb2music-simple-project.sb3pen-dolphin-3d.sb2pen-dolphin-3d.sb3pen-simple-project.sb2pen-simple-project.sb3text2speech-simple-project.sb3videoSensing-simple-project.sb2videoSensing-simple-project.sb3wedo2-simple-project.sb2wedo2-simple-project.sb3
video-state
integration
11
test/fixtures/load-extensions/README.md
vendored
11
test/fixtures/load-extensions/README.md
vendored
|
@ -1,12 +1,12 @@
|
|||
Tests in this folder are run in scratch by integration/load-extensions.js to determine whether an extension can load properly. The test projects in this folder are examples of non-core extensions usage. Read integration/load-extensions.js for more.
|
||||
Tests in this folder are run in scratch by integration/load-extensions.js to determine whether an extension can load properly. The test projects in this folder are examples of non-core extensions usage. Read `integration/load-extensions.js` for more.
|
||||
|
||||
### Adding new extensions
|
||||
|
||||
When extending Scratch with non-core extensions, save an example project to this directory with the naming convention:
|
||||
When extending Scratch with non-core extensions, save an example project to this the appropiate subdirectory based on which test in `load-extensions.js` will be using that test file. The file should use the following naming convention:
|
||||
|
||||
`[extensionID]-rest-of-file-name.[file type sb3 or sb2]`
|
||||
|
||||
The load-extensions.js test will automatically test this new project file since it gets a list of all files in this directory for testing and extracts the extension id from the first section of the file same separated by a dash.
|
||||
The load-extensions.js test will automatically test this new project file since it gets a list of all files in its repsective subdirectories for testing and extracts the extension id from the first section of the file same separated by a dash.
|
||||
|
||||
Each of the `[extensionID]-simple-project` test files have been made as the simplest possible cases for loading the extension. This means that only one block has been added to the project and that block is from the relevant extension.
|
||||
|
||||
|
@ -15,7 +15,4 @@ Each of the `[extensionID]-simple-project` test files have been made as the simp
|
|||
Sometimes we need to test more complex projects to catch cases and contexts where an extension should load and doesn't. We can save those project files using the convention [extensionID]-project-name. For example, the Dolphins 3D project (#115870836) had a pen extension that wouldn't load, whereas `pen-simple-project.sb2` and `pen-simple-project.sb3` did pass these tests. For this reason, `pen-dolphin-3d.sb2` and `pen-dolphin-3d.sb3` are now part of the test examples.
|
||||
|
||||
### // TO DO
|
||||
The translation and videoSensing extensions don't have test projects added for them yet since they need a little more infrastructure stubbed out in the test.
|
||||
|
||||
|
||||
|
||||
The translation extension doesn't have test projects added for them yet since they need a little more infrastructure stubbed out in the test.
|
||||
|
|
BIN
test/fixtures/load-extensions/confirm-load/videoSensing-simple-project.sb2
vendored
Normal file
BIN
test/fixtures/load-extensions/confirm-load/videoSensing-simple-project.sb2
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/load-extensions/confirm-load/videoSensing-simple-project.sb3
vendored
Normal file
BIN
test/fixtures/load-extensions/confirm-load/videoSensing-simple-project.sb3
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/load-extensions/video-state/videoState-off.sb2
vendored
Normal file
BIN
test/fixtures/load-extensions/video-state/videoState-off.sb2
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/load-extensions/video-state/videoState-on-transparency-0.sb2
vendored
Normal file
BIN
test/fixtures/load-extensions/video-state/videoState-on-transparency-0.sb2
vendored
Normal file
Binary file not shown.
|
@ -1,21 +1,23 @@
|
|||
const path = require('path');
|
||||
const test = require('tap').test;
|
||||
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 fileList = fs.readdirSync('./test/fixtures/load-extensions/');
|
||||
const testFiles = fileList.filter(file => path.extname(file) === '.sb2' || path.extname(file) === '.sb3');
|
||||
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/${file}`);
|
||||
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 projects', extTest => {
|
||||
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));
|
||||
|
@ -25,3 +27,42 @@ test('Load external extensions', async t => {
|
|||
}
|
||||
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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue