Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(testrunner): support sourcemaps (#3459)
Joel Einbinderf45791dd8bf8
diff --git a/package.json b/package.jsonindex 02dbfa0718..659342f8de 100644--- a/package.json+++ b/package.json@@ -78,6 +78,7 @@"pirates": "^4.0.1","pixelmatch": "^4.0.2","socksv5": "0.0.6",+ "source-map-support": "^0.5.19","text-diff": "^1.0.1","ts-loader": "^6.1.2","typescript": "^3.8.3",diff --git a/test/runner/transform.js b/test/runner/transform.jsindex c9d7cab257..cf0bcdceef 100644--- a/test/runner/transform.js+++ b/test/runner/transform.js@@ -19,8 +19,28 @@ const path = require('path');const fs = require('fs');const pirates = require('pirates');const babel = require('@babel/core');-const version = 0;+const sourceMapSupport = require('source-map-support');++const version = 1;const cacheDir = path.join(os.tmpdir(), 'playwright-transform-cache');+/** @type {Map<string, string>} */+const sourceMaps = new Map();++sourceMapSupport.install({+ environment: 'node',+ handleUncaughtExceptions: false,+ retrieveSourceMap(source) {+ if (!sourceMaps.has(source))+ return null;+ const sourceMapPath = sourceMaps.get(source);+ if (!fs.existsSync(sourceMapPath))+ return null;+ return {+ map: JSON.parse(fs.readFileSync(sourceMapPath, 'utf-8')),+ url: source+ };+ }+});/*** @param {string} content@@ -38,6 +58,8 @@ function installTransform() {return pirates.addHook((code, filename) => {const cachePath = calculateCachePath(code, filename);const codePath = cachePath + '.js';+ const sourceMapPath = cachePath + '.map';+ sourceMaps.set(filename, sourceMapPath);if (fs.existsSync(codePath))return fs.readFileSync(codePath, 'utf8');@@ -45,12 +67,14 @@ function installTransform() {presets: [['@babel/preset-env', {targets: {node: 'current'}}],'@babel/preset-typescript'],+ sourceMaps: true,});if (result.code) {fs.mkdirSync(path.dirname(cachePath), {recursive: true});+ if (result.map)+ fs.writeFileSync(sourceMapPath, JSON.stringify(result.map), 'utf8');fs.writeFileSync(codePath, result.code, 'utf8');}- // TODO(einbinder) sourcemapsreturn result.code;}, {exts: ['.ts']