Skip to content

Commit

Permalink
chore: handle file URLs in dynamic imports (#10744)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 30, 2020
1 parent d554eb1 commit f798a65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -9,8 +9,9 @@
- `[babel-plugin-jest-hoist]` Preserve order of hoisted mock nodes within containing block ([#10536](https://github.com/facebook/jest/pull/10536))
- `[expect]` Stop modifying the sample in `expect.objectContaining()` ([#10711](https://github.com/facebook/jest/pull/10711))
- `[jest-circus, jest-jasmine2]` fix: don't assume `stack` is always a string ([#10697](https://github.com/facebook/jest/pull/10697))
- `[jest-config]` Fix bug introduced in watch mode by PR[#10678](https://github.com/facebook/jest/pull/10678/files#r511037803) ([#10692](https://github.com/facebook/jest/pull/10692))
- `[jest-config]` Fix bug introduced in watch mode by PR [#10678](https://github.com/facebook/jest/pull/10678/files#r511037803) ([#10692](https://github.com/facebook/jest/pull/10692))
- `[jest-resolve-dependencies]` Resolve mocks as dependencies ([#10713](https://github.com/facebook/jest/pull/10713))
- `[jest-runtime]` Handle file URLs in dynamic imports ([#10744](https://github.com/facebook/jest/pull/10744))

### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
Expand Up @@ -10,7 +10,7 @@ Ran all test suites matching /native-esm.tla.test.js/i.
exports[`on node ^12.16.0 || >=13.7.0 runs test with native ESM 1`] = `
Test Suites: 1 passed, 1 total
Tests: 15 passed, 15 total
Tests: 16 passed, 16 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm.test.js/i.
Expand Down
6 changes: 6 additions & 0 deletions e2e/native-esm/__tests__/native-esm.test.js
Expand Up @@ -145,3 +145,9 @@ test('supports named imports from CJS', () => {

expect(Object.keys(defaultFromCjs)).toEqual(['namedFunction', 'default']);
});

test('supports file urls as imports', async () => {
const dynamic = await import(new URL('../stateful.mjs', import.meta.url));

expect(dynamic.default).toBe(staticImportedStateful);
});
4 changes: 4 additions & 0 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -438,6 +438,10 @@ class Runtime {
return globals;
}

if (specifier.startsWith('file://')) {
specifier = fileURLToPath(specifier);
}

const [path, query] = specifier.split('?');

const resolved = this._resolveModule(referencingIdentifier, path);
Expand Down

0 comments on commit f798a65

Please sign in to comment.