Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nonGlobalStepDefinitions): .features files now work with webpack #404

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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