Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize jest-junit CI and local dev setup #273

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12.x, 13.x, 14.x, 16.x]
jest-version: [24, 25, 26, 27]
exclude:
# jest@27 doesn't support node@13
- node-version: 13.x
jest-version: 27
node-version: [23.x, 22.x, 21.x, 20.x]
jest-version: [30.0.0-alpha.3]
runs-on: ubuntu-latest

steps:
Expand All @@ -36,13 +32,13 @@ jobs:
yarn add --dev jest@${{ matrix.jest-version }} babel-jest@${{ matrix.jest-version }}
yarn
- name: run tests
run: yarn test
run: NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" yarn test
test-os:
name: Test on ${{ matrix.os }} using Node.js LTS
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -54,4 +50,4 @@ jobs:
- name: install
run: yarn
- name: run tests
run: yarn test
run: NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" yarn test
60 changes: 30 additions & 30 deletions __tests__/__snapshots__/buildJsonResults.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`buildJsonResults should support displayName template var for jest multi-project 1`] = `
Object {
"testsuites": Array [
Object {
"_attr": Object {
{
"testsuites": [
{
"_attr": {
"errors": 0,
"failures": 0,
"name": "jest tests",
"tests": 2,
"time": 1.234,
},
},
Object {
"testsuite": Array [
Object {
"_attr": Object {
{
"testsuite": [
{
"_attr": {
"errors": 0,
"failures": 0,
"name": "project1-foo",
Expand All @@ -25,22 +25,22 @@ Object {
"timestamp": "2018-02-10T14:52:31",
},
},
Object {
"properties": Array [
Object {
"property": Object {
"_attr": Object {
{
"properties": [
{
"property": {
"_attr": {
"name": "best-tester",
"value": "Jason Palmer",
},
},
},
],
},
Object {
"testcase": Array [
Object {
"_attr": Object {
{
"testcase": [
{
"_attr": {
"classname": "a thing should foo",
"name": "project1-bar",
"time": 0.003,
Expand All @@ -50,10 +50,10 @@ Object {
},
],
},
Object {
"testsuite": Array [
Object {
"_attr": Object {
{
"testsuite": [
{
"_attr": {
"errors": 0,
"failures": 0,
"name": "project2-foo",
Expand All @@ -63,22 +63,22 @@ Object {
"timestamp": "2018-02-10T14:52:31",
},
},
Object {
"properties": Array [
Object {
"property": Object {
"_attr": Object {
{
"properties": [
{
"property": {
"_attr": {
"name": "best-tester",
"value": "Jason Palmer",
},
},
},
],
},
Object {
"testcase": Array [
Object {
"_attr": Object {
{
"testcase": [
{
"_attr": {
"classname": "another thing should foo",
"name": "project2-bar",
"time": 0.001,
Expand Down
116 changes: 58 additions & 58 deletions __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,69 +454,69 @@ describe('buildJsonResults', () => {
});

expect(jsonResults).toMatchInlineSnapshot(`
Object {
"testsuites": Array [
Object {
"_attr": Object {
"errors": 0,
"failures": 0,
"name": "jest tests",
"tests": 1,
"time": 1.234,
},
{
"testsuites": [
{
"_attr": {
"errors": 0,
"failures": 0,
"name": "jest tests",
"tests": 1,
"time": 1.234,
},
},
{
"testsuite": [
{
"_attr": {
"errors": 0,
"failures": 0,
"name": "foo",
"skipped": 0,
"tests": 1,
"time": 0.12,
"timestamp": "2017-03-17T01:05:47",
},
Object {
"testsuite": Array [
Object {
"_attr": Object {
"errors": 0,
"failures": 0,
"name": "foo",
"skipped": 0,
"tests": 1,
"time": 0.12,
"timestamp": "2017-03-17T01:05:47",
},
{
"properties": [
{
"property": {
"_attr": {
"name": "best-tester",
"value": "Jason Palmer",
},
},
Object {
"properties": Array [
Object {
"property": Object {
"_attr": Object {
"name": "best-tester",
"value": "Jason Palmer",
},
},
},
],
},
],
},
{
"testcase": [
{
"_attr": {
"classname": "foo baz should bar",
"name": "foo baz should bar",
"time": 0.001,
},
Object {
"testcase": Array [
Object {
"_attr": Object {
"classname": "foo baz should bar",
"name": "foo baz should bar",
"time": 0.001,
},
{
"properties": [
{
"property": {
"_attr": {
"name": "dd_tags[test.invocations]",
"value": 2,
},
},
Object {
"properties": Array [
Object {
"property": Object {
"_attr": Object {
"name": "dd_tags[test.invocations]",
"value": 2,
},
},
},
],
},
],
},
],
},
],
}
`)
},
],
},
],
},
],
},
],
}
`)
});
});
87 changes: 60 additions & 27 deletions __tests__/lib/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
const xml = require('xml');
const path = require('path');
const fs = require('fs');
const libxmljs = require('libxmljs2');

const schemaPath = path.join(__dirname, 'junit.xsd');
const schemaStr = fs.readFileSync(schemaPath);
const schema = libxmljs.parseXmlString(schemaStr);

global.expect.extend({
toBeCompliantJUnit(jsonResults) {
const xmlStr = xml(jsonResults, { indent: ' '});
module.exports = async () => {
const xml = require('xml');
const path = require('path');
const fs = require('fs');
await import('libxml2-wasm').then(({ XmlDocument, XsdValidator }) => {
global.expect.extend({
toBeCompliantJUnit(jsonResults) {
const schemaPath = path.join(__dirname, 'junit.xsd');
const schema = XmlDocument.fromBuffer(fs.readFileSync(schemaPath));
const validator = XsdValidator.fromDoc(schema);

const xmlStr = xml(jsonResults, { indent: ' '});

const doc = XmlDocument.fromString(xmlStr);

try {
validator.validate(doc);

return {
message: () => `expected not to validate against junit xsd`,
pass: true
}
} catch (err) {
return {
message: () => `${err.message}\n${xmlStr}`,
pass: false
}
}
}
});
});
};

const libxmljsObj = libxmljs.parseXmlString(xmlStr);
const isValid = libxmljsObj.validate(schema);

if (!isValid) {
return {
message: () => `${libxmljsObj.validationErrors.join('\n')}\n${xmlStr}`,
pass: false
}
} else {
return {
message: () => `expected not to validate against junit xsd`,
pass: true
}
}
}
});
// import ('libxml2-wasm').then(({XmlDocument, XsdValidator}) => {
// const schemaPath = path.join(__dirname, 'junit.xsd');
// const schema = XmlDocument.fromBuffer(fs.readFileSync(schemaPath));
// const validator = XsdValidator.fromDoc(schema);

// console.log('Here');
// global.expect.extend({
// toBeCompliantJUnit(jsonResults) {
// const xmlStr = xml(jsonResults, { indent: ' '});

// const doc = XmlDocument.fromBuffer(xmlStr);

// try {
// validator.validate(doc);

// return {
// message: () => `expected not to validate against junit xsd`,
// pass: true
// }
// } catch (err) {
// return {
// message: () => `${err.message}\n${xmlStr}`,
// pass: false
// }
// }
// }
// });
// });
Loading
Loading