-
Notifications
You must be signed in to change notification settings - Fork 60
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: don't run test/*.spec.js files automatically in Browsers #202
Conversation
For Browsers we use webpack. Karma will create a bundle for every file that is specified as entry point. This may take lots of resources (see ipfs-inactive/js-ipfs-http-client#683 for more information). The solution is to have only a single entry point, `test/browser.js`, which will then be responsible to create the bundle with all the tests. BREAKING CHANGE: Without bundling all tests in `test/browser.js` the tests might not run. The bundling can be done like this: // This is webpack specific. It will create a single bundle // out of all files ending in ".spec.js" within the "test" // directory and all its subdirectories. 'use strict' const testsContext = require.context('.', true, /\.spec\.js/) testsContext.keys().forEach(testsContext)
Codecov Report
@@ Coverage Diff @@
## master #202 +/- ##
=======================================
Coverage 78.16% 78.16%
=======================================
Files 6 6
Lines 142 142
=======================================
Hits 111 111
Misses 31 31 Continue to review full report at Codecov.
|
@vmx this is such a great find!!!!! ❤️ I say let's remove .spec.js all together and use node.js and browser.js as the entry points |
@diasdavid Well, my change makes browser.js the only entry point, though I don't think it's ideal. For webpack it will be just a file that globs all .spec.js files together. So it's the same as before (which I think makes sense), but sadly with another file. I wished it was possible differently, but I didn't find a way in Karma. |
I've uploaded an alternative idea: f7457f4 This illustrates what I was after, but it is really hacky and doesn't even work in all cases. I guess it could be done with a custom Karma preprocessor, but I'm not sure if it's worth it. |
Really this should be fixed in karma-webpack, e.g. there should be a config option for karma-webpack to either bundle all files or not. These hacks will work for some time and then break :( I think the alternative is the better approach and you can probably use some node builtins to search for the correct location of when executing the test, e.g injecting the correct files in |
@dignifiedquire If it's technically possible with Karma, that would be cool. Does it mean that a preprocessor can merge/bundle several files and Karma will see them as a single one? |
@@ -14,8 +14,7 @@ function getPatterns (ctx) { | |||
} | |||
|
|||
return [ | |||
'test/browser.js', | |||
'test/**/*.spec.js' | |||
'test/browser.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change as it is will break the assumption on tests everywhere.
To make this happen, we need to make it consistent (either use .spec for node and browser or for none) and we need updated docs.
After spending a lot of time of thinking and trying I think I found a viable, backwards compatible solution to the problem: f694aa6 (it's not 100% working yet, but I'm really close). |
If a project does define a |
I'd like to close this one in favour of #203. |
For Browsers we use webpack. Karma will create a bundle for every file
that is specified as entry point. This may take lots of resources (see
ipfs-inactive/js-ipfs-http-client#683 for more information).
The solution is to have only a single entry point,
test/browser.js
,which will then be responsible to create the bundle with all the tests.
BREAKING CHANGE: Without bundling all tests in
test/browser.js
thetests might not run. The bundling can be done like this: