Skip to content

Commit

Permalink
Update integration tests to support all platforms, including Windows (#…
Browse files Browse the repository at this point in the history
…177)

* Update integration tests to support all platforms, including Windows

* Add Windows and Mac to test matrix, matching pa11y
  • Loading branch information
aarongoldenthal authored Nov 3, 2023
1 parent e7b7c17 commit 3a5104b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@ on:
- master
pull_request:
branches: # Run actions when a PR is pushed based on one of these branches
- master
- '**'

jobs:
checkout_and_test:
runs-on: ubuntu-latest
name: Node v${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: [12, 14, 16]
include:
- node-version: 12.x
- os: ubuntu-latest
node: 12
lint: true # Linter is run only once to shorten the total build time
- node-version: 14.x
- node-version: 16.x

steps:
- name: Set git config
shell: bash
run: |
git config --global core.autocrlf false
if: runner.os == 'Windows'
- name: Checkout code from ${{ github.repository }}
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
uses: actions/checkout@v3
- name: Setup node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Run linter
Expand Down
4 changes: 3 additions & 1 deletion test/integration/cli-json.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint max-len: 'off' */
'use strict';

const path = require('path');
const assert = require('proclaim');

describe('pa11y-ci (with the `--json` flag set)', () => {
Expand All @@ -15,14 +16,15 @@ describe('pa11y-ci (with the `--json` flag set)', () => {

it('outputs the results as JSON', () => {
const outputData = JSON.parse(global.lastResult.output);
const filePath = path.resolve(__dirname, 'mock/config/foo/erroring.html');
assert.deepEqual(outputData, {
total: 3,
errors: 1,
passes: 1,
results: {
'./foo/erroring.html': [
{
message: `net::ERR_FILE_NOT_FOUND at file://${__dirname}/mock/config/foo/erroring.html`
message: `net::ERR_FILE_NOT_FOUND at file://${filePath}`
}
],
'http://localhost:8090/failing-1': [
Expand Down
5 changes: 3 additions & 2 deletions test/integration/mock/website/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs');
const http = require('http');
const path = require('path');
const parseUrl = require('url').parse;

module.exports = startWebsite;
Expand All @@ -11,13 +12,13 @@ function startWebsite(port, done) {
const server = http.createServer((request, response) => {

const urlPath = parseUrl(request.url).pathname;
const viewPath = `${__dirname}/html${urlPath}.html`;
const viewPath = path.join(__dirname, 'html', `${urlPath}.html`);

if (urlPath.includes('.xml')) {
response.writeHead(200, {
'Content-Type': 'text/xml'
});
return response.end(fs.readFileSync(`${__dirname}/${urlPath}`, 'utf-8'));
return response.end(fs.readFileSync(path.join(__dirname, urlPath), 'utf-8'));
}

try {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ before(done => {
});
});

function cliCall(cliArguments) {
function cliCall(cliArguments = []) {

const command = path.resolve(__dirname, '../../bin/pa11y-ci.js');
const binFile = path.resolve(__dirname, '../../bin/pa11y-ci.js');
const result = {
output: '',
stdout: '',
Expand All @@ -26,7 +26,7 @@ function cliCall(cliArguments) {
};

return new Promise(resolve => {
const child = spawn(command, cliArguments || [], {
const child = spawn('node', [binFile, ...cliArguments], {
cwd: path.join(__dirname, 'mock/config'),
env: process.env
});
Expand Down

0 comments on commit 3a5104b

Please sign in to comment.