blanket icon indicating copy to clipboard operation
blanket copied to clipboard

Please restore require.extensions['.js']

Open pmendelski opened this issue 10 years ago • 4 comments

Hi,

I'm using blanket.js for test coverage. It's a great tool - thanks!

Although I found some minor bug.

Scenario: I want to run instrumnted tests. If they fail I would like to rerun the tests but without instrumentalization. I'm using grunt with grunt-mocha-test plugin like this:

    mochaTest: {
        options: {
            reporter: 'spec'
        },
        functional: {
            src: [paths.test + '/functional/**/*test.js']
        },
        integration: {
            src: [paths.test + '/integration/**/*test.js']
        },
        unit: {
            src: [paths.test + '/unit/**/*test.js']
        },
        testcov: {
            options: {
                require: paths.test + '/blanket',
                clearRequireCache: true
            },
            src: [paths.test + '/**/*test.js']
        },
        coverage: {
            options: {
                reporter: 'html-cov',
                quiet: true,
                captureFile: paths.tmp + '/coverage.html'
            },
            src: [paths.test + '/**/*test.js']
        }
    },

I created a grunt task that executes this scenario and in case of testcov error runs not instrumented tests. Although because of line 128 in blanket/src/index.js (blanket version 1.1.6) once instumented tests stayed instrumented for all other tasks.

    require.extensions['.js'] = function(localModule, filename) { ... } // Please restore it after tests execution!

Fix I had to restore require.extensions['.js'] function manually to fix it. I think you could do the same in blanket to prevent this strange situation.

Cheers!

pmendelski avatar Feb 28 '14 10:02 pmendelski

Good point, I have spent quite some time to find out that clearing require.cache is not enough. It would be great to describe how blanket works under the hood (just few sentences in documentation).

BTW. I also noticed that require.extensions is deprecated. Do you have any idea on how to replace it with different mechanism?

And of course many thanks for creating and supporting blanket. It is really great!

bsodzik avatar Feb 28 '14 10:02 bsodzik

related to our prob here? : https://github.com/thlorenz/proxyquire/issues/33

dynnamitt avatar May 14 '14 11:05 dynnamitt

@bsodzik can you say more about why clearing require.cache was insufficient to solve your problems? Clearing it in my require.extensions handler fixed a similar problem that I was having.

danvk avatar Feb 11 '15 18:02 danvk

@danvk, besides clearing require.cache we also had to restore require.extensions['.js'] after blanket had finished its work (as @mendlik mentioned in his post). Now I see that blanket provides method restoreNormalLoader which is doing exactly what we implemented in our code. Unfortunately, back in February 2014 there was neither a documentation for that method nor a good soul to tell us about its existence.

What is a little bit worrying is that there is still no documentation for restoreNormalLoader. Maybe that method is not needed any more, but it still exists in blanket code..

bsodzik avatar Feb 18 '15 15:02 bsodzik