@reporters/junit 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0](https://github.com/MoLow/reporters/compare/junit-v1.0.4...junit-v1.1.0) (2023-05-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * report node 20 features ([c99a76c](https://github.com/MoLow/reporters/commit/c99a76c0f6bef75abb2c053c82c88448b0c82690))
9
+
10
+ ## [1.0.4](https://github.com/MoLow/reporters/compare/junit-v1.0.3...junit-v1.0.4) (2023-04-03)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * allow multiple roots ([590df94](https://github.com/MoLow/reporters/commit/590df948f8a4626fc29e8ce185e08d2226a307ba))
16
+
3
17
  ## [1.0.3](https://github.com/MoLow/reporters/compare/junit-v1.0.2...junit-v1.0.3) (2023-03-12)
4
18
 
5
19
 
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![npm version](https://img.shields.io/npm/v/@reporters/junit)](https://www.npmjs.com/package/@reporters/junit) ![tests](https://github.com/MoLow/reporters/actions/workflows/test.yaml/badge.svg?branch=main)
1
+ [![npm version](https://img.shields.io/npm/v/@reporters/junit)](https://www.npmjs.com/package/@reporters/junit) ![tests](https://github.com/MoLow/reporters/actions/workflows/test.yaml/badge.svg?branch=main) [![codecov](https://codecov.io/gh/MoLow/reporters/branch/main/graph/badge.svg?token=0LFVC8SCQV)](https://codecov.io/gh/MoLow/reporters)
2
+
2
3
  # Junit Reporter
3
4
  A Junit reporter for `node:test`.
4
5
  intendend for use with major CI tools like Jenkins, CircleCI, etc that consume Junit reports.
package/index.js CHANGED
@@ -41,6 +41,7 @@ module.exports = async function* junitReporter(source) {
41
41
  yield '<?xml version="1.0" encoding="utf-8"?>\n';
42
42
  yield '<testsuites>\n';
43
43
  let currentSuite = null;
44
+ const roots = [];
44
45
 
45
46
  function startTest(event) {
46
47
  const originalSuite = currentSuite;
@@ -51,6 +52,9 @@ module.exports = async function* junitReporter(source) {
51
52
  children: [],
52
53
  };
53
54
  originalSuite?.children.push(currentSuite);
55
+ if (!currentSuite.parent) {
56
+ roots.push(currentSuite);
57
+ }
54
58
  }
55
59
 
56
60
  for await (const event of source) {
@@ -69,7 +73,7 @@ module.exports = async function* junitReporter(source) {
69
73
  startTest(event);
70
74
  }
71
75
  const currentTest = currentSuite;
72
- if (currentSuite?.nesting === event.data.nesting && currentSuite?.parent) {
76
+ if (currentSuite?.nesting === event.data.nesting) {
73
77
  currentSuite = currentSuite.parent;
74
78
  }
75
79
  currentTest.props.time = (event.data.details.duration_ms / 1000).toFixed(6);
@@ -113,6 +117,8 @@ module.exports = async function* junitReporter(source) {
113
117
  break;
114
118
  }
115
119
  }
116
- yield treeToXML(currentSuite);
120
+ for (const suite of roots) {
121
+ yield treeToXML(suite);
122
+ }
117
123
  yield '</testsuites>\n';
118
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/junit",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "A jUnit reporter for `node:test`",
5
5
  "keywords": [
6
6
  "junit",
@@ -1,9 +1,10 @@
1
1
  const { spawnSync } = require('child_process');
2
2
  const assert = require('assert');
3
3
  const { compareLines } = require('../../../tests/utils');
4
- const output = require('./output');
4
+ // eslint-disable-next-line import/no-dynamic-require
5
+ const output = require(`./output.${process.version.split('.')[0]}`);
5
6
 
6
- const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example']);
7
+ const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: {} });
7
8
 
8
9
  assert.strictEqual(child.stderr?.toString(), '');
9
10
  compareLines(child.stdout?.toString(), output.stdout);
@@ -1,14 +1,14 @@
1
1
  module.exports = {
2
2
  stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
3
3
  <testsuites>
4
- \t<testsuite name="tests" time=".*" disabled="0" errors="0" tests="2" failures="1" skipped="0" hostname=".*">
4
+ \t<testsuite name="tests" time=".*" disabled="0" errors="0" tests="3" failures="1" skipped="0" hostname=".*">
5
5
  \t\t<testcase name="is ok" time=".*" classname="test"/>
6
6
  \t\t<testcase name="fails" time=".*" classname="test" failure="this is an error">
7
7
  \t\t\t<failure type="testCodeFailure" message="this is an error">
8
8
  \\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {
9
9
  failureType: 'testCodeFailure',
10
10
  cause: Error: this is an error
11
- at Object.&lt;anonymous&gt; (.*)
11
+ .*
12
12
  .*
13
13
  .*
14
14
  .*
@@ -21,6 +21,10 @@ module.exports = {
21
21
  }
22
22
  \t\t\t</failure>
23
23
  \t\t</testcase>
24
+ \t\t<testcase name="is a diagnostic" time=".*" classname="test"/>
25
+ \t</testsuite>
26
+ \t<testsuite name="more tests" time=".*" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname=".*">
27
+ \t\t<testcase name="is ok" time=".*" classname="test"/>
24
28
  \t</testsuite>
25
29
  </testsuites>
26
30
  `,
@@ -0,0 +1,31 @@
1
+ module.exports = {
2
+ stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
3
+ <testsuites>
4
+ \t<testsuite name="tests" time=".*" disabled="0" errors="0" tests="3" failures="1" skipped="0" hostname=".*">
5
+ \t\t<testcase name="is ok" time=".*" classname="test"/>
6
+ \t\t<testcase name="fails" time=".*" classname="test" failure="this is an error">
7
+ \t\t\t<failure type="testCodeFailure" message="this is an error">
8
+ \\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {
9
+ failureType: 'testCodeFailure',
10
+ cause: Error: this is an error
11
+ .*
12
+ .*
13
+ .*
14
+ .*
15
+ .*
16
+ .*
17
+ .*
18
+ .*
19
+ .*
20
+ code: 'ERR_TEST_FAILURE'
21
+ }
22
+ \t\t\t</failure>
23
+ \t\t</testcase>
24
+ \t\t<testcase name="is a diagnostic" time=".*" classname="test"/>
25
+ \t</testsuite>
26
+ \t<testsuite name="more tests" time=".*" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname=".*">
27
+ \t\t<testcase name="is ok" time=".*" classname="test"/>
28
+ \t</testsuite>
29
+ </testsuites>
30
+ `,
31
+ };
@@ -0,0 +1,31 @@
1
+ module.exports = {
2
+ stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
3
+ <testsuites>
4
+ \t<testsuite name="tests" time=".*" disabled="0" errors="0" tests="3" failures="1" skipped="0" hostname=".*">
5
+ \t\t<testcase name="is ok" time=".*" classname="test"/>
6
+ \t\t<testcase name="fails" time=".*" classname="test" failure="this is an error">
7
+ \t\t\t<failure type="testCodeFailure" message="this is an error">
8
+ \\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {
9
+ failureType: 'testCodeFailure',
10
+ cause: Error: this is an error
11
+ .*
12
+ .*
13
+ .*
14
+ .*
15
+ .*
16
+ .*
17
+ .*
18
+ .*
19
+ .*
20
+ code: 'ERR_TEST_FAILURE'
21
+ }
22
+ \t\t\t</failure>
23
+ \t\t</testcase>
24
+ \t\t<testcase name="is a diagnostic" time=".*" classname="test"/>
25
+ \t</testsuite>
26
+ \t<testsuite name="more tests" time=".*" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname=".*">
27
+ \t\t<testcase name="is ok" time=".*" classname="test"/>
28
+ \t</testsuite>
29
+ </testsuites>
30
+ `,
31
+ };