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 karma is auto-watching files, karma-webpack causes tests to occasionally run twice, possibly OS X-only #44

Closed
alanchrt opened this issue Apr 1, 2015 · 5 comments

Comments

@alanchrt
Copy link

alanchrt commented Apr 1, 2015

I have a larger project set up using gulp with karma's watch to run tests on the fly.

I noticed that frequently when making updates to test files karma is watching, the tests get fired twice. After paring down my configurations, it looks like karma-webpack is the culprit.

I'm on OS X, so hopefully the repro works on whatever platform. Here are instructions/a barebones repo to isolate the issue and reproduce:

https://github.com/alanctkc/karma-webpack-watch-bug-repro#readme

Here's a comparison of the output I get simulating changes with and without the ['webpack'] preprocessor:

https://gist.github.com/alanctkc/79c2c4586f13f22bd8e6

Unfortunately, it doesn't seem to be super deterministic, so you might have to simulate changes a few times before seeing any duplicates. But, when the preprocessor is removed, there never seem to be any duplicate runs at all.

Any ideas?

@ColCh
Copy link

ColCh commented Apr 5, 2015

What if you add timeout ~ 400ms for watcher ?

@alanchrt
Copy link
Author

alanchrt commented Apr 7, 2015

Thanks, @ColCh. Bumping autoWatchBatchDelay up does help, and solves the immediate need for me.

Any ideas what about karma-webpack might trigger a change? Would just opening the JS files for reading be enough to cause it?

@dlindahl
Copy link

FWIW, this very same problem was reported in nikku/karma-browserify#67. The comment from @mattyfsh seems to have resolved the issue for me.

rogeriochaves added a commit to rogeriochaves/karma-webpack that referenced this issue Nov 28, 2015
This prevents specs from running twice every time a file changes, because the webpack already triggers a rerun when recompiled.

Thanks to this comment: codymikol#44 (comment)
randycoulman added a commit to CodingZeal/react-boilerplate that referenced this issue Jul 18, 2016
@joshwiens
Copy link
Contributor

Issue has multiple resolutions. Resolving

rogeriochaves added a commit to rogeriochaves/karma-webpack that referenced this issue Aug 1, 2016
This prevents specs from running twice every time a file changes, because the webpack already triggers a rerun when recompiled.

Thanks to this comment: codymikol#44 (comment)
joshwiens pushed a commit that referenced this issue Aug 3, 2016
* Do not let karma watch files

This prevents specs from running twice every time a file changes, because the webpack already triggers a rerun when recompiled.

Thanks to this comment: #44 (comment)

* Removed array wrapping and default options

* Removed extra colon
@milimetric
Copy link

I got my config to work (it no longer runs tests twice) based on the browserify example mentioned above. Here it is for clarity:

{
    ...

    frameworks: ['jasmine-ajax', 'jasmine'],

    files: [{
        pattern: './test/**/*.spec.js',
        watched: false,
        included: true,
        served: true
    }],

    preprocessors: {
        './test/**/*.spec.js': ['webpack']
    }
}

ohdyno pushed a commit to ohdyno/dcpFcsRpsApp that referenced this issue Feb 20, 2018
The cause for this is not clearly understood.  However, the hypothesis
is that karma and webpack both are watching the files.
The fix seems to be the same as presented here:
codymikol/karma-webpack#44
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

No branches or pull requests

5 participants