Skip to content

Can't set classname for testcase element in JUnit XML when using node:test #59417

@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 { suite, test } from "node:test";
    
    await suite('suiteName', () => {
      test('testName', () => {});
    });
  2. Run the test via console

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

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

Always. Regardless the suite or test function arguments.

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

There should be a way to set classname value for the JUnit report.

As of JUnit XML specification, classname is

Full class name for the class the test method is in.

For example, GitLab uses classname when rendering the test reports.

https://docs.gitlab.com/ci/testing/unit_test_reports/

The testcase classname attribute is used as the suite name, not the testsuite name attribute.

What do you see instead?

 <testcase name="testName" time="0.000363" classname="test"/>

classname is always "test".

Additional information

I guess currently there's no way to set classname in a test event, so reports always get "test" instead:

currentTest.attrs.classname = event.data.classname ?? 'test';

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