Skip to content

JUnit XML failure element and attribute are incorrect when using node:assert #59593

@CuriousStork

Description

@CuriousStork

Version

v24.4.1

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

test

What steps will reproduce the bug?

  1. Create any test file, like

    import { equal } from "node:assert/strict";
    import { test } from "node:test";
    
    const value = 1;
    
    await test("testName", () => {
      equal(value, 0, `The value must be 0`);
    });
  2. Run the test via console

    node --test --test-reporter=junit ".\junit.test.mts"
  3. Check the report from stdout.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

  • failure element should have a correct message attribute. I guess having "The value must be 0" in this example would be fine
  • testcase element shouldn't have the failure attribute.

What do you see instead?

failure in testcase element and message in failure element are "The value must be 01 !== 0":

        <testcase name="testName" time="0.002234" classname="test" failure="The value must be 01 !== 0">
                <failure type="testCodeFailure" message="The value must be 01 !== 0">
Error [ERR_TEST_FAILURE]: The value must be 0

1 !== 0

    at async file:///C:/code/project/junit.test.mts:6:1 {
  code: 'ERR_TEST_FAILURE',
  failureType: 'testCodeFailure',
  cause: AssertionError [ERR_ASSERTION]: The value must be 0
  
  1 !== 0
  
      at TestContext.&lt;anonymous> (file:///C:/code/project/junit.test.mts:7:3)
      at Test.runInAsyncScope (node:async_hooks:214:14)
      at Test.run (node:internal/test_runner/test:1062:25)
      at Test.start (node:internal/test_runner/test:959:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17)
      at async file:///C:/code/project/junit.test.mts:6:1 {
    generatedMessage: false,
    code: 'ERR_ASSERTION',
    actual: 1,
    expected: 0,
    operator: 'strictEqual'
  }
}
                </failure>
        </testcase>

Additional information

No response

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