Skip to content

Commit

Permalink
fix: Avoid require conflict with Cypress [#1405] (#1406)
Browse files Browse the repository at this point in the history
Use derequire the rename all uses of `require` to `_dereq_` to avoid the problem of Cypress overloading the `require` method.

Closes #1405

## Reviewer checks

**Required fields, to be filled out by PR reviewer(s)**
- [x] Follows the commit message policy, appropriate for next version
- [x] Has documentation updated, a DU ticket, or requires no documentation change
- [x] Includes new tests, or was unnecessary
- [x] Code is reviewed for security by: Stephen
  • Loading branch information
WilcoFiers authored Mar 6, 2019
1 parent 0d3d267 commit 30aa570
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": "8.0.0",
"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 30aa570

Please sign in to comment.