forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add matrix node test (dequelabs#4275)
* ci: add matrix node test * 🤖 Automated formatting fixes * use node orb * full node range * fix npm command * 🤖 Automated formatting fixes * fix how jsdom is installed * comments * drop down support to just 6 + LTS * use all-rules.html * read file * move node test to GHA * fix gha * fix upload * try again? * pin to v3 for upload/download * fix prettier action * output ignore file * cat not echo --------- Co-authored-by: straker <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,209 additions
and
1,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules/ | ||
doc/api | ||
doc/api |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} |