Skip to content

Commit bad569d

Browse files
committed
fix: fix source map support resolve in node runner
1 parent 32da926 commit bad569d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/node/runner.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { mkdirSync } from 'fs'
2-
import path from 'path'
2+
import { createRequire } from 'module'
33
import { fileURLToPath } from 'node:url'
4+
import path from 'path'
5+
import { watch } from 'chokidar'
6+
import { execa } from 'execa'
47
import { asyncExitHook, gracefulExit } from 'exit-hook'
58
import mergeOptions from 'merge-options'
69
import { nanoid } from 'nanoid'
7-
import { watch } from 'chokidar'
8-
import { execa } from 'execa'
910
import { premove } from 'premove'
10-
import { createPolka, findTests, log } from '../utils/index.js'
1111
import * as DefaultRunners from '../test-runners.js'
12+
import { createPolka, findTests, log } from '../utils/index.js'
1213
import { build } from './utils.js'
1314

1415
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1516
const merge = mergeOptions.bind({ ignoreUndefined: true })
17+
const require = createRequire(import.meta.url)
1618

1719
/**
1820
* @typedef {import('playwright-core').Page} Page
@@ -122,6 +124,7 @@ export class NodeRunner {
122124

123125
await this.#setupServer()
124126
await this.options.beforeTests(this.env)
127+
const sourceMapRegisterPath = require.resolve('source-map-support/register')
125128

126129
try {
127130
const { outName } = await this.runTests()
@@ -138,7 +141,7 @@ export class NodeRunner {
138141
this.dir,
139142
'node',
140143
'-r',
141-
'source-map-support/register',
144+
sourceMapRegisterPath,
142145
path.join(this.dir, outName),
143146
],
144147
{
@@ -148,7 +151,7 @@ export class NodeRunner {
148151
)
149152
: execa(
150153
'node',
151-
['-r', 'source-map-support/register', path.join(this.dir, outName)],
154+
['-r', sourceMapRegisterPath, path.join(this.dir, outName)],
152155
{
153156
preferLocal: true,
154157
stdio: 'inherit',
@@ -167,12 +170,13 @@ export class NodeRunner {
167170

168171
await this.#setupServer()
169172
await this.options.beforeTests(this.env)
173+
const sourceMapRegisterPath = require.resolve('source-map-support/register')
170174

171175
const { files, outName } = await this.runTests()
172176
try {
173177
await execa(
174178
'node',
175-
['-r', 'source-map-support/register', path.join(this.dir, outName)],
179+
['-r', sourceMapRegisterPath, path.join(this.dir, outName)],
176180
{
177181
stdio: 'inherit',
178182
}
@@ -190,7 +194,7 @@ export class NodeRunner {
190194
const { files, outName } = await this.runTests()
191195
await execa(
192196
'node',
193-
['-r', 'source-map-support/register', path.join(this.dir, outName)],
197+
['-r', sourceMapRegisterPath, path.join(this.dir, outName)],
194198
{
195199
stdio: 'inherit',
196200
}

src/node/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22
import esbuild from 'esbuild'
3-
import mergeOptions from 'merge-options'
43
import { wasmLoader } from 'esbuild-plugin-wasm'
4+
import mergeOptions from 'merge-options'
55

66
const merge = mergeOptions.bind({
77
ignoreUndefined: true,
@@ -22,7 +22,7 @@ const merge = mergeOptions.bind({
2222
* @param {string} tmpl
2323
*/
2424
export async function build(runner, config = {}, tmpl = '') {
25-
const outName = `node-out.js`
25+
const outName = 'node-out.js'
2626
const outPath = path.join(runner.dir, outName)
2727
const files = new Set()
2828

src/test-runners.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path'
21
import { createRequire } from 'module'
2+
import path from 'path'
33
import { fileURLToPath } from 'url'
44

55
const require = createRequire(import.meta.url)
@@ -19,7 +19,7 @@ export const mocha = {
1919
compileRuntime(options, paths) {
2020
return `
2121
import mocha from 'mocha/mocha.js'
22-
${options.mode === 'node' ? `globalThis.location={}` : ``}
22+
${options.mode === 'node' ? 'globalThis.location={}' : ''}
2323
2424
const options = JSON.parse(process.env.PW_OPTIONS)
2525
const { allowUncaught, bail, reporter, timeout, color, ui, grep } = options.testRunner.options

0 commit comments

Comments
 (0)