Skip to content

Commit

Permalink
test: Add test showing axe runs under strict csp (#1744)
Browse files Browse the repository at this point in the history
* test: add test showing axe runs under strict csp

* use meta tag directly

* check for errors
  • Loading branch information
straker authored and WilcoFiers committed Aug 3, 2019
1 parent a0f3eef commit 94950c7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/integration/full/strict-csp/strict-csp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8" />
<script id="check-phantomjs">
// phantomjs requires running in non-strict csp
if (!window.PHANTOMJS) {
var thisScript = document.getElementById('check-phantomjs');
var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'Content-Security-Policy');
meta.setAttribute(
'content',
"script-src 'nonce-4AEemGb0xJptoIGFP3Nd'; style-src 'nonce-4AEemGb0xJptoIGFP3Nd'"
);
document.head.appendChild(meta);
}
</script>
<link
nonce="4AEemGb0xJptoIGFP3Nd"
rel="stylesheet"
type="text/css"
href="/node_modules/mocha/mocha.css"
/>
<script
nonce="4AEemGb0xJptoIGFP3Nd"
src="/node_modules/mocha/mocha.js"
></script>
<script
nonce="4AEemGb0xJptoIGFP3Nd"
src="/node_modules/chai/chai.js"
></script>
<script nonce="4AEemGb0xJptoIGFP3Nd" src="/axe.js"></script>
<script nonce="4AEemGb0xJptoIGFP3Nd">
mocha.setup({
timeout: 10000,
ui: 'bdd'
});
var assert = chai.assert;
</script>
</head>
<body>
<div id="mocha"></div>
<script nonce="4AEemGb0xJptoIGFP3Nd" src="/test/testutils.js"></script>
<script nonce="4AEemGb0xJptoIGFP3Nd" src="strict-csp.js"></script>
<script
nonce="4AEemGb0xJptoIGFP3Nd"
src="/test/integration/adapter.js"
></script>
</body>
</html>
17 changes: 17 additions & 0 deletions test/integration/full/strict-csp/strict-csp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// phantomjs requires running in non-strict csp
(window.PHANTOMJS ? describe.skip : describe)('strict-csp', function() {
'use strict';

it('should parse without errors', function() {
assert.isDefined(window.axe), 'axe is not defined';
assert.isDefined(window.axe.run, 'axe.run is not defined');
});

it('should run without errors', function(done) {
axe.run(function(err, results) {
assert.isNull(err);
assert.isDefined(results);
done();
});
});
});

0 comments on commit 94950c7

Please sign in to comment.