Skip to content

Commit

Permalink
fix: Avoid require conflict wity Cypress [#1405]
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Mar 5, 2019
1 parent 1ffa28a commit 3708444
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build/imports-generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const browserify = require('browserify');
const derequire = require('derequire');
const createFile = require('./shared/create-file');

const inputFile = path.join(
Expand All @@ -25,6 +26,8 @@ async function run() {
throw new Error('Cannot browserify axe.imports', err);
}
try {
// Replace `require` calls with `_dereq_` in order not to confuse Cypress.js
result = derequire(result);
await createFile(outputFile, result);
} catch (error) {
throw new Error('Cannot write browserify generated axe.imports', error);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"chai": "~4.1.2",
"clone": "~2.1.1",
"css-selector-parser": "^1.3.0",
"derequire": "^2.0.6",
"dot": "~1.1.2",
"emoji-regex": "7.0.3",
"es6-promise": "^4.2.6",
Expand Down
10 changes: 10 additions & 0 deletions test/integration/full/umd/umd-module-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ describe('UMD module.export', function() {
assert.strictEqual(module.exports, axe);
});

it('does not use `require` functions', function() {
// This is to avoid colliding with Cypress.js which overloads all
// uses of variables named `require`.
assert.notMatch(
axe.source,
/[^.]require\(/,
'Axe source should not contain `require` variables'
);
});

it('should ensure axe source includes axios', function() {
assert.isTrue(axe.source.includes(axe.imports.axios.toString()));
});
Expand Down

0 comments on commit 3708444

Please sign in to comment.