Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moduleNameMapper to not resolve .wasm.js to .wasm #9894

Merged
merged 20 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions packages/backend/src/core/activitypub/LdSignatureService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as crypto from 'node:crypto';
import { Inject, Injectable } from '@nestjs/common';
import jsonld from 'jsonld';
import { HttpRequestService } from '@/core/HttpRequestService.js';
import { bindThis } from '@/decorators.js';
import { CONTEXTS } from './misc/contexts.js';
Expand Down Expand Up @@ -85,7 +84,9 @@ class LdSignature {
@bindThis
public async normalize(data: any) {
const customLoader = this.getLoader();
return await jsonld.normalize(data, {
// XXX: Importing jsonld dynamically since Jest frequently fails to import it statically
Copy link
Member Author

@saschanaz saschanaz Feb 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

諦めた結果こうなってしまいました
なんかjsonldのdependencyである@digitalbazaar/http-client/dist/cjs/index.cjsのdynamic importあたりでなにかエラーが出てくるみたいですが、原因不明です。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jestjs/jest#10620 (comment) 関係あるかもです、ないかもです

When I call it with a valid filepath, Jest exits with a non-zero exit code without reporting any failure (I would expect it to throw "Ok 2").

まさにその通り

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもCJSとかあるnodeが悪い、denoにするべき💢

// https://github.com/misskey-dev/misskey/pull/9894#discussion_r1103753595
return (await import('jsonld')).default.normalize(data, {
documentLoader: customLoader,
});
}
Expand Down