Skip to content

Commit 55a94c7

Browse files
committed
test: fix path
1 parent 3f70202 commit 55a94c7

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

__tests__/cjs/import.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os from 'os'
22
import path from 'path'
3+
import normalizePath from 'normalize-path'
34
import {
45
importFromString,
56
createImportFromString,
@@ -144,7 +145,7 @@ export default code
144145
})
145146
} catch (err) {
146147
if (err instanceof Error) {
147-
expect(err.stack).toMatch(new RegExp(`at \\S+${relativeFilename}:\\d+:\\d+$`, 'm'))
148+
expect(err.stack).toMatch(new RegExp(`at \\S*${relativeFilename}:\\d+:\\d+$`, 'm'))
148149
} else {
149150
throw err
150151
}
@@ -153,7 +154,8 @@ export default code
153154

154155
it('should use absolute filename in error stack trace', async () => {
155156
expect.assertions(1)
156-
const filename = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
157+
const filenamePath = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
158+
const filename = normalizePath(filenamePath)
157159
try {
158160
await importFromStringFn('throw new Error("boom")', {
159161
filename,

__tests__/cjs/require.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os from 'os'
22
import path from 'path'
3+
import normalizePath from 'normalize-path'
34
import { requireFromString, createRequireFromString } from '../../src/index'
45

56
it('should work with `module.exports`', () => {
@@ -100,7 +101,7 @@ it('should use relative filename in error stack trace', () => {
100101
})
101102
} catch (err) {
102103
if (err instanceof Error) {
103-
expect(err.stack).toMatch(new RegExp(`at \\S+${relativeFilename}:\\d+:\\d+$`, 'm'))
104+
expect(err.stack).toMatch(new RegExp(`at \\S*${relativeFilename}:\\d+:\\d+$`, 'm'))
104105
} else {
105106
throw err
106107
}
@@ -109,7 +110,8 @@ it('should use relative filename in error stack trace', () => {
109110

110111
it('should use absolute filename in error stack trace', () => {
111112
expect.assertions(1)
112-
const filename = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
113+
const filenamePath = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
114+
const filename = normalizePath(filenamePath)
113115
try {
114116
requireFromString('throw new Error("boom")', {
115117
filename,

__tests__/esm/require.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os from 'os'
22
import path from 'path'
3+
import normalizePath from 'normalize-path'
34
import { fileURLToPath } from 'url'
45
import { requireFromString } from '../../src/index'
56

@@ -94,7 +95,7 @@ it('should use relative filename in error stack trace', () => {
9495
})
9596
} catch (err) {
9697
if (err instanceof Error) {
97-
expect(err.stack).toMatch(new RegExp(`at \\S+${relativeFilename}:\\d+:\\d+$`, 'm'))
98+
expect(err.stack).toMatch(new RegExp(`at \\S*${relativeFilename}:\\d+:\\d+$`, 'm'))
9899
} else {
99100
throw err
100101
}
@@ -103,7 +104,8 @@ it('should use relative filename in error stack trace', () => {
103104

104105
it('should use absolute filename in error stack trace', () => {
105106
expect.assertions(1)
106-
const filename = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
107+
const filenamePath = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
108+
const filename = normalizePath(filenamePath)
107109
try {
108110
requireFromString('throw new Error("boom")', {
109111
filename,

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
"devDependencies": {
5353
"@types/jest": "28.1.8",
5454
"@types/node": "18.7.16",
55+
"@types/normalize-path": "3.0.0",
5556
"cross-env": "7.0.3",
5657
"jest": "28.1.3",
58+
"normalize-path": "3.0.0",
5759
"rollup": "2.79.0",
5860
"rollup-plugin-dts": "4.2.2",
5961
"rollup-plugin-esbuild-transform": "1.5.0",

0 commit comments

Comments
 (0)