Skip to content

Commit

Permalink
fix(nonGlobalStepDefinitions): .features files now work with webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian De Ro committed Jul 2, 2020
1 parent 7d4a3d5 commit 65ee0a4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 37 deletions.
14 changes: 10 additions & 4 deletions lib/featuresLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ const createCucumber = (
var moduleCache = arguments[5];
function isWebpack(){
return !!require.cache;
}
// Stolen from https://github.com/browserify/browserify/issues/1444
function clearFromCache(instance)
function clearFromCacheBrowserify(instance)
{
for(var key in moduleCache)
if(isWebpack()) return;
for(const key in moduleCache)
{
if(moduleCache[key].exports == instance)
{
delete moduleCache[key];
return;
}
}
throw "could not clear instance from module cache";
throw new Error("could not clear instance from browserify module cache");
}
${globalToRequire.join("\n")}
Expand Down Expand Up @@ -70,7 +76,7 @@ module.exports = function(_, filePath = this.resourcePath) {
if (isNonGlobalStepDefinitionsMode()) {
nonGlobalStepDefinitionsToRequire = features.map(featurePath => ({
[featurePath]: getStepDefinitionsPaths(featurePath).map(
sdPath => `clearFromCache(require('${sdPath}'))`
sdPath => `clearFromCacheBrowserify(require('${sdPath}'))`
)
}));
} else {
Expand Down

0 comments on commit 65ee0a4

Please sign in to comment.