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

Conversation

floatinghotpot
Copy link
Contributor

deleting spec and its directly children is not enough. if a source code file required by its children, should also be reloaded.

so need delete recursively, but skip all files from node_modules, as they are regarded mature and not being modified.

Deleting direct children is not enough. If the changed file is required by its children, should also be cleared from cache and reloaded.
deleting file from cache is reloading and testing the source code, not any mature lib from node_modues.
@jbblanchet
Copy link
Contributor

Looks good to me. Like I mentioned in #32, I'm not sure how to test it. I'd really like to be able to put in an automated test. Maybe put a few dummy modules that depends on one another, have them increment a global variable, load them in the test runner, run a jasmine test file and check that the global variables have been incremented twice? But that seems overkill. Got any idea?

@floatinghotpot
Copy link
Contributor Author

i've manually tested this bugfix in my projects with console.log(), and it works fine.

here is how I test it.

in gulp-jasmine/index.js

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

in each of my source code file, the first line:

console.log('loading ' + __filename);

@jbblanchet
Copy link
Contributor

Yeah, I'm probably just a little paranoid with my automated testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants