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

Preset conflicting with jest --watch #435

Open
tim-rohrer opened this issue Sep 2, 2023 · 0 comments
Open

Preset conflicting with jest --watch #435

tim-rohrer opened this issue Sep 2, 2023 · 0 comments

Comments

@tim-rohrer
Copy link

I've been working with ESM for a while. Changes to Jest and my own understanding have caused me to try and thin my projects, to go to a more minimal number of npm install commands. It also caused me to better understand how to I should be able to use this present and ESM together. My jest.config.ts now looks like this:

import type { JestConfigWithTsJest } from "ts-jest"

const config: JestConfigWithTsJest = {
  preset: "@shelf/jest-mongodb",
  extensionsToTreatAsEsm: [".ts"],
  verbose: true,
  rootDir: "src",
  moduleNameMapper: {
    "^(\\.{1,2}/.*)\\.js$": "$1",
  },
  transform: {
    // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
    // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
    "^.+\\.tsx?$": [
      "ts-jest",
      {
        useESM: true,
      },
    ],
  },
  fakeTimers: {
    enableGlobally: true,
    doNotFake: ["nextTick", "setImmediate"],
  },
}

export default config

In the past, I didn't understand that I could use this preset with ESM, but I realize I can if I configure ts-jest as above.

What I found was that NODE_OPTIONS=--experimental-vm-modules npx jest --watch results in tests being run over and over again without me changing any files. It simply repeats.

jest does work without --watch. Through trial and error, if I remove preset: "@shelf/jest-mongodb".

I'll go back to manually configuring the mongdb memory server, but if someone sees something obviously wrong with my configuration, please let me know.

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

No branches or pull requests

1 participant