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 authored and lgandecki committed Jul 3, 2020
1 parent 7d4a3d5 commit 8b92ed3
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 38 deletions.
22 changes: 17 additions & 5 deletions lib/featuresLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@ const createCucumber = (
window.cucumberJson = ${JSON.stringify(cucumberJson)};
var moduleCache = arguments[5];
function clearFromCache(moduleId, instance){
if(isWebpack()){
delete require.cache[moduleId];
} else {
clearFromCacheBrowserify(instance);
}
}
function isWebpack(){
return !!require.cache
}
// Stolen from https://github.com/browserify/browserify/issues/1444
function clearFromCache(instance)
{
for(var key in moduleCache)
function clearFromCacheBrowserify(instance) {
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 +81,8 @@ module.exports = function(_, filePath = this.resourcePath) {
if (isNonGlobalStepDefinitionsMode()) {
nonGlobalStepDefinitionsToRequire = features.map(featurePath => ({
[featurePath]: getStepDefinitionsPaths(featurePath).map(
sdPath => `clearFromCache(require('${sdPath}'))`
sdPath =>
`clearFromCache(require.resolve && require.resolve('${sdPath}'), require('${sdPath}'))`
)
}));
} else {
Expand Down

0 comments on commit 8b92ed3

Please sign in to comment.