switch from puppeteer to playwright

This commit is contained in:
Rene
2021-01-25 00:47:15 +01:00
parent 4eecc6fa7a
commit be25d8a712
42 changed files with 1054 additions and 949 deletions
+32
View File
@@ -0,0 +1,32 @@
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment').default;
const { setupRollupTest, cleanupRollupTest } = require('./jest-browser.rollup.js');
const buildTests = [];
class BrowserRollupEnvironment extends PlaywrightEnvironment {
constructor(envConfig, envContext) {
super(envConfig, envContext);
this.watch = (envConfig.displayName.name || '').includes('-dev');
this.ctx = envContext;
this.cfg = envConfig;
}
async setup() {
const { testPath } = this.ctx;
if (!buildTests.includes(testPath)) {
await cleanupRollupTest(testPath, this.cfg.cache);
await setupRollupTest(this.cfg.rootDir, this.ctx.testPath, this.cfg.cache && this.cfg.cacheDirectory, this.watch);
buildTests.push(testPath);
}
await super.setup();
}
async teardown() {
await super.teardown();
}
}
module.exports = BrowserRollupEnvironment;
@@ -8,10 +8,10 @@ const rollupPluginHtml = require('@rollup/plugin-html');
const rollupPluginStyles = require('rollup-plugin-styles');
const rollupPluginServe = require('rollup-plugin-serve');
const rollupPluginLivereload = require('rollup-plugin-livereload');
const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
const deploymentConfig = require('./jest-browser.rollup.config.js');
const rollupConfigName = 'rollup.config.js';
const cacheFilePrefix = 'jest-puppeteer-overlayscrollbars-cache-';
const cacheFilePrefix = 'jest-browser-overlayscrollbars-cache-';
const cacheEncoding = 'utf8';
const cacheHash = 'md5';
@@ -194,7 +194,7 @@ const setupRollupTest = async (rootDir, testPath, cacheDir, watch) => {
rollupPluginStyles(),
...defaultConfig.pipeline,
rollupPluginHtml({
title: `Jest-Puppeteer: ${testName}`,
title: `Jest-Browser: ${testName}`,
fileName: deploymentConfig.html.output,
template: genHtmlTemplateFunc(getHtmlFileContent),
meta: [{ charset: 'utf-8' }, { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }],
@@ -327,9 +327,9 @@ const setupRollupTest = async (rootDir, testPath, cacheDir, watch) => {
}
};
const cleanupRollupTest = (testPath, cache) => {
const cleanupRollupTest = async (testPath, cache) => {
if (!cache) {
del(path.resolve(path.dirname(testPath), deploymentConfig.build));
await del(path.resolve(path.dirname(testPath), deploymentConfig.build));
}
};
+2
View File
@@ -0,0 +1,2 @@
jest.setTimeout(60000);
context.setDefaultTimeout(60000);
-36
View File
@@ -1,36 +0,0 @@
const PuppeteerEnvironment = require('jest-environment-puppeteer');
// const pti = require('puppeteer-to-istanbul');
const { setupRollupTest, cleanupRollupTest } = require('./jest-puppeteer.rollup.js');
class PuppeteerRollupEnvironment extends PuppeteerEnvironment {
constructor(envConfig, envContext) {
super(envConfig, envContext);
this.watch = envConfig.displayName.name === 'puppeteer-dev';
this.ctx = envContext;
this.cfg = envConfig;
}
async setup() {
// setup
await setupRollupTest(this.cfg.rootDir, this.ctx.testPath, this.cfg.cache && this.cfg.cacheDirectory, this.watch);
await super.setup();
// coverage
// const { page } = this.global;
// await Promise.all([page.coverage.startCSSCoverage(), page.coverage.startJSCoverage()]);
}
async teardown() {
// coverage
// const { page } = this.global;
// const [jsCoverage, cssCoverage] = await Promise.all([page.coverage.stopJSCoverage(), page.coverage.stopCSSCoverage()]);
// pti.write([...jsCoverage, ...cssCoverage], { includeHostname: true, storagePath: './.pptr' });
// cleanup
cleanupRollupTest(this.ctx.testPath, this.cfg.cache);
await super.teardown();
}
}
module.exports = PuppeteerRollupEnvironment;
-4
View File
@@ -1,4 +0,0 @@
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;
jest.setTimeout(60000);
setDefaultOptions({ timeout: 60000 });
+1 -1
View File
@@ -1,5 +1,5 @@
const express = require('express');
const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
const deploymentConfig = require('./jest-browser.rollup.config.js');
const app = express();
+1 -1
View File
@@ -1,5 +1,5 @@
const path = require('path');
const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
const deploymentConfig = require('./jest-browser.rollup.config.js');
module.exports = {
process: (src, filePath) => {