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

when deleting cached file, do it recursively #36

Closed
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
23 changes: 15 additions & 8 deletions index.js
Expand Up @@ -4,6 +4,19 @@ var gutil = require('gulp-util');
var through = require('through2');
var Jasmine = require('jasmine');

function deleteRequireCache( id ) {
// recursively delete source code to be tested,
// but skip mature code loaded from node_modules
if(id.indexOf('node_modules') >= 0) return;
var files = require.cache[ id ];
if (typeof files !== 'undefined') {
for (var i in files.children) {
deleteRequireCache( files.children[i].id );
}
delete require.cache[ id ];
}
}

module.exports = function (options) {
options = options || {};

Expand Down Expand Up @@ -35,18 +48,12 @@ module.exports = function (options) {

/**
* Get the cache object of the specs.js file,
* get its children and delete the children cache
* delete it and its children recursively from cache
*/
var resolvedPath = path.resolve(file.path);
var modId = require.resolve(resolvedPath);
var files = require.cache[modId];
if (typeof files !== 'undefined') {
for (var i in files.children) {
delete require.cache[files.children[i].id];
}
}
deleteRequireCache( modId );

delete require.cache[modId];
jasmine.addSpecFile(resolvedPath);

cb(null, file);
Expand Down