Skip to content

Commit a22623d

Browse files
committed
Modernize jest-junit CI and local dev setup
1 parent a7f59c1 commit a22623d

File tree

12 files changed

+1378
-1932
lines changed

12 files changed

+1378
-1932
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
node-version: [12.x, 13.x, 14.x, 16.x]
20-
jest-version: [24, 25, 26, 27]
21-
exclude:
22-
# jest@27 doesn't support node@13
23-
- node-version: 13.x
24-
jest-version: 27
19+
node-version: [23.x, 22.x, 21.x, 20.x]
20+
jest-version: [29, 28]
2521
runs-on: ubuntu-latest
2622

2723
steps:

__tests__/__snapshots__/buildJsonResults.test.js.snap

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`buildJsonResults should support displayName template var for jest multi-project 1`] = `
4-
Object {
5-
"testsuites": Array [
6-
Object {
7-
"_attr": Object {
4+
{
5+
"testsuites": [
6+
{
7+
"_attr": {
88
"errors": 0,
99
"failures": 0,
1010
"name": "jest tests",
1111
"tests": 2,
1212
"time": 1.234,
1313
},
1414
},
15-
Object {
16-
"testsuite": Array [
17-
Object {
18-
"_attr": Object {
15+
{
16+
"testsuite": [
17+
{
18+
"_attr": {
1919
"errors": 0,
2020
"failures": 0,
2121
"name": "project1-foo",
@@ -25,22 +25,22 @@ Object {
2525
"timestamp": "2018-02-10T14:52:31",
2626
},
2727
},
28-
Object {
29-
"properties": Array [
30-
Object {
31-
"property": Object {
32-
"_attr": Object {
28+
{
29+
"properties": [
30+
{
31+
"property": {
32+
"_attr": {
3333
"name": "best-tester",
3434
"value": "Jason Palmer",
3535
},
3636
},
3737
},
3838
],
3939
},
40-
Object {
41-
"testcase": Array [
42-
Object {
43-
"_attr": Object {
40+
{
41+
"testcase": [
42+
{
43+
"_attr": {
4444
"classname": "a thing should foo",
4545
"name": "project1-bar",
4646
"time": 0.003,
@@ -50,10 +50,10 @@ Object {
5050
},
5151
],
5252
},
53-
Object {
54-
"testsuite": Array [
55-
Object {
56-
"_attr": Object {
53+
{
54+
"testsuite": [
55+
{
56+
"_attr": {
5757
"errors": 0,
5858
"failures": 0,
5959
"name": "project2-foo",
@@ -63,22 +63,22 @@ Object {
6363
"timestamp": "2018-02-10T14:52:31",
6464
},
6565
},
66-
Object {
67-
"properties": Array [
68-
Object {
69-
"property": Object {
70-
"_attr": Object {
66+
{
67+
"properties": [
68+
{
69+
"property": {
70+
"_attr": {
7171
"name": "best-tester",
7272
"value": "Jason Palmer",
7373
},
7474
},
7575
},
7676
],
7777
},
78-
Object {
79-
"testcase": Array [
80-
Object {
81-
"_attr": Object {
78+
{
79+
"testcase": [
80+
{
81+
"_attr": {
8282
"classname": "another thing should foo",
8383
"name": "project2-bar",
8484
"time": 0.001,

__tests__/buildJsonResults.test.js

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -454,69 +454,69 @@ describe('buildJsonResults', () => {
454454
});
455455

456456
expect(jsonResults).toMatchInlineSnapshot(`
457-
Object {
458-
"testsuites": Array [
459-
Object {
460-
"_attr": Object {
461-
"errors": 0,
462-
"failures": 0,
463-
"name": "jest tests",
464-
"tests": 1,
465-
"time": 1.234,
466-
},
457+
{
458+
"testsuites": [
459+
{
460+
"_attr": {
461+
"errors": 0,
462+
"failures": 0,
463+
"name": "jest tests",
464+
"tests": 1,
465+
"time": 1.234,
466+
},
467+
},
468+
{
469+
"testsuite": [
470+
{
471+
"_attr": {
472+
"errors": 0,
473+
"failures": 0,
474+
"name": "foo",
475+
"skipped": 0,
476+
"tests": 1,
477+
"time": 0.12,
478+
"timestamp": "2017-03-17T01:05:47",
467479
},
468-
Object {
469-
"testsuite": Array [
470-
Object {
471-
"_attr": Object {
472-
"errors": 0,
473-
"failures": 0,
474-
"name": "foo",
475-
"skipped": 0,
476-
"tests": 1,
477-
"time": 0.12,
478-
"timestamp": "2017-03-17T01:05:47",
480+
},
481+
{
482+
"properties": [
483+
{
484+
"property": {
485+
"_attr": {
486+
"name": "best-tester",
487+
"value": "Jason Palmer",
479488
},
480489
},
481-
Object {
482-
"properties": Array [
483-
Object {
484-
"property": Object {
485-
"_attr": Object {
486-
"name": "best-tester",
487-
"value": "Jason Palmer",
488-
},
489-
},
490-
},
491-
],
490+
},
491+
],
492+
},
493+
{
494+
"testcase": [
495+
{
496+
"_attr": {
497+
"classname": "foo baz should bar",
498+
"name": "foo baz should bar",
499+
"time": 0.001,
492500
},
493-
Object {
494-
"testcase": Array [
495-
Object {
496-
"_attr": Object {
497-
"classname": "foo baz should bar",
498-
"name": "foo baz should bar",
499-
"time": 0.001,
501+
},
502+
{
503+
"properties": [
504+
{
505+
"property": {
506+
"_attr": {
507+
"name": "dd_tags[test.invocations]",
508+
"value": 2,
500509
},
501510
},
502-
Object {
503-
"properties": Array [
504-
Object {
505-
"property": Object {
506-
"_attr": Object {
507-
"name": "dd_tags[test.invocations]",
508-
"value": 2,
509-
},
510-
},
511-
},
512-
],
513-
},
514-
],
515-
},
516-
],
517-
},
518-
],
519-
}
520-
`)
511+
},
512+
],
513+
},
514+
],
515+
},
516+
],
517+
},
518+
],
519+
}
520+
`)
521521
});
522522
});

__tests__/lib/setupTests.js

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,62 @@
1-
const xml = require('xml');
2-
const path = require('path');
3-
const fs = require('fs');
4-
const libxmljs = require('libxmljs2');
5-
6-
const schemaPath = path.join(__dirname, 'junit.xsd');
7-
const schemaStr = fs.readFileSync(schemaPath);
8-
const schema = libxmljs.parseXmlString(schemaStr);
9-
10-
global.expect.extend({
11-
toBeCompliantJUnit(jsonResults) {
12-
const xmlStr = xml(jsonResults, { indent: ' '});
1+
module.exports = async () => {
2+
const xml = require('xml');
3+
const path = require('path');
4+
const fs = require('fs');
5+
await import('libxml2-wasm').then(({ XmlDocument, XsdValidator }) => {
6+
global.expect.extend({
7+
toBeCompliantJUnit(jsonResults) {
8+
const schemaPath = path.join(__dirname, 'junit.xsd');
9+
const schema = XmlDocument.fromBuffer(fs.readFileSync(schemaPath));
10+
const validator = XsdValidator.fromDoc(schema);
11+
12+
const xmlStr = xml(jsonResults, { indent: ' '});
13+
14+
const doc = XmlDocument.fromString(xmlStr);
15+
16+
try {
17+
validator.validate(doc);
18+
19+
return {
20+
message: () => `expected not to validate against junit xsd`,
21+
pass: true
22+
}
23+
} catch (err) {
24+
return {
25+
message: () => `${err.message}\n${xmlStr}`,
26+
pass: false
27+
}
28+
}
29+
}
30+
});
31+
});
32+
};
1333

14-
const libxmljsObj = libxmljs.parseXmlString(xmlStr);
15-
const isValid = libxmljsObj.validate(schema);
1634

17-
if (!isValid) {
18-
return {
19-
message: () => `${libxmljsObj.validationErrors.join('\n')}\n${xmlStr}`,
20-
pass: false
21-
}
22-
} else {
23-
return {
24-
message: () => `expected not to validate against junit xsd`,
25-
pass: true
26-
}
27-
}
28-
}
29-
});
35+
// import ('libxml2-wasm').then(({XmlDocument, XsdValidator}) => {
36+
// const schemaPath = path.join(__dirname, 'junit.xsd');
37+
// const schema = XmlDocument.fromBuffer(fs.readFileSync(schemaPath));
38+
// const validator = XsdValidator.fromDoc(schema);
39+
40+
// console.log('Here');
41+
// global.expect.extend({
42+
// toBeCompliantJUnit(jsonResults) {
43+
// const xmlStr = xml(jsonResults, { indent: ' '});
44+
45+
// const doc = XmlDocument.fromBuffer(xmlStr);
46+
47+
// try {
48+
// validator.validate(doc);
49+
50+
// return {
51+
// message: () => `expected not to validate against junit xsd`,
52+
// pass: true
53+
// }
54+
// } catch (err) {
55+
// return {
56+
// message: () => `${err.message}\n${xmlStr}`,
57+
// pass: false
58+
// }
59+
// }
60+
// }
61+
// });
62+
// });

__tests__/testResultProcessor.test.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jest.mock('fs', () => {
2121
});
2222

2323
const fs = require('fs');
24-
const libxmljs = require('libxmljs2');
2524
const path = require('path');
2625

2726
const testResultProcessor = require('../');
@@ -53,10 +52,6 @@ describe('jest-junit', () => {
5352

5453
// Ensure file would have been generated
5554
expect(fs.writeFileSync).toHaveBeenLastCalledWith(path.resolve('junit.xml'), expect.any(String));
56-
57-
// Ensure generated file is valid xml
58-
const xmlDoc = libxmljs.parseXml(fs.writeFileSync.mock.calls[0][1]);
59-
expect(xmlDoc).toBeTruthy();
6055
});
6156

6257
it('should generate valid xml with unique name', () => {
@@ -75,10 +70,6 @@ describe('jest-junit', () => {
7570

7671
// Ensure file would have been generated
7772
expect(fs.writeFileSync).toHaveBeenLastCalledWith(expect.stringMatching(expectedOutputRegex), expect.any(String));
78-
79-
// Ensure generated file is valid xml
80-
const xmlDoc = libxmljs.parseXml(fs.writeFileSync.mock.calls[0][1]);
81-
expect(xmlDoc).toBeTruthy();
8273
});
8374

8475
it('should generate valid xml despite illegal characters', () => {
@@ -90,10 +81,6 @@ describe('jest-junit', () => {
9081

9182
// Ensure file would have been generated
9283
expect(fs.writeFileSync).toHaveBeenLastCalledWith(path.resolve('junit.xml'), expect.any(String));
93-
94-
// Ensure generated file is valid xml
95-
const xmlDoc = libxmljs.parseXml(fs.writeFileSync.mock.calls[0][1]);
96-
expect(xmlDoc).toBeTruthy();
9784
});
9885

9986
it('should generate xml at the output filepath defined by JEST_JUNIT_OUTPUT_FILE', () => {

integration-tests/reporter/__tests__/simple.test.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

integration-tests/reporter/jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)