Skip to content

Commit 8b9dd96

Browse files
committed
test: make junit reporter assertions more flexible
The previous assertions for the JUnit reporter output were too strict about the order of XML attributes. The attribute order is not guaranteed and can vary, causing the test to fail. This commit updates the regular expressions to be independent of the attribute order, ensuring the test is more robust.
1 parent 63f36b0 commit 8b9dd96

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

test/parallel/test-runner-reporters.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,19 @@ describe('node:test reporters', { concurrency: true }, () => {
191191
assert.match(fileConent, / skipped 0/);
192192
assert.match(fileConent, / todo 0/);
193193
});
194+
195+
it('should correctly report pass/fail for junit reporter using reporters.js', async () => {
196+
const file = tmpdir.resolve(`${tmpFiles++}.xml`);
197+
const child = spawnSync(process.execPath,
198+
['--test', '--test-reporter', 'junit', '--test-reporter-destination', file, testFile]);
199+
200+
assert.strictEqual(child.stderr.toString(), '');
201+
assert.strictEqual(child.stdout.toString(), '');
202+
203+
const fileContents = fs.readFileSync(file, 'utf8');
204+
assert.match(fileContents, /<testsuite .*name="nested".*tests="2".*failures="1".*skipped="0".*>/);
205+
assert.match(fileContents, /<testcase .*name="failing".*>\s*<failure .*type="testCodeFailure".*message="error".*>/);
206+
assert.match(fileContents, /<testcase .*name="ok".*classname="test".*\/>/);
207+
assert.match(fileContents, /<testcase .*name="top level".*classname="test".*\/>/);
208+
});
194209
});

0 commit comments

Comments
 (0)