Open smvv opened 1 year ago
note: it seems that esbuild-jest
is transforming the test source file using babel when the source code contains the string ock(
: https://github.com/aelbore/esbuild-jest/commit/e94d4c181108efc4341956995e36edb3d7d81b45#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R34
Could that ordering be an issue that causes the runtime error?
Yes. All import statements will be hoisted. In fact, It's a bug of tsc. see https://github.com/microsoft/TypeScript/issues/16166
Could a jest plugin like this hoisting of mock calls be related?
It's possible to hoist jest related methods.
I haven't tested it myself. Have you tried manually editing the statement order of the swc compiled files? If it is feasible, It's better to send a feature request to https://github.com/swc-project/plugins/tree/main/packages/jest , since it is related to import hoisting and this repository focuses on the mutability of export.
I've read #79 but I think I'm seeing a related issue.
minimal reproducible code
There are two input source files:
The swc config used for transforming TS to JS in jest is:
The tsc config is:
tsc transpiled
Test output:
swc transpiled
Test output:
Notes
SWC version info:
Tsc generates this import order:
while swc generates:
Could that ordering be an issue that causes the runtime error?
I'm using the jest preset
ts-jest
with a custom transformer (to allow switching at runtime usingTS_LOADER
between tsc and swc).Could a jest plugin like this hoisting of mock calls be related?
I hope this issue contains all the information. Let me know if a reproducible git repo would be helpful to narrow down the problem. Thank you!