Skip to content

4.x: junitReporter doesn't record Before/After suite failures #5645

Description

@mirao

In CodeceptJS 3.x there could be the "mocha-junit-reporter" configured in a CodeceptJS config in "mocha" section.
If the test failed in BeforeSuite(), Scenario() or AfterSuite() I could see the failure, typically in Jenkins's JUnit test result report plugin ✔️

For example:

Image

In CodeceptJS 4.x, it was replaced by the plugin "junitReporter". It doesn't record any failure when the test fails in BeforeSuite() or AfterSuite() 🐛 . It records only Scenario() failures.

tests/My_test.ts:

Feature('My');

BeforeSuite(async ({ I }) => {
    I.say("Before Suite");
    throw new Error("Before Suite Error");
});

Scenario('test something',  ({ I }) => {
    I.amOnPage("https://example.com");
});

AfterSuite(async ({ I }) => {
    I.say("After Suite");
    throw new Error("After Suite Error");
});

codecept.conf.ts

import { setHeadlessWhen, setCommonPlugins } from "@codeceptjs/configure";
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
  tests: "./tests/*_test.ts",
  output: "./output",
  helpers: {
    Playwright: {
      browser: "chromium",
      url: "http://localhost",
      show: true,
    },
  },
  include: {
    I: "./steps_file.ts",
  },
  noGlobals: true,
  plugins: {
    junitReporter: {
      enabled: true,
    },
  },
  name: "my",
  require: ["tsx/cjs"],
};

output:

mirao@rog:~/workspace/my$ codeceptjs run --verbose
***************************************
nodeInfo:  24.16.0
osInfo:  Linux 6.17 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
cpuInfo:  (16) x64 AMD Ryzen 7 9700X 8-Core Processor
chromeInfo:  149.0.7827.155
edgeInfo:  "N/A"
firefoxInfo:  152.0
safariInfo:  N/A
playwrightBrowsers:  "chromium: 149.0.7827.55, firefox: 151.0, webkit: 26.5"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v4.0.8 #StandWithUkraine
Using test root "/home/mirao/workspace/my"
Helpers: Playwright
Plugins: screenshot, junitReporter, retryFailedStep

My --
/home/mirao/workspace/my/tests/My_test.ts
    [1]  Starting recording promises
    Timeouts: 
 › [Session] Starting singleton browser session
  BeforeSuite()
    I say "Before Suite"
   Before Suite
    [1] Error | Error: Before Suite Error e => { const err = recorder.getAsyncErr() === null...
    [1] <teardown>  Stopping recording promises
  ✖ FAILED in 4ms

  AfterSuite()
    [2]  Starting recording promises
    I say "After Suite"
   After Suite
    [2] Error | Error: After Suite Error e => { const err = recorder.getAsyncErr() === null...
    [2] <teardown>  Stopping recording promises
  ✖ FAILED in 1ms


-- FAILURES:

  1) My
       "before all" hook: BeforeSuite for "test something":
     
  Before Suite Error
      at Context.<anonymous> (tests/My_test.ts:5:11)
      at promiseRetry.retries.retries (file:///home/mirao/workspace/my/node_modules/codeceptjs/lib/mocha/asyncWrapper.js:162:20)
  
  
  ◯ File: file:///home/mirao/workspace/my/tests/My_test.ts
  

  2) My
       "after all" hook: AfterSuite for "test something":
     
  After Suite Error
      at Context.<anonymous> (tests/My_test.ts:14:11)
      at promiseRetry.retries.retries (file:///home/mirao/workspace/my/node_modules/codeceptjs/lib/mocha/asyncWrapper.js:162:20)
      at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
  
  
  ◯ File: file:///home/mirao/workspace/my/tests/My_test.ts
  


  FAIL  | 0 passed, 2 failed, 2 failedHooks   // 123ms
 › <junitReporter> JUnit report saved to /home/mirao/workspace/my/output/report.xml

output/report.xml:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="CodeceptJS" tests="0" failures="0" skipped="0" errors="0" time="0.000" timestamp="2026-06-19T11:19:00.325Z"/>

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