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

jest 27 + svelte-jester 2 #63

Closed
patrickleet opened this issue Aug 5, 2021 · 14 comments
Closed

jest 27 + svelte-jester 2 #63

patrickleet opened this issue Aug 5, 2021 · 14 comments

Comments

@patrickleet
Copy link

patrickleet commented Aug 5, 2021

just tried upgrading jest + svelte-jest with the new release

getting various errors with different configurations.

See linked github actions builds for specifics

@patrickleet
Copy link
Author

in CI I get different errors, which is odd, here's a public repo with github actions: https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel/pull/10/checks?check_run_id=3256813646

@sebastianrothe
Copy link
Collaborator

This is an issue with node v16.6.0 jestjs/jest#11708

Please upgrade your node version.

@sebastianrothe
Copy link
Collaborator

in CI I get different errors, which is odd, here's a public repo with github actions: https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel/pull/10/checks?check_run_id=3256813646

The error is related to Jest thinking you don't use ESM. Have a look over here #59 (comment)

@patrickleet
Copy link
Author

I looked at that comment, which links to a PR.

Tbh, I'm not really sure what I'm supposed to change still.

@sidharthv96
Copy link

@benmccann I'm getting the following error with 2.1.0

> jest src

● Validation Error:

  Module svelte-jester in the transform option was not found.
         <rootDir> is: /Users/sidv/dev/turgen/ds-frontend

  Configuration Documentation:
  https://jestjs.io/docs/configuration

Is there any extra configuration required?
My jest.config.json

{
  "testEnvironment": "jsdom",
  "transform": {
    "^.+\\.svelte$": [
      "svelte-jester",
      {
        "preprocess": true
      }
    ],
    "^.+\\.ts$": "ts-jest"
  },
  "moduleNameMapper": {
    "^\\$lib(.*)$": "<rootDir>/src/lib$1",
    "^\\$app(.*)$": [
      "<rootDir>/.svelte-kit/dev/runtime/app$1",
      "<rootDir>/.svelte-kit/build/runtime/app$1"
    ]
  },
  "moduleFileExtensions": [
    "js",
    "ts",
    "svelte"
  ],
  "setupFilesAfterEnv": [
    "./src/setupTests.ts"
  ],
  "globals": {
    "ts-jest": {
      "tsconfig": "tsconfig.spec.json"
    }
  }
}

@benmccann
Copy link
Collaborator

2.1.1 is out now which fixes an issue with the file paths in package.json. I'm not sure if it changes things for you or not. If it doesn't, it would help to have a project to reproduce the error

@patrickleet
Copy link
Author

@benmccann

The error still occurs here with 2.1.1 https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel/pull/10/checks?check_run_id=3473288531

That repo is public and that PR is a reproduction.

@patrickleet
Copy link
Author

Here's another branch configured differently - experimental-vm-modules, removed esbuild-jest (which makes import.meta.env work), and extensionsToTreatAsEsm set:

CloudNativeEntrepreneur/sveltekit-eventsourced-funnel#26

This way fails because of the import.meta.env stuff though without esbuild-jest handling it.

Maybe the logic they have in there could be put into svelte-jester?

@patrickleet
Copy link
Author

Took it a bit further here: CloudNativeEntrepreneur/sveltekit-eventsourced-funnel#30 by using a babel plugin to handle the import.meta.env stuff, but now getting require not defined from using mocks, cause I guess mocks don't work with ESM?

@mszkb
Copy link

mszkb commented Aug 31, 2021

This should be resolved with #69

@patrickleet
Copy link
Author

this is working, imo - the only thing that is not working well with jest is mocking ESM, but that's a jest issue, not this lib. Example set up here: https://github.com/CloudNativeEntrepreneur/sveltekit-eventsourced-funnel

@benmccann
Copy link
Collaborator

@patrickleet not sure if you saw, but basic experimental mocking support has been checked in for ESM now and will be released hopefully tomorrow, so perhaps that issue is solved now as well. jestjs/jest@90d6908

@patrickleet
Copy link
Author

I did not - nice! I got creative without it for now haha. That will for sure come in handy for some more useful tests though.

@patrickleet
Copy link
Author

@benmccann not sure if you saw, but the babel config I ended up with is pretty minimal - it ONLY handle import.meta.env stuff - could be useful for svelte-add jest config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants