diff --git a/src/node/runner.js b/src/node/runner.js index 731d4795..7f898ecc 100644 --- a/src/node/runner.js +++ b/src/node/runner.js @@ -1,18 +1,20 @@ import { mkdirSync } from 'fs' -import path from 'path' +import { createRequire } from 'module' import { fileURLToPath } from 'node:url' +import path from 'path' +import { watch } from 'chokidar' +import { execa } from 'execa' import { asyncExitHook, gracefulExit } from 'exit-hook' import mergeOptions from 'merge-options' import { nanoid } from 'nanoid' -import { watch } from 'chokidar' -import { execa } from 'execa' import { premove } from 'premove' -import { createPolka, findTests, log } from '../utils/index.js' import * as DefaultRunners from '../test-runners.js' +import { createPolka, findTests, log } from '../utils/index.js' import { build } from './utils.js' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const merge = mergeOptions.bind({ ignoreUndefined: true }) +const require = createRequire(import.meta.url) /** * @typedef {import('playwright-core').Page} Page @@ -122,6 +124,7 @@ export class NodeRunner { await this.#setupServer() await this.options.beforeTests(this.env) + const sourceMapRegisterPath = require.resolve('source-map-support/register') try { const { outName } = await this.runTests() @@ -138,7 +141,7 @@ export class NodeRunner { this.dir, 'node', '-r', - 'source-map-support/register', + sourceMapRegisterPath, path.join(this.dir, outName), ], { @@ -148,7 +151,7 @@ export class NodeRunner { ) : execa( 'node', - ['-r', 'source-map-support/register', path.join(this.dir, outName)], + ['-r', sourceMapRegisterPath, path.join(this.dir, outName)], { preferLocal: true, stdio: 'inherit', @@ -167,12 +170,13 @@ export class NodeRunner { await this.#setupServer() await this.options.beforeTests(this.env) + const sourceMapRegisterPath = require.resolve('source-map-support/register') const { files, outName } = await this.runTests() try { await execa( 'node', - ['-r', 'source-map-support/register', path.join(this.dir, outName)], + ['-r', sourceMapRegisterPath, path.join(this.dir, outName)], { stdio: 'inherit', } @@ -190,7 +194,7 @@ export class NodeRunner { const { files, outName } = await this.runTests() await execa( 'node', - ['-r', 'source-map-support/register', path.join(this.dir, outName)], + ['-r', sourceMapRegisterPath, path.join(this.dir, outName)], { stdio: 'inherit', } diff --git a/src/node/utils.js b/src/node/utils.js index ffb8cb02..1e40657e 100644 --- a/src/node/utils.js +++ b/src/node/utils.js @@ -1,7 +1,7 @@ import path from 'path' import esbuild from 'esbuild' -import mergeOptions from 'merge-options' import { wasmLoader } from 'esbuild-plugin-wasm' +import mergeOptions from 'merge-options' const merge = mergeOptions.bind({ ignoreUndefined: true, @@ -22,7 +22,7 @@ const merge = mergeOptions.bind({ * @param {string} tmpl */ export async function build(runner, config = {}, tmpl = '') { - const outName = `node-out.js` + const outName = 'node-out.js' const outPath = path.join(runner.dir, outName) const files = new Set() diff --git a/src/test-runners.js b/src/test-runners.js index e5742afa..82c4776e 100644 --- a/src/test-runners.js +++ b/src/test-runners.js @@ -1,5 +1,5 @@ -import path from 'path' import { createRequire } from 'module' +import path from 'path' import { fileURLToPath } from 'url' const require = createRequire(import.meta.url) @@ -19,7 +19,7 @@ export const mocha = { compileRuntime(options, paths) { return ` import mocha from 'mocha/mocha.js' -${options.mode === 'node' ? `globalThis.location={}` : ``} +${options.mode === 'node' ? 'globalThis.location={}' : ''} const options = JSON.parse(process.env.PW_OPTIONS) const { allowUncaught, bail, reporter, timeout, color, ui, grep } = options.testRunner.options