tests: Add tests for Ruffle JS API
Add some basic scaffolding for testing the JS API. Adds a test for `RufflePlayer.load` and `RufflePlayer.metadata`.
This commit is contained in:
parent
d34b72cc47
commit
0c5951da52
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"browser": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
const { js_api_before, play_and_monitor } = require("../polyfill/utils");
|
||||||
|
const { use } = require("chai");
|
||||||
|
const chaiHtml = require("chai-html");
|
||||||
|
|
||||||
|
use(chaiHtml);
|
||||||
|
|
||||||
|
describe("RufflePlayer.load", () => {
|
||||||
|
js_api_before();
|
||||||
|
|
||||||
|
it("loads and plays a URL", () => {
|
||||||
|
const player = browser.$("<ruffle-player>");
|
||||||
|
browser.execute((player) => {
|
||||||
|
player.load("/test_assets/example.swf");
|
||||||
|
}, player);
|
||||||
|
play_and_monitor(browser, player);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,21 @@
|
||||||
|
const { js_api_before } = require("../polyfill/utils");
|
||||||
|
const { expect, use } = require("chai");
|
||||||
|
const chaiHtml = require("chai-html");
|
||||||
|
|
||||||
|
use(chaiHtml);
|
||||||
|
|
||||||
|
describe("RufflePlayer.metadata", () => {
|
||||||
|
js_api_before("/test_assets/example.swf");
|
||||||
|
|
||||||
|
it("has metadata after load", () => {
|
||||||
|
const player = browser.$("<ruffle-player>");
|
||||||
|
const metadata = browser.execute((player) => player.metadata, player);
|
||||||
|
expect(metadata).to.eql({
|
||||||
|
width: 550,
|
||||||
|
height: 400,
|
||||||
|
frameRate: 24,
|
||||||
|
numFrames: 1,
|
||||||
|
swfVersion: 15,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -112,6 +112,32 @@ function open_test(browser, absolute_dir, file_name) {
|
||||||
browser.url(`http://localhost:4567/test/polyfill/${dir_name}/${file_name}`);
|
browser.url(`http://localhost:4567/test/polyfill/${dir_name}/${file_name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Test set-up for basic JS API testing. */
|
||||||
|
function js_api_before(swf) {
|
||||||
|
let player = null;
|
||||||
|
before("Loads the test", () => {
|
||||||
|
browser.url("http://localhost:4567/test_assets/js_api.html");
|
||||||
|
|
||||||
|
inject_ruffle_and_wait(browser);
|
||||||
|
|
||||||
|
player = browser.execute(() => {
|
||||||
|
const ruffle = window.RufflePlayer.newest();
|
||||||
|
const player = ruffle.createPlayer();
|
||||||
|
const container = document.getElementById("test-container");
|
||||||
|
container.appendChild(player);
|
||||||
|
return player;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (swf) {
|
||||||
|
browser.execute((player) => {
|
||||||
|
player.load("/test_assets/example.swf");
|
||||||
|
}, player);
|
||||||
|
play_and_monitor(browser, player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
is_ruffle_loaded,
|
is_ruffle_loaded,
|
||||||
wait_for_ruffle,
|
wait_for_ruffle,
|
||||||
|
@ -120,4 +146,5 @@ module.exports = {
|
||||||
inject_ruffle_and_wait,
|
inject_ruffle_and_wait,
|
||||||
open_test,
|
open_test,
|
||||||
setup_error_handler,
|
setup_error_handler,
|
||||||
|
js_api_before,
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Ruffle JS API Test</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="test-container">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -27,7 +27,7 @@ exports.config = {
|
||||||
// NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
|
// NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
|
||||||
// directory is where your package.json resides, so `wdio` will be called from there.
|
// directory is where your package.json resides, so `wdio` will be called from there.
|
||||||
//
|
//
|
||||||
specs: ["./test/polyfill/**/test.js"],
|
specs: ["./test/polyfill/**/test.js", "./test/js_api/*.js"],
|
||||||
// Patterns to exclude.
|
// Patterns to exclude.
|
||||||
exclude: [
|
exclude: [
|
||||||
// 'path/to/excluded/files'
|
// 'path/to/excluded/files'
|
||||||
|
|
Loading…
Reference in New Issue