It took me 2:30 hours to set this up and document it, it's incredibly tedious 😅
💡 If you're going to create a new npm project, take a look at my
// {...
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"silent": true,
"extensionsToTreatAsEsm": [
".ts"
],
"moduleNameMapper": {
"^(\\\\.{1,2}/.*)\\\\.js$": "$1"
},
"transform": {
"^.+\\\\.ts$": [
"ts-jest",
{
"useESM": true
}
]
}
},
// ...}
{
"name": "Jest",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--experimental-vm-modules", // <<< important
"${workspaceRoot}/node_modules/.bin/jest",
"${input:exchange}",
"-t",
"${input:testName}",
"--runInBand"
],
"cwd": "${workspaceRoot}",
"stopOnEntry": false,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
},
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
},