Comments (19)
I should mention that the one down-side to this technique that I’ve noticed is that it breaks watch
mode for subsequently required files — only the test_index
will trigger a karma rebuild.
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 }
]
from karma-webpack.
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.
from karma-webpack.
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 mocha-runner.js
and run it with $ babel-node mocha-runner.js
The gist is pretty well documented, so you shouldn't have any major problems understanding it.
from karma-webpack.
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.
from karma-webpack.
I think webpack can also do the watching - just make sure karma.config.js
contains webpack: {watch: true}
.
from karma-webpack.
// test_index.js
var testsContext = require.context(".", true, /_test.js$/);
testsContext.keys().forEach(testsContext);
This reads all tests and require them...
from karma-webpack.
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.
from karma-webpack.
Actually, watching with webpack is better since the tests will be rerun only once - after webpack rebuilds test_index.js
.
Watching with karma means that karma will run tests upon change some_test.js
and after webpack rebuilds the test_index.js
from karma-webpack.
I've made a PR with updated docs at #25. Let me know what you think.
from karma-webpack.
@plasticine, that watch
update you made saved the day. Went from 10+ seconds to compile on each change down to about 500ms 👍
from karma-webpack.
that watch update you made saved the day.
Awesome :D
from karma-webpack.
Hmm I tried both { pattern: 'test/**/*_test.*', included: false, served: false, watched: true }
and adding watch: true
to the webpack config. neither way detects a new test file for me
from karma-webpack.
@kentor, the watch
doesn't detect new files, but changes to existing files.
from karma-webpack.
I had that issue yesterday..
Try upgrading karma, karma-webpack and webpack to the latest versions and
see if the issue persists. There was some breaking change somewhere
recently.
On Tue, 4 Aug 2015 11:53 jonira [email protected] wrote:
I'm having the following issue: karma start ends up with error: Uncaught
ReferenceError: require is not defined for my test_index.js—
Reply to this email directly or view it on GitHub
#23 (comment)
.
from karma-webpack.
@KidkArolis thanks for the info. After I recreated the setup and installed latest packages, Karma started working.
from karma-webpack.
Had the same issue, think upgrading webpack to 1.11 from 1.10.5 solved the issue. Thanks Karo!
from karma-webpack.
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.
@jonira did you ever find a solution for this issue?
from karma-webpack.
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:
karma 1.3.0
karma-webpack 1.8.0
webpack 1.13.3
from karma-webpack.
@robinelvin Same here, i have karma-webpack
configured and it indeed doesn't recompile the tests.
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:
karma 1.4.1
karma-webpack 2.0.2
webpack 2.2.0
from karma-webpack.
Related Issues (20)
- karma-webpack 5.0 No longer notified of compilation starting HOT 2
- Cannot read property 'entry' of undefined
- Cannot read property 'entry' of undefined
- karma-webpack 5 fails to read files with a query parameter (e.g. font-awesome) HOT 6
- 5.0 crashes on MacOS (Preprocessor, Plugin), fixed on master -> Release 5.1? HOT 7
- Trying to add karma-webpack to angular karma config HOT 2
- karma.conf.js being treated as entrypoint results in many errors from webpack 5 HOT 2
- Webpack Errors being reported twice.
- Process is not defined HOT 1
- Error during file loading or preprocessing HOT 7
- Webpack file cache isn't generated when webacpack watch option is false/nothing
- karma-webpack does not respect webpack mode = "production" HOT 3
- I have the same problem. HOT 1
- preprocessor change between v4 & v5 leading to error when used with karma-mocha HOT 15
- Issue with Webpack 5 unable to find file 404 (works with webpack 4) HOT 1
- Don't warn overriding [name].js to [name].js
- Figure out a publishing Github Workflow
- Ensure all project dependencies have no auditing issues
- Provide a migration path from karma-webpack
- Update the README.md
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-webpack.