Tone.js/test/html/testHTML.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-08-26 23:43:28 +00:00
const puppeteer = require("puppeteer");
const { resolve } = require("path");
const fs = require("fs");
2019-01-09 03:08:00 +00:00
const { spawn } = require("child_process");
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
function runPage(name){
2018-08-26 23:43:28 +00:00
return new Promise(async (done, error) => {
2018-08-27 00:02:58 +00:00
const browser = await puppeteer.launch({ args : ["--no-sandbox"] });
2018-08-26 23:43:28 +00:00
const page = await browser.newPage();
page.on("pageerror", e => error(e));
2019-01-09 03:08:00 +00:00
await page.goto(`http://localhost:9999/examples/${name}`, { waitFor : "networkidle0" });
2018-08-26 23:43:28 +00:00
await browser.close();
done();
});
}
2019-01-09 03:08:00 +00:00
describe("TEST", () => {
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
let serverProcess = null;
before((done) => {
const serverCommand = resolve(__dirname, "../../node_modules/.bin/http-server");
serverProcess = spawn(serverCommand, ["-p", "9999"]);
//give it a second for the server to start
setTimeout(() => done(), 1000);
2018-08-26 23:43:28 +00:00
});
2019-01-09 03:08:00 +00:00
after(() => {
serverProcess.kill();
2018-08-26 23:43:28 +00:00
});
2019-01-09 03:08:00 +00:00
context("HTML Tests", () => {
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
it("can run multiple contexts at once", () => {
return runPage("../test/html/multiple_instances.html");
});
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
it("has the same transport after offline test", () => {
return runPage("../test/html/same_transport.html");
});
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
});
2018-08-26 23:43:28 +00:00
2019-01-09 03:08:00 +00:00
context("Examples", () => {
const exampleDir = resolve(__dirname, "../../examples/");
const files = fs.readdirSync(exampleDir).filter(f => f.endsWith(".html"));
files.forEach(f => {
it(`can run example ${f}`, () => {
return runPage(f);
});
2018-08-26 23:43:28 +00:00
});
});
});
2019-01-09 03:08:00 +00:00