Skip to content

Commit d04fb81

Browse files
committed
update tests
1 parent 7abba69 commit d04fb81

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

e2e/native-esm/__tests__/native-esm.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@ test('should have correct import.meta', () => {
2828
expect(typeof require).toBe('undefined');
2929
expect(typeof jest).toBe('undefined');
3030
expect(import.meta).toEqual({
31+
dirname: expect.any(String),
32+
filename: expect.any(String),
3133
jest: expect.anything(),
3234
url: expect.any(String),
3335
});
3436
expect(import.meta.jest).toBe(jestObject);
3537
expect(
3638
import.meta.url.endsWith('/e2e/native-esm/__tests__/native-esm.test.js'),
3739
).toBe(true);
40+
expect(
41+
import.meta.filename.endsWith(
42+
'/e2e/native-esm/__tests__/native-esm.test.js',
43+
),
44+
).toBe(true);
45+
expect(import.meta.filename.startsWith('/')).toBe(true);
46+
expect(import.meta.dirname.endsWith('/e2e/native-esm/__tests__')).toBe(true);
3847
});
3948

4049
test('should double stuff', () => {

packages/jest-runtime/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,10 @@ export default class Runtime {
521521
meta.url = pathToFileURL(modulePath).href;
522522

523523
if (meta.url.startsWith('file://')) {
524+
// @ts-expect-error Jest uses @types/node@16. Will be fixed when updated to @types/[email protected]
524525
meta.filename = fileURLToPath(meta.url);
525-
meta.dirname = path.resolve(meta.filename);
526+
// @ts-expect-error Jest uses @types/node@16. Will be fixed when updated to @types/[email protected]
527+
meta.dirname = path.dirname(meta.filename);
526528
}
527529

528530
let jest = this.jestObjectCaches.get(modulePath);
@@ -682,7 +684,7 @@ export default class Runtime {
682684
// @ts-expect-error Jest uses @types/node@16. Will be fixed when updated to @types/[email protected]
683685
meta.filename = fileURLToPath(meta.url);
684686
// @ts-expect-error Jest uses @types/node@16. Will be fixed when updated to @types/[email protected]
685-
meta.dirname = path.resolve(meta.filename);
687+
meta.dirname = path.dirname(meta.filename);
686688
}
687689
},
688690
});

0 commit comments

Comments
 (0)