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

ci: add matrix node test #4275

Merged
merged 22 commits into from
Dec 18, 2023
Merged
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
13 changes: 7 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ commands:
browser-tools-job:
steps:
- browser-tools/install-browser-tools

jobs:
# Fetch and cache dependencies.
dependencies_unix:
Expand Down Expand Up @@ -240,15 +241,15 @@ jobs:
- <<: *restore_dependency_cache_unix
- run: npm run test:rule-help-version

# Test node API
test_node:
# Test jsdom API
test_jsdom:
<<: *defaults
<<: *unix_box
steps:
- checkout
- <<: *restore_dependency_cache_unix
- <<: *restore_build
- run: npm run test:node
- run: npm run test:jsdom

# Release a "next" version
next_release:
Expand Down Expand Up @@ -360,7 +361,7 @@ workflows:
- test_rule_help_version:
requires:
- build_unix
- test_node:
- test_jsdom:
requires:
- build_unix
# Verify the sri history is correct
Expand All @@ -385,7 +386,7 @@ workflows:
- test_virtual_rules
- build_api_docs
- test_rule_help_version
- test_node
- test_jsdom
- verify_sri
filters:
branches:
Expand All @@ -403,7 +404,7 @@ workflows:
- test_virtual_rules
- build_api_docs
- test_rule_help_version
- test_node
- test_jsdom
filters:
branches:
only: develop
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
cache: 'npm'
# Workflows are not allowed to edit workflows. As result, we need to prevent Prettier from formatting them.
- name: Prevent workflows from being formatted
run: echo ".github" >> .prettierignore
run: echo ".github" >> .prettierignore && cat .prettierignore
Copy link
Contributor Author

@straker straker Dec 18, 2023

Choose a reason for hiding this comment

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

This line wasn't working correctly and was failing the build as the .prettierignore file didn't have a newline character at the end of the file. So instead of appending a new line item this was appending to the end of the last item. Left this in for easier debugging.

node_modules/
doc/api.github

- run: npm run fmt
# Prevent the prettierignore change from being committed.
- run: git checkout .prettierignore
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on:
pull_request:
push:
branches:
- master
- develop

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run build
# v4 download seems to have some flakiness with the download of artifacts so pinning to v3 for now
# @see https://github.com/actions/download-artifact/issues/249
- uses: actions/upload-artifact@v3
with:
name: axe-core
path: axe.js
retention-days: 1

test_node:
strategy:
matrix:
node: [6, 18, 20]
runs-on: ubuntu-latest
timeout-minutes: 5
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node}}
- uses: actions/download-artifact@v3
with:
name: axe-core
- run: npm run test:node
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
doc/api
doc/api
2,112 changes: 1,056 additions & 1,056 deletions locales/el.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"test:locales": "mocha test/test-locales.js",
"test:virtual-rules": "mocha test/test-virtual-rules.js",
"test:rule-help-version": "mocha test/test-rule-help-version.js",
"test:node": "mocha test/node/*.js",
"test:node": "node test/node/node.js",
"test:jsdom": "mocha test/node/jsdom.js",
"version": "echo \"use 'npm run release' to bump axe-core version\" && exit 1",
"release": "git fetch origin --tags --force && standard-version -a",
"rule-gen": "node build/rule-generator",
Expand Down
93 changes: 93 additions & 0 deletions test/node/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// this file is purposefully written without mocha and in es5 syntax in order
// to be compatible with node 4+

var axe = require('../../');
var assert = require('assert');
var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');

initJsdom(function (err, window) {
assert.equal(err, null);

console.log('running axe');
axe.run(
window.document.documentElement,
{
preload: false,
rules: { 'color-contrast': { enabled: false } }
},
function (axeError, results) {
assert.equal(axeError, null);
assert.notEqual(results.violations.length, 0);
console.log('axe ran successfully');
}
);
});

/**
* Install a version of jsdom that is compatible with the currently running node
* version and return the jsdom window object.
* @param {Function} callback - callback function when jsdom is installed.
* Is passed any error object and the jsdom window object.
*/
function initJsdom(callback) {
try {
var nodeToJsdomMatrix = {
4: '9.12.0', // last jsdom version that supported this node version
6: '11.12.0',
8: '15.2.1',
10: '16.7.0',
12: '19.0.0',
14: '21.1.2',
16: '22.1.0'
};

var majorNodeVersion = process.versions.node.split('.')[0];
var jsdomVersion = nodeToJsdomMatrix[majorNodeVersion] || 'latest';

console.log('node version detected as: v' + majorNodeVersion);
console.log('installing jsdom@' + jsdomVersion);
var child = spawn(
'npm',
['install', 'jsdom@' + jsdomVersion, '--no-save'],
{
cwd: __dirname
}
);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function (data) {
console.log(data);
});
child.stderr.on('data', function (data) {
console.error(data);
});
child.on('close', function () {
console.log('installed');
var jsdom = require('jsdom');
var domStr = fs.readFileSync(
path.join('test', 'integration', 'full', 'all-rules', 'all-rules.html'),
'utf8'
);

// jsdom 9
if (jsdom.env) {
jsdom.env(domStr, function (jsdomError, window) {
if (jsdomError) {
callback(jsdomError);
}

callback(null, window);
});
}
// jsdom 11+
else {
var dom = new jsdom.JSDOM(domStr);
callback(null, dom.window);
}
});
} catch (err) {
callback(err);
}
}
4 changes: 4 additions & 0 deletions test/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "This package.json is intentionally left empty so running the node.js test does not install jsdom at the root level node_modules",
"dependencies": {}
}