Closed ms-dosx86 closed 1 month ago
2.
jest
refused to run spec files with ESM enabled withbabel-jest
. It kept throwing this errorSyntaxError: Cannot use import statement outside a module
Yup. It looks like you're hitting https://github.com/jestjs/jest/issues/9860. As that issue says (eventually), you can solve the problem by adding extensionsToTreatAsEsm: ['.ts']
to the jest config.
However then you discover the next problem, which is that our tests rely on jest.mock
to mock out entire modules, which doesn't seem to work very well either. (https://github.com/jestjs/jest/issues/10025 seems related, though it doesn't entirely match the behaviour I observe).
Anyway, I think your proposed approach of sticking to CJS for Jest is the right one, for now at least.
Hi @richvdh !
And added a sign off in the last commit. Sorry, that was my bad. Didn't see it in the description checklist.
Thanks. Unfortunately that doesn't help with the earlier commits. Could you edit the description of the pull request to add a Signed-off-by
line there?
And added a sign off in the last commit. Sorry, that was my bad. Didn't see it in the description checklist.
Thanks. Unfortunately that doesn't help with the earlier commits. Could you edit the description of the pull request to add a
Signed-off-by
line there?
Oh.. I see. I updated the description. Hope that it's correct this time.
Checklist
public
/exported
symbols have accurate TSDoc documentation.Fixes https://github.com/matrix-org/matrix-js-sdk/issues/4154
There were a couple of things I encountered during this PR:
import type
insrc/models/MSC3089TreeSpace.ts
because@babel/preset-typescript
refused to remove that unused import. It contains two interfaces that should be removed afteryarn build
. But I guess this https://github.com/matrix-org/matrix-js-sdk/blob/develop/src/models/MSC3089TreeSpace.ts#L83prevents it from being removed.
import type
fixes this with minimum amount of effort.jest
refused to run spec files with ESM enabled withbabel-jest
. It kept throwing this erroreven tho I have
babel
andbabel-typescript
configured properly. I tried as described in the docs https://jestjs.io/docs/ecmascript-modules , but no success.Then I tried
ts-jest
instead ofbabel-jest
. It worked but 7 of 137 specs failed. This is one of themAccording to this https://github.com/kulshekhar/ts-jest/issues/1873 it might be related to circular dependencies problem since
src/crypto/index.ts
ends up importingsrc/client.ts
which tries to import./crypto
so the test fails. It works fine withyarn build
tho. I'm not familiar withjest
so any help here will be appreciated.Anyway, I replaced
.babelrc
withbabel.config.js
to run tests withmodules: "commonjs"
to makejest
work.And finally I added an example to test async imports (
rust-crypto
import) and see that they were splitted from the main chunk. A command to build and serve the exampleSigned-off-by: Bayyr Oorjak the.bayyr.oorjak@gmail.com