1
1
import { createRequire } from "module" ;
2
2
import path from "path" ;
3
- import { fileURLToPath } from "url" ;
4
3
import { describe , it , expect } from "vitest" ;
5
4
6
- const __filename = fileURLToPath ( import . meta. url ) ;
7
- const __dirname = path . dirname ( __filename ) ;
5
+ // Current directory where the test file is located
6
+ const currentDir = import . meta. dirname ;
7
+
8
+ // Get project root (go up from tests/integration to project root)
9
+ const projectRoot = path . resolve ( currentDir , "../.." ) ;
8
10
9
11
describe ( "Build Test" , ( ) => {
10
12
it ( "should successfully require CommonJS module" , ( ) => {
11
13
const require = createRequire ( __filename ) ;
12
- const cjsPath = path . resolve ( __dirname , "../../ dist/cjs/lib.js" ) ;
14
+ const cjsPath = path . resolve ( projectRoot , "dist/cjs/lib.js" ) ;
13
15
14
16
const cjsModule = require ( cjsPath ) as Record < string , unknown > ;
15
17
@@ -18,7 +20,7 @@ describe("Build Test", () => {
18
20
} ) ;
19
21
20
22
it ( "should successfully import ESM module" , async ( ) => {
21
- const esmModule = ( await import ( "../../dist/lib.js" ) ) as Record < string , unknown > ;
23
+ const esmModule = ( await import ( "../../dist/esm/ lib.js" ) ) as Record < string , unknown > ;
22
24
23
25
expect ( esmModule ) . toBeDefined ( ) ;
24
26
expect ( typeof esmModule ) . toBe ( "object" ) ;
@@ -31,7 +33,7 @@ describe("Build Test", () => {
31
33
const cjsModule = require ( cjsPath ) as Record < string , unknown > ;
32
34
33
35
// Import ESM module
34
- const esmModule = ( await import ( "../../dist/lib.js" ) ) as Record < string , unknown > ;
36
+ const esmModule = ( await import ( "../../dist/esm/ lib.js" ) ) as Record < string , unknown > ;
35
37
36
38
// Compare exports
37
39
const cjsKeys = Object . keys ( cjsModule ) . sort ( ) ;
0 commit comments