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.
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. Myjest.config.ts
now looks like this: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 removepreset: "@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.