Replace Chromeless with Puppeteer
This commit is contained in:
parent
8139afdb52
commit
3d02a6c769
@ -29,7 +29,6 @@
|
|||||||
"babel-loader": "^7.1.4",
|
"babel-loader": "^7.1.4",
|
||||||
"babel-polyfill": "^6.22.0",
|
"babel-polyfill": "^6.22.0",
|
||||||
"babel-preset-env": "^1.6.1",
|
"babel-preset-env": "^1.6.1",
|
||||||
"chromeless": "^1.5.1",
|
|
||||||
"copy-webpack-plugin": "^4.5.1",
|
"copy-webpack-plugin": "^4.5.1",
|
||||||
"docdash": "^0.4.0",
|
"docdash": "^0.4.0",
|
||||||
"eslint": "^4.6.1",
|
"eslint": "^4.6.1",
|
||||||
@ -37,6 +36,7 @@
|
|||||||
"gh-pages": "^1.0.0",
|
"gh-pages": "^1.0.0",
|
||||||
"jsdoc": "^3.5.5",
|
"jsdoc": "^3.5.5",
|
||||||
"json": "^9.0.4",
|
"json": "^9.0.4",
|
||||||
|
"puppeteer": "^2.0.0",
|
||||||
"scratch-vm": "0.2.0-prerelease.20191227164934",
|
"scratch-vm": "0.2.0-prerelease.20191227164934",
|
||||||
"tap": "^11.0.0",
|
"tap": "^11.0.0",
|
||||||
"travis-after-all": "^1.4.4",
|
"travis-after-all": "^1.4.4",
|
||||||
|
|||||||
@ -1,29 +1,31 @@
|
|||||||
/* global vm, render, Promise */
|
/* global vm, render, Promise */
|
||||||
const {Chromeless} = require('chromeless');
|
const puppeteer = require('puppeteer');
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const chromeless = new Chromeless();
|
|
||||||
|
|
||||||
const indexHTML = path.resolve(__dirname, 'index.html');
|
const indexHTML = path.resolve(__dirname, 'index.html');
|
||||||
const testDir = (...args) => path.resolve(__dirname, 'pick-tests', ...args);
|
const testDir = (...args) => path.resolve(__dirname, 'pick-tests', ...args);
|
||||||
|
|
||||||
const runFile = (file, action, script) =>
|
const runFile = async (file, action, page, script) => {
|
||||||
// start each test by going to the index.html, and loading the scratch file
|
// start each test by going to the index.html, and loading the scratch file
|
||||||
chromeless.goto(`file://${indexHTML}`)
|
await page.goto(`file://${indexHTML}`);
|
||||||
.setFileInput('#file', testDir(file))
|
const fileInput = await page.$('#file');
|
||||||
// the index.html handler for file input will add a #loaded element when it
|
await fileInput.uploadFile(testDir(file));
|
||||||
// finishes.
|
// the index.html handler for file input will add a #loaded element when it
|
||||||
.wait('#loaded')
|
// finishes.
|
||||||
.evaluate(`function () {return (${script})(${action});}`)
|
await page.waitForSelector('#loaded');
|
||||||
;
|
return page.evaluate(`(function () {return (${script})(${action});})()`);
|
||||||
|
};
|
||||||
|
|
||||||
// immediately invoked async function to let us wait for each test to finish before starting the next.
|
// immediately invoked async function to let us wait for each test to finish before starting the next.
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const browser = await puppeteer.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
const testOperation = async function (name, action, expect) {
|
const testOperation = async function (name, action, expect) {
|
||||||
await test(name, async t => {
|
await test(name, async t => {
|
||||||
|
|
||||||
const results = await runFile('test-mouse-touch.sb2', action, boundAction => {
|
const results = await runFile('test-mouse-touch.sb2', action, page, boundAction => {
|
||||||
vm.greenFlag();
|
vm.greenFlag();
|
||||||
const sendResults = [];
|
const sendResults = [];
|
||||||
|
|
||||||
@ -97,5 +99,5 @@ const runFile = (file, action, script) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// close the browser window we used
|
// close the browser window we used
|
||||||
await chromeless.end();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -1,54 +1,54 @@
|
|||||||
/* global vm, Promise */
|
/* global vm, Promise */
|
||||||
const {Chromeless} = require('chromeless');
|
const puppeteer = require('puppeteer');
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const chromeless = new Chromeless();
|
|
||||||
|
|
||||||
const indexHTML = path.resolve(__dirname, 'index.html');
|
const indexHTML = path.resolve(__dirname, 'index.html');
|
||||||
const testDir = (...args) => path.resolve(__dirname, 'scratch-tests', ...args);
|
const testDir = (...args) => path.resolve(__dirname, 'scratch-tests', ...args);
|
||||||
|
|
||||||
const testFile = file => test(file, async t => {
|
const testFile = (file, page) => test(file, async t => {
|
||||||
// start each test by going to the index.html, and loading the scratch file
|
// start each test by going to the index.html, and loading the scratch file
|
||||||
const says = await chromeless.goto(`file://${indexHTML}`)
|
await page.goto(`file://${indexHTML}`);
|
||||||
.setFileInput('#file', testDir(file))
|
const fileInput = await page.$('#file');
|
||||||
// the index.html handler for file input will add a #loaded element when it
|
await fileInput.uploadFile(testDir(file));
|
||||||
// finishes.
|
// the index.html handler for file input will add a #loaded element when it
|
||||||
.wait('#loaded')
|
// finishes.
|
||||||
.evaluate(() => {
|
await page.waitForSelector('#loaded');
|
||||||
// This function is run INSIDE the integration chrome browser via some
|
const says = await page.evaluate(() => {
|
||||||
// injection and .toString() magic. We can return some "simple data"
|
// This function is run INSIDE the integration chrome browser via some
|
||||||
// back across as a promise, so we will just log all the says that happen
|
// injection and .toString() magic. We can return some "simple data"
|
||||||
// for parsing after.
|
// back across as a promise, so we will just log all the says that happen
|
||||||
|
// for parsing after.
|
||||||
|
|
||||||
// this becomes the `says` in the outer scope
|
// this becomes the `says` in the outer scope
|
||||||
const messages = [];
|
const messages = [];
|
||||||
const TIMEOUT = 5000;
|
const TIMEOUT = 5000;
|
||||||
|
|
||||||
vm.runtime.on('SAY', (_, __, message) => {
|
vm.runtime.on('SAY', (_, __, message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.greenFlag();
|
vm.greenFlag();
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
// waiting for all threads to complete, then we return
|
// waiting for all threads to complete, then we return
|
||||||
while (vm.runtime.threads.some(thread => vm.runtime.isActiveThread(thread))) {
|
while (vm.runtime.threads.some(thread => vm.runtime.isActiveThread(thread))) {
|
||||||
if ((Date.now() - startTime) >= TIMEOUT) {
|
if ((Date.now() - startTime) >= TIMEOUT) {
|
||||||
// if we push the message after end, the failure from tap is not very useful:
|
// if we push the message after end, the failure from tap is not very useful:
|
||||||
// "not ok test after end() was called"
|
// "not ok test after end() was called"
|
||||||
messages.unshift(`fail Threads still running after ${TIMEOUT}ms`);
|
messages.unshift(`fail Threads still running after ${TIMEOUT}ms`);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 50));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages;
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
});
|
}
|
||||||
});
|
|
||||||
|
return messages;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Map string messages to tap reporting methods. This will be used
|
// Map string messages to tap reporting methods. This will be used
|
||||||
// with events from scratch's runtime emitted on block instructions.
|
// with events from scratch's runtime emitted on block instructions.
|
||||||
@ -103,13 +103,16 @@ const testFile = file => test(file, async t => {
|
|||||||
|
|
||||||
// immediately invoked async function to let us wait for each test to finish before starting the next.
|
// immediately invoked async function to let us wait for each test to finish before starting the next.
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const browser = await puppeteer.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
const files = fs.readdirSync(testDir())
|
const files = fs.readdirSync(testDir())
|
||||||
.filter(uri => uri.endsWith('.sb2') || uri.endsWith('.sb3'));
|
.filter(uri => uri.endsWith('.sb2') || uri.endsWith('.sb3'));
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
await testFile(file);
|
await testFile(file, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the browser window we used
|
// close the browser window we used
|
||||||
await chromeless.end();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user