-
Notifications
You must be signed in to change notification settings - Fork 220
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
Producing a single test bundle #23
Comments
// test_index.js
var testsContext = require.context(".", true, /_test.js$/);
testsContext.keys().forEach(testsContext); This reads all tests and require them... |
I was running into this same issue but the solution by @sokra worked for me karma.conf.js: config.set({
...
files: [
'test/helpers/**/*.{coffee,js}',
'test/test_index.js'
],
preprocessors: {
'test/test_index.js': ['webpack']
}, test_index.js: // load all specs into one bundle
var testsContext = require.context(".", true, /_spec.coffee$/);
testsContext.keys().forEach(testsContext); Personally I think it is a better default to have one bundle for all the test files. For our unit test specs, we always require the files that are needed for that spec file to execute. Because each spec has it's own bundle, modules were being evaluated multiple times, and I did not realize it for a while. Maybe update the readme to be a bit more clear? For any sizable app, misconfiguring this will make tests much slower. |
This is an awesome tip, I really think it might be worth mentioning this in the README. This really saved us — we were rocking ~75MB of test code which was making testing really slow locally, and completely impossible to run remotely via something like Browserstack. |
I should mention that the one down-side to this technique that I’ve noticed is that it breaks Edit: I am an idiot :-)This works perfectly... files: [
'test/test_helper.js',
'test/test_index.js',
{ pattern: 'test/**/*_test.*', included: false, served: false, watched: true }
] |
I think webpack can also do the watching - just make sure |
Actually, watching with webpack is better since the tests will be rerun only once - after webpack rebuilds |
I've made a PR with updated docs at #25. Let me know what you think. |
@plasticine, that |
Awesome :D |
Hmm I tried both |
@kentor, the |
I'm having the following issue: Karma detects file changes, but executes the old version of the file. Terminating and restarting karma causes the changed version of the file to be executed. |
I had that issue yesterday.. Try upgrading karma, karma-webpack and webpack to the latest versions and On Tue, 4 Aug 2015 11:53 jonira [email protected] wrote:
|
@KidkArolis thanks for the info. After I recreated the setup and installed latest packages, Karma started working. |
Had the same issue, think upgrading webpack to 1.11 from 1.10.5 solved the issue. Thanks Karo! |
I may be late to the party, but I come bearing gifts :) The solution to this problem is to not use Karma at all (for unit tests that is). Or webpack for that matter. Here's the gist we use to run tests directly with Mocha: https://gist.github.com/tomazzaman/1e2c71e1afb6a45c1001 Save the file as The gist is pretty well documented, so you shouldn't have any major problems understanding it. |
@jonira did you ever find a solution for this issue? |
I have the same issue as @jonira had (and probably @TotempaaltJ too) in that changed files trigger the tests to reload but it executes the old code. I should add that my tests are written in Typescript and I don't see any output which tells me they are recompiled. I'm using a test_index.js which pulls in all the .ts files as recommended. Versions: |
@robinelvin Same here, i have Also saving the karma config triggers the reload, but doesn't update the configs (that makes a bit of sense since it is a config file, but the above doesn't). Versions: |
If I add
preprocessors: {'**/*_test.js': ['webpack']}
and I have 100s of tests, that produces 100s of large bundles - that's slow, reruns tests all the time since karma keeps detecting changes and rerunning all ests as each test bundle is produced by webpack and this sends many megabytes to the test browser to evaluate.Instead, if I add
preprocessors: {"test_index.js": ['webpack']}
and require all my tests in that file (e.g. here then webpack produces 1 test bundle. However, now I have to manually maintain the full list of all my tests which doesn't scale.I don't know enough about karma plugins or webpack yet, but do you reckon there's a way to configure webpack/karma/karma-webpack to produce ony 1 test bundle from a pattern such as
**/*_test.js
?Perhaps something like dynamically, via the karma-webapck plugin, adding configuration about which modules to force include even if they're not required (is there such option?)
The text was updated successfully, but these errors were encountered: