Skip to content

Commit 7c1cb7e

Browse files
committed
test: fix path in esm
1 parent 96b9ba8 commit 7c1cb7e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

__tests__/esm/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 { fileURLToPath, pathToFileURL } from 'url'
45
import { importFromString, createImportFromString, importFromStringSync } from '../../src/index'
56

@@ -139,8 +140,9 @@ export default code
139140
it('should use relative filename in error stack trace', async () => {
140141
expect.assertions(1)
141142
const filename = 'foo.js'
142-
const relativeDirname = path.relative(process.cwd(), __dirname)
143-
const relativeFilename = path.join(relativeDirname, filename)
143+
const relativeDirnamePath = path.relative(process.cwd(), __dirname)
144+
const relativeFilenamePath = path.join(relativeDirnamePath, filename)
145+
const relativeFilename = normalizePath(relativeFilenamePath)
144146
try {
145147
await importFromString('throw new Error("boom")', {
146148
filename,

__tests__/esm/require.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ it('should use relative filename in error stack trace', () => {
103103

104104
it('should use absolute filename in error stack trace', () => {
105105
expect.assertions(1)
106-
const filename = path.join(os.homedir(), 'foo', 'bar', 'baz.js')
106+
const homedir = os.homedir()
107+
const normalizedHomedir = /^[A-Z]/.test(homedir)
108+
? `${homedir[0].toLowerCase()}${homedir.slice(1)}`
109+
: homedir
110+
const filename = path.join(normalizedHomedir, 'foo', 'bar', 'baz.js')
107111
try {
108112
requireFromString('throw new Error("boom")', {
109113
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)