jest-community / jest-junit

A Jest reporter that creates compatible junit xml files
Apache License 2.0
483 stars 109 forks source link

Can't run jest-junit as a reporter #239

Closed mscharley closed 1 year ago

mscharley commented 1 year ago

I'm trying to get a new project setup with jest-junit but I get the following exception whenever I try to start jest:

> test:jest
> NODE_OPTIONS='--experimental-vm-modules' jest --no-cache

TypeError: An error occurred while adding the reporter at path "/path/to/project/node_modules/jest/build/index.js".
Reporter is not a constructor
    at TestScheduler._addCustomReporter (/path/to/project/node_modules/@jest/core/build/TestScheduler.js:373:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TestScheduler._setupReporters (/path/to/project/node_modules/@jest/core/build/TestScheduler.js:352:11)
    at async createTestScheduler (/path/to/project/node_modules/@jest/core/build/TestScheduler.js:86:3)
    at async runJest (/path/to/project/node_modules/@jest/core/build/runJest.js:342:21)
    at async _run10000 (/path/to/project/node_modules/@jest/core/build/cli/index.js:326:7)
    at async runCLI (/path/to/project/node_modules/@jest/core/build/cli/index.js:191:3)
    at async Object.run (/path/to/project/node_modules/jest-cli/build/run.js:124:37)

This only happens if I try to use this as a reporter using

  reporters: ["jest", ["jest-junit", {}]],

However, if I configure jest-junit as a testResultsProcessor then everything just works out of the box. The only thing I can think of that might be causing an issue is that this is an ESM project but without any context it's hard to say - I would have expected that to break things completely if it was the cause.

{
  "devDependencies": {
    "@jest/globals": "29.3.1",
    "@types/jest": "29.2.6",
    "jest": "29.3.1",
    "jest-junit": "^15.0.0"
  }
}
SimenB commented 1 year ago

jest isn't a valid reporter. Did you mean default?

mscharley commented 1 year ago

Hi Simen, that did it. I tried looking back at the README and I can't find what gave me the idea that would work. Sorry for the obvious issue, but thank you for pointing it out.