-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7a2632
commit 460c008
Showing
5 changed files
with
207 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* eslint max-len: 'off' */ | ||
'use strict'; | ||
|
||
const assert = require('proclaim'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
describe('pa11y-ci (with default reporter)', () => { | ||
before(() => { | ||
return global.cliCall(['--config', | ||
'defaults']); | ||
}); | ||
|
||
it('outputs to the stdout and stderr', () => { | ||
assert.include(global.lastResult.stdout, 'Running Pa11y on 2 URLs'); | ||
assert.include(global.lastResult.stderr, 'http://localhost:8090/passing-1 - Failed to run'); | ||
assert.include(global.lastResult.stderr, 'http://localhost:8090/passing-2 - Failed to run'); | ||
assert.include(global.lastResult.stderr, 'timed out'); | ||
}); | ||
|
||
}); | ||
|
||
describe('pa11y-ci (with json built-in reporter)', () => { | ||
before(() => { | ||
return global.cliCall(['--config', | ||
'defaults', '--reporter', 'json']); | ||
}); | ||
|
||
|
||
it('logs json to stdout', () => { | ||
let report; | ||
assert.doesNotThrow(() => { | ||
report = JSON.parse(global.lastResult.output); | ||
}); | ||
assert.isObject(report); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-1'); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-2'); | ||
}); | ||
|
||
}); | ||
|
||
describe('pa11y-ci (with json built-in reporter and configuration)', () => { | ||
const reportFile = path.resolve(__dirname, './mock/config/__output__/results.json'); | ||
before(() => { | ||
return global.cliCall(['--config', | ||
'reporters-json']); | ||
}); | ||
|
||
after(() => { | ||
if (fs.existsSync(reportFile)) { | ||
fs.rmSync(reportFile); | ||
} | ||
}); | ||
|
||
|
||
it('stores report in a file', () => { | ||
assert.equal(global.lastResult.output, ''); | ||
let report; | ||
|
||
assert.ok(fs.existsSync(reportFile)); | ||
|
||
assert.doesNotThrow(() => { | ||
report = JSON.parse(fs.readFileSync(reportFile, 'utf-8')); | ||
}); | ||
assert.isObject(report); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-1'); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-2'); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('pa11y-ci (with custom json reporter configuration)', () => { | ||
const reportFile = path.resolve(__dirname, './mock/config/__output__/my-results.json'); | ||
before(() => { | ||
return global.cliCall(['--config', | ||
'reporters-custom']); | ||
}); | ||
|
||
after(() => { | ||
if (fs.existsSync(reportFile)) { | ||
fs.rmSync(reportFile); | ||
} | ||
}); | ||
|
||
|
||
it('stores report in a "my-results.json" file', () => { | ||
assert.equal(global.lastResult.output, ''); | ||
let report; | ||
|
||
assert.ok(fs.existsSync(reportFile)); | ||
|
||
assert.doesNotThrow(() => { | ||
report = JSON.parse(fs.readFileSync(reportFile, 'utf-8')); | ||
}); | ||
assert.isObject(report); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-1'); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-2'); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('pa11y-ci (with multiple reporters)', () => { | ||
const customReportFile = path.resolve(__dirname, './mock/config/__output__/my-results.json'); | ||
const defaultReportFile = path.resolve(__dirname, './mock/config/__output__/default.json'); | ||
before(() => { | ||
return global.cliCall(['--config', | ||
'reporters-multiple']); | ||
}); | ||
|
||
after(() => { | ||
if (fs.existsSync(customReportFile)) { | ||
fs.rmSync(customReportFile); | ||
} | ||
if (fs.existsSync(defaultReportFile)) { | ||
fs.rmSync(defaultReportFile); | ||
} | ||
}); | ||
|
||
|
||
it('stores report in a "my-results.json" file', () => { | ||
let report; | ||
|
||
assert.ok(fs.existsSync(customReportFile)); | ||
|
||
assert.doesNotThrow(() => { | ||
report = JSON.parse(fs.readFileSync(customReportFile, 'utf-8')); | ||
}); | ||
assert.isObject(report); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-1'); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-2'); | ||
}); | ||
|
||
it('stores report in the default reporter file', () => { | ||
let report; | ||
|
||
assert.ok(fs.existsSync(defaultReportFile)); | ||
|
||
assert.doesNotThrow(() => { | ||
report = JSON.parse(fs.readFileSync(defaultReportFile, 'utf-8')); | ||
}); | ||
assert.isObject(report); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-1'); | ||
assert.include(Object.keys(report.results), 'http://localhost:8090/passing-2'); | ||
}); | ||
|
||
it('outputs results to console', () => { | ||
assert.include(global.lastResult.stdout, 'Running Pa11y on 2 URLs'); | ||
assert.include(global.lastResult.stderr, 'http://localhost:8090/passing-1 - Failed to run'); | ||
assert.include(global.lastResult.stderr, 'http://localhost:8090/passing-2 - Failed to run'); | ||
assert.include(global.lastResult.stderr, 'timed out'); | ||
}); | ||
|
||
}); |
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,12 @@ | ||
{ | ||
"defaults": { | ||
"timeout": 100, | ||
"reporters": [ | ||
["./reporters/custom.js", { "fileName": "./__output__/my-results.json"}] | ||
] | ||
}, | ||
"urls": [ | ||
"http://localhost:8090/passing-1", | ||
"http://localhost:8090/passing-2" | ||
] | ||
} |
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,12 @@ | ||
{ | ||
"defaults": { | ||
"timeout": 100, | ||
"reporters": [ | ||
["json", { "fileName": "./__output__/results.json"}] | ||
] | ||
}, | ||
"urls": [ | ||
"http://localhost:8090/passing-1", | ||
"http://localhost:8090/passing-2" | ||
] | ||
} |
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,14 @@ | ||
{ | ||
"defaults": { | ||
"timeout": 100, | ||
"reporters": [ | ||
"cli", | ||
"./reporters/custom.js", | ||
["./reporters/custom.js", { "fileName": "./__output__/my-results.json"}] | ||
] | ||
}, | ||
"urls": [ | ||
"http://localhost:8090/passing-1", | ||
"http://localhost:8090/passing-2" | ||
] | ||
} |
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,14 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const {resolve, dirname} = require('path'); | ||
|
||
module.exports = ({fileName = './__output__/default.json'}) => ({ | ||
afterAll(report) { | ||
if (fileName) { | ||
const filePath = resolve(process.cwd(), fileName); | ||
fs.mkdirSync(dirname(filePath), {recursive: true}); | ||
fs.writeFileSync(filePath, JSON.stringify(report), 'utf8'); | ||
} | ||
} | ||
}); |