-
Notifications
You must be signed in to change notification settings - Fork 18
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
TypeError [ERR_INVALID_ARG_TYPE] #72
Comments
Seems to be related to Windows again. I will have a look at it tonight. |
I'm not sure if this is related (or just my mistake) but I was trying to run the latest master branch locally and got this:
|
The tests run on Windows. So this is not the problem. The repo you linked is ESM and the test command also enables this mode. BUT the transformer, that is used, is a CJS transformer. There seems to be something wrong with the whole setup. |
It is definitely a bug, which is not covered by our current tests. Jest chooses the CJS transformer, but runs the processAsync code. That's where it fails. We need to add a test for this case. BUT, why is Jest choosing the CJS version? |
I tried some variations of See |
I encountered the issue above and found this chat helpful in resolving my test failures.
I then encountered "ReferenceError: document is not defined" & "using the wrong test environment".
to the top of my test file fixed that. |
Same issue for me, but the above doesn't fix it :( |
Starts happening when preprocessing is enabled in "transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
}, Happens even when there is no pre-processing configured in Unfortunately, I need that preprocessing. |
Any update on this? @mtempleheald could you please share your working config? |
I am encountering the same issue on macOS (Monterey). Its currently blocking me from collecting coverage :( |
From looking at
got transformed into
And it seemed to work. As js/ts is not my thing, I'll just add all the seemingly random things that my jest config has now // jest.config.ts
import type { Config } from "@jest/types";
const config: Config.InitialOptions = {
verbose: true,
preset: "ts-jest/presets/default-esm",
transform: {
"^.+\\.svelte$": [
"<rootDir>/node_modules/svelte-jester/dist/transformer.mjs",
{ preprocess: "./svelte.config.test.cjs" }, // holds the most default svelte-preprocess ever
],
"^.+\\.ts$": "ts-jest",
},
moduleFileExtensions: ["js", "ts", "svelte"],
testEnvironment: "jsdom",
moduleNameMapper: {
"^\\$lib(.*)$": "<rootDir>/src/lib$1",
"^\\$app(.*)$": [
"<rootDir>/.svelte-kit/dev/runtime/app$1",
"<rootDir>/.svelte-kit/build/runtime/app$1",
],
},
setupFilesAfterEnv: ["<rootDir>/jest-setup.ts"],
collectCoverageFrom: ["src/**/*.{ts,tsx,svelte,js,jsx}"],
transformIgnorePatterns: [],
extensionsToTreatAsEsm: [".ts", ".svelte"],
globals: {
"ts-jest": {
babelConfig: true,
useESM: true,
},
},
};
export default config; |
Was facing same issue for untested svelte files. |
Same issue under osx. Failed to collect coverage from ./About.svelte |
Hi, @mdi22 and i had similar problems, and found a working solution (after 3 frustrating days 🙈). Here comes the solution just in case someone stumbles upon that thread like we did during troubleshooting. Actually, it is not easy to choose the right place where to put the solution, because of all the different technologies included in our stack: Our stack:
(Other system properties dont matter, we are using osx, linux and windows for development.) Goal was to have a testing setup for custom svelte components, including coverage and debugging. Our custom components may depend on imported Typescript and/or Bootstrap code. These errors came up at some point in time during working on the test setup (some mentioned by others in posts above too, anyway, this list is not complete):
We managed to fix all that. Here is a working subset of our project code, when reading it, take *.test.ts as entry points: Main points of the solution:
Some settings that worked too, but we found them not so pretty:Jest config:
babel config, as recommended in svelte-preprocess (https://github.com/sveltejs/svelte-preprocess)
svelte.config.js in cjs module syntax
This did NOT work, our typescript config was messed up:
Some other helpful resources around svelte component testing:
. We hope, that helps someone 🙂 |
There seems to be some new options to jest transformers (https://github.com/facebook/jest/blob/main/docs/CodeTransformation.md#writing-custom-transformers) to control the runner, on which version to choose (CJS or ESM). Might be worth a try. |
Should be fixed now 😄 Let us know if you run into any issues. |
Having trouble running tests, here's a demo repo.
I'm using it with SvelteKit and pnpm on Windows 10.
The text was updated successfully, but these errors were encountered: