Skip to content

Preset conflicting with jest --watch #435

@tim-rohrer

Description

@tim-rohrer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions