mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-08-06 19:38:58 -04:00
Use Playwright instead of Puppeteer
This commit is contained in:
parent
5566a600ba
commit
a41bcafac7
4 changed files with 7 additions and 37 deletions
|
@ -36,7 +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-core": "^2.0.0",
|
"playwright-chromium": "^1.0.1",
|
||||||
"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,24 +0,0 @@
|
||||||
const packageJson = require('puppeteer-core/package.json');
|
|
||||||
const puppeteer = require('puppeteer-core');
|
|
||||||
|
|
||||||
const fetcher = puppeteer.createBrowserFetcher();
|
|
||||||
const revision = packageJson.puppeteer.chromium_revision;
|
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
module.exports = async () => {
|
|
||||||
const downloadedRevisions = await fetcher.localRevisions();
|
|
||||||
if (downloadedRevisions.indexOf(revision) !== -1) {
|
|
||||||
console.log('Chromium already downloaded');
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Downloading Chromium...');
|
|
||||||
return fetcher.download(revision)
|
|
||||||
.then(() => {
|
|
||||||
console.log('Downloaded Chromium successfully');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -1,10 +1,8 @@
|
||||||
/* global vm, render, Promise */
|
/* global vm, render, Promise */
|
||||||
const puppeteer = require('puppeteer-core');
|
const {chromium} = require('playwright-chromium');
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const downloadChromium = require('../helper/download-chromium');
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -12,7 +10,7 @@ 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
|
||||||
await page.goto(`file://${indexHTML}`);
|
await page.goto(`file://${indexHTML}`);
|
||||||
const fileInput = await page.$('#file');
|
const fileInput = await page.$('#file');
|
||||||
await fileInput.uploadFile(testDir(file));
|
await fileInput.setInputFiles(testDir(file));
|
||||||
|
|
||||||
await page.evaluate(() =>
|
await page.evaluate(() =>
|
||||||
// `loadFile` is defined on the page itself.
|
// `loadFile` is defined on the page itself.
|
||||||
|
@ -24,8 +22,7 @@ const runFile = async (file, action, page, script) => {
|
||||||
|
|
||||||
// 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 () => {
|
||||||
await downloadChromium();
|
const browser = await chromium.launch();
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
const testOperation = async function (name, action, expect) {
|
const testOperation = async function (name, action, expect) {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
/* global vm, Promise */
|
/* global vm, Promise */
|
||||||
const puppeteer = require('puppeteer-core');
|
const {chromium} = require('playwright-chromium');
|
||||||
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 downloadChromium = require('../helper/download-chromium');
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -13,7 +11,7 @@ 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
|
||||||
await page.goto(`file://${indexHTML}`);
|
await page.goto(`file://${indexHTML}`);
|
||||||
const fileInput = await page.$('#file');
|
const fileInput = await page.$('#file');
|
||||||
await fileInput.uploadFile(testDir(file));
|
await fileInput.setInputFiles(testDir(file));
|
||||||
await page.evaluate(() =>
|
await page.evaluate(() =>
|
||||||
// `loadFile` is defined on the page itself.
|
// `loadFile` is defined on the page itself.
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
|
@ -107,8 +105,7 @@ const testFile = (file, page) => 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 () => {
|
||||||
await downloadChromium();
|
const browser = await chromium.launch();
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
const files = fs.readdirSync(testDir())
|
const files = fs.readdirSync(testDir())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue