Skip to content

Commit

Permalink
fix: fix source map support resolve in node runner
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Feb 10, 2025
1 parent 32da926 commit bad569d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/node/runner.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -138,7 +141,7 @@ export class NodeRunner {
this.dir,
'node',
'-r',
'source-map-support/register',
sourceMapRegisterPath,
path.join(this.dir, outName),
],
{
Expand All @@ -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',
Expand All @@ -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',
}
Expand All @@ -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',
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/utils.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions src/test-runners.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down

0 comments on commit bad569d

Please sign in to comment.