Skip to content

Commit

Permalink
Fix moduleNameMapper to not resolve .wasm.js to .js
Browse files Browse the repository at this point in the history
Fixes misskey-dev#9767

Undici [tries to import `./llhttp/llhttp.wasm.js`](https://github.com/nodejs/undici/blob/e155c6db5cec9bc577d548fa7c7378013631c79c/lib/client.js#L342) which is currently broken by the (hacky) module name mapper.
  • Loading branch information
saschanaz committed Feb 11, 2023
1 parent 5d02405 commit 1750fc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
14 changes: 0 additions & 14 deletions packages/backend/jest-resolver.cjs

This file was deleted.

11 changes: 9 additions & 2 deletions packages/backend/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ module.exports = {

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
"^@/(.*?).js": "<rootDir>/src/$1.ts",
// Do not resolve .wasm.js to .wasm by the rule below
'^(.+)\\.wasm\\.js$': '$1.wasm.js',
// SWC converts @/foo/bar.js to `../../src/foo/bar.js`, and then this rule
// converts it again to `../../src/foo/bar` which then can be resolved to
// `.ts` files.
// See https://github.com/swc-project/jest/issues/64#issuecomment-1029753225
// TODO: Use `--allowImportingTsExtensions` on TypeScript 5.0 so that we can
// directly import `.ts` files without this hack.
'^(\\.{1,2}/.*)\\.js$': '$1',
},

Expand Down Expand Up @@ -112,7 +119,7 @@ module.exports = {
// resetModules: false,

// A path to a custom resolver
resolver: './jest-resolver.cjs',
// resolver: './jest-resolver.cjs',

// Automatically restore mock state between every test
restoreMocks: true,
Expand Down

0 comments on commit 1750fc5

Please sign in to comment.