1
1
import { createRequire } from "module" ;
2
2
import path from "path" ;
3
- import { fileURLToPath } from "url" ;
3
+ import { fileURLToPath , pathToFileURL } from "url" ;
4
4
import { describe , it , expect } from "vitest" ;
5
5
6
6
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -19,8 +19,9 @@ describe("Build Test", () => {
19
19
20
20
it ( "should successfully import ESM module" , async ( ) => {
21
21
const esmPath = path . resolve ( __dirname , "../../dist/lib.js" ) ;
22
+ const esmFileURL = pathToFileURL ( esmPath ) . href ;
22
23
23
- const esmModule = ( await import ( esmPath ) ) as Record < string , unknown > ;
24
+ const esmModule = ( await import ( esmFileURL ) ) as Record < string , unknown > ;
24
25
25
26
expect ( esmModule ) . toBeDefined ( ) ;
26
27
expect ( typeof esmModule ) . toBe ( "object" ) ;
@@ -34,7 +35,8 @@ describe("Build Test", () => {
34
35
35
36
// Import ESM module
36
37
const esmPath = path . resolve ( __dirname , "../../dist/lib.js" ) ;
37
- const esmModule = ( await import ( esmPath ) ) as Record < string , unknown > ;
38
+ const esmFileURL = pathToFileURL ( esmPath ) . href ;
39
+ const esmModule = ( await import ( esmFileURL ) ) as Record < string , unknown > ;
38
40
39
41
// Compare exports
40
42
const cjsKeys = Object . keys ( cjsModule ) . sort ( ) ;
0 commit comments