Cannot find module jest-sequencer-@jest/test-sequencer

Viewed 1128

I am trying to debug Jest tests in VSCode, but it can't resolve some modules. I set a breakpoint where jest.run is called below is the argv

"--runInBand"
"--no-cache"
"--watchAll=false"
"--config"
"{\"roots\":[\"<rootDir>/src\"],\"collectCoverageFrom\":[\"src/**/*.{js,jsx,ts,tsx}\",\"!src/**/*.d.ts\"],\"setupFiles\":[\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/react-app-polyfill/jsdom.js\"],\"setupFilesAfterEnv\":[],\"testMatch\":[\"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}\",\"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}\"],\"testEnvironment\":\"jsdom\",\"testRunner\":\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/jest-circus/runner.js\",\"transform\":{\"^.+\\\\.(js|jsx|mjs|cjs|ts|tsx)$\":\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/react-scripts/config/jest/babelTransform.js\",\"^.+\\\\.css$\":\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/react-scripts/config/jest/cssTransform.js\",\"^(?!.*\\\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)\":\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/react-scripts/config/jest/fileTransform.js\"},\"transformIgnorePatterns\":[\"[/\\\\\\\\]node_modules[/\\\\\\\\].+\\\\.(js|jsx|mjs|cjs|ts|tsx)$\",\"^.+\\\\.module\\\\.(css|sass|scss)$\"],\"modulePaths\":[],\"moduleNameMapper\":{\"^react-native$\":\"react-native-web\",\"^.+\\\\.module\\\\.(css|sass|scss)$\":\"identity-obj-proxy\"},\"moduleFileExtensions\":[\"web.js\",\"js\",\"web.ts\",\"ts\",\"web.tsx\",\"tsx\",\"json\",\"web.jsx\",\"jsx\",\"node\"],\"watchPlugins\":[\"jest-watch-typeahead/filename\",\"jest-watch-typeahead/testname\"],\"resetMocks\":true,\"rootDir\":\"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp\"}"
"--env"
"/Users/username/projects/project-name/CSharpProjectName/src/ClientApp/node_modules/jest-environment-jsdom/build/index.js"

My suspicion is that the value for --env is what is causing the problem.

For reference, I my config files:

jest.config.js

module.exports = {
  transform: {
    "^.+\\.tsx?$": "ts-jest",
  },
  testRegex: "(.*)\\.(test|spec)\\.(jsx?|tsx?)$",
  rootDir: "/Users/username/projects/project-name/CSharpProjectName/src/ClientApp",
  modulePaths: [
    "<rootDir>"
  ],
  moduleDirectories: ["node_modules", "src"],
  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
  testEnvironment: "jsdom"
};

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug CRA Tests",
            "type": "node",
            "request": "launch",
            "runtimeExecutable": "${workspaceRoot}/src/ClientApp/node_modules/.bin/react-scripts",
            "args": ["test", "--runInBand", "--no-cache", "--watchAll=false", "--env=jsdom"],
            "cwd": "${workspaceRoot}/src/ClientApp",
            "protocol": "inspector",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "env": { "CI": "true" },
            "disableOptimisticBPs": true
        }
    ]
}

Directory structure:

project-name   
└── CSharpProjectName
    ├── .vscode
    │   ├── tasks.json
    │   ├── launch.json    
    │   └── settings.json 
    ├── Dockerfile
    └── src
        ├── ClientApp
        │   ├── jest.config.js
        │   ├── package-lock.json
        │   ├── package.json
        │   ├── public
        │   │   ├── favicon.ico
        │   │   ├── index.html
        │   │   └── manifest.json
        │   ├── src
        │   │   ├── App.test.tsx
        │   │   ├── App.tsx
        │   │   ├── components
        │   │   │   ├── Home.tsx
        │   │   │   ├── Layout.tsx
        │   │   │   └── NavMenu.tsx
        │   │   ├── index.tsx
        │   │   ├── react-app-env.d.ts
        │   │   └── registerServiceWorker.ts
        │   └── tsconfig.json
        ├── Program.cs
        ├── Startup.cs
        ├── CSharpProjectName.csproj
        └── appsettings.json

And I open VS Code from the CSharpProjectName directory.

EDIT:

Tried using cross-env as the executable in launch.json. Also did not work:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cross Env Debug CRA Tests",
            "type": "node",
            "request": "launch",
            "runtimeExecutable": "${workspaceRoot}/src/ClientApp/node_modules/.bin/cross-env",
            "args": ["CI=true", "${workspaceRoot}/src/ClientApp/node_modules/.bin/react-scripts", "test", "--env=jsdom"],
            "cwd": "${workspaceRoot}/src/ClientApp",
            "protocol": "inspector",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        }
    ]
}
2 Answers

Something eerily similar started happening to me, today.

I finally discovered that, in VS Code, I had accidentally ticked on "Breakpoints --> Caught Exceptions" in the "Run and Debug" view at some point. This caused the appearance of this error, but one that could be ignored by continuing to run (or by unticking that "Caught Exceptions" option).

Related