Skip to content

Commit

Permalink
add multiple reporters tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightjack committed May 10, 2021
1 parent 05dfbb5 commit 1d7010b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/unit/lib/pa11y-ci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,47 @@ describe('lib/pa11y-ci', () => {
});

});

describe('multiple reporters', () => {
let userUrls;
let userOptions;
let optionReporter;
let reporter;

beforeEach(async () => {
reporter = require('../mock/reporter.mock')();
optionReporter = require('../mock/reporter-options.mock');
mockery.registerMock('my-reporter', reporter);
mockery.registerMock('option-reporter', optionReporter);

userUrls = [
'foo-url'
];
userOptions = {
concurrency: 4,
log,
reporters: ['my-reporter', ['option-reporter', {fileName: '/__TEST__.json'}], 'option-reporter']
};

pa11y.withArgs('foo-url').resolves({pageUrl: 'foo-url',
issues: []});

await pa11yCi(userUrls, userOptions);
});

it('calls reporters results methods', () => {
assert.calledOnce(reporter.results);
assert.callCount(optionReporter.$$resultsStub, 2);
});

it('calls option-reporter results with the correct options', () => {
// First time: custom option
const firstCall = optionReporter.$$resultsStub.getCall(0);
assert.calledWith(firstCall, 'foo-url', '/__TEST__.json');

// First time: default option
const secondCall = optionReporter.$$resultsStub.getCall(1);
assert.calledWith(secondCall, 'foo-url', '');
});
});
});
13 changes: 13 additions & 0 deletions test/unit/mock/reporter-options.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const sinon = require('sinon');

const resultsStub = sinon.stub();

module.exports = ({fileName = ''} = {}) => ({
results({pageUrl}) {
resultsStub(pageUrl, fileName);
}
});

module.exports.$$resultsStub = resultsStub;

0 comments on commit 1d7010b

Please sign in to comment.