Skip to content

Implement JUnit reporter#486

Merged
smainil merged 5 commits intotcort:masterfrom
Gijsreyn:junit-reporter
Sep 2, 2025
Merged

Implement JUnit reporter#486
smainil merged 5 commits intotcort:masterfrom
Gijsreyn:junit-reporter

Conversation

@Gijsreyn
Copy link
Contributor

This PR addresses #424. To not break the build from #364, I simply added a junit reported to the reporters objet, allowing to report on:

  • Calculate total tests, failed tests, skipped tests, and passed tests
  • Generate JUnit XML
  • Handle all link status

@Gijsreyn
Copy link
Contributor Author

Hey @smainil, just in an attempt to implement it myself, perhaps you can take a look at this one if you have time. Much appreciated!

@smainil
Copy link
Collaborator

smainil commented Jul 30, 2025

@Gijsreyn I just had a quick look to your changes and it's more or less what I tried to do the other day.

It works as expected only if you analyze a single file. If you analyze more than one file the content of the junit report is overwritten again and again and will only content the result of the last analyzed file.

you should not create the content of the file as a plain text but use an xmlBuilder module like this

        const doc = create({ version: '1.0', encoding: 'UTF-8' })
            .ele('testsuites');
        const suite = doc.ele('testsuite', { name: filenameForOutput });
        if (err) suite.ele('error', { message: err })
        else {
            for (const result of results) {
                const test = suite.ele('testcase', { classname: result.link, name: result.link, time: 0 });
                if (result.status !== 'dead') continue;
                else {
                    if (result.err != null) {
                        test.ele('error', {
                            message: result.err,
                            type: 'error'
                        });
                    } else {
                        test.ele('error', {
                            message: result.err
                                ?? `${result.link} is ${result.status} (${result.statusCode})`,
                            type: result.status
                        });
                    }
                }
            }
        }
        fs.writeFileSync('junit.xml', doc.end({ prettyPrint: true }) + '\n');

3 last working days before holidays and time to find a way to solve the problem

@Gijsreyn
Copy link
Contributor Author

Great catch, I hadn't actually tried that one out.

I skipped the module part as per previous PR, as I thought it gave problems of earlier releases...

@Gijsreyn
Copy link
Contributor Author

Mind giving it another stab @smainil? I have just updated the code to use xmlBuilder.

@smainil
Copy link
Collaborator

smainil commented Aug 13, 2025

@Gijsreyn Going to have a look to it

@smainil
Copy link
Collaborator

smainil commented Aug 13, 2025

it works really good. 👏 I would like to find a way to make it more generic and not junit only related

@Gijsreyn
Copy link
Contributor Author

it works really good. 👏 I would like to find a way to make it more generic and not junit only related

Understood! For now, I have updated the code with your remarks. Do you want to do that in this PR or a different one?

@smainil
Copy link
Collaborator

smainil commented Aug 13, 2025

Understood! For now, I have updated the code with your remarks. Do you want to do that in this PR or a different one?

Seems good for now in this PR. The current code is now more generic. Only the variables needed for the junit reporters are defined in the junit reporters

@smainil
Copy link
Collaborator

smainil commented Aug 13, 2025

@WillGibson @BaseMax the code proposed by @Gijsreyn is good for me (but I am not a nodejs expert :-)) can you have a look to the changes please before I merge ?

@Gijsreyn
Copy link
Contributor Author

Hey @WillGibson, @BaseMax or @smainil, is this ready to be pulled in and get released :)?

Copy link
Collaborator

@smainil smainil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

@smainil smainil merged commit c54543a into tcort:master Sep 2, 2025
12 checks passed
@smainil
Copy link
Collaborator

smainil commented Sep 2, 2025

@Gijsreyn Changes are merged to master

@smainil
Copy link
Collaborator

smainil commented Sep 2, 2025

@tcort could you publish a new version now that these changes are on the master branch ? Thx

@Gijsreyn
Copy link
Contributor Author

Gijsreyn commented Sep 2, 2025

@Gijsreyn Changes are merged to master

Thanks a lot!

@Gijsreyn Gijsreyn deleted the junit-reporter branch September 6, 2025 06:18
@Gijsreyn
Copy link
Contributor Author

@tcort - just checking in. Would it be possible to publish a new release with these changes? Would really help us to test it out in an Azure DevOps pipeline. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants