Giter Site home page Giter Site logo

Comments (19)

plasticine avatar plasticine commented on May 14, 2024 10

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.

jonira avatar jonira commented on May 14, 2024 6

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.

tomazzaman avatar tomazzaman commented on May 14, 2024 5

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.

plasticine avatar plasticine commented on May 14, 2024 1

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.

KidkArolis avatar KidkArolis commented on May 14, 2024 1

I think webpack can also do the watching - just make sure karma.config.js contains webpack: {watch: true}.

from karma-webpack.

sokra avatar sokra commented on May 14, 2024
// test_index.js
var testsContext = require.context(".", true, /_test.js$/);
testsContext.keys().forEach(testsContext);

This reads all tests and require them...

from karma-webpack.

luxx avatar luxx commented on May 14, 2024

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.

KidkArolis avatar KidkArolis commented on May 14, 2024

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.

KidkArolis avatar KidkArolis commented on May 14, 2024

I've made a PR with updated docs at #25. Let me know what you think.

from karma-webpack.

damassi avatar damassi commented on May 14, 2024

@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.

plasticine avatar plasticine commented on May 14, 2024

that watch update you made saved the day.

Awesome :D

from karma-webpack.

kentor avatar kentor commented on May 14, 2024

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.

damassi avatar damassi commented on May 14, 2024

@kentor, the watch doesn't detect new files, but changes to existing files.

from karma-webpack.

KidkArolis avatar KidkArolis commented on May 14, 2024

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.

jonira avatar jonira commented on May 14, 2024

@KidkArolis thanks for the info. After I recreated the setup and installed latest packages, Karma started working.

from karma-webpack.

wbecker avatar wbecker commented on May 14, 2024

Had the same issue, think upgrading webpack to 1.11 from 1.10.5 solved the issue. Thanks Karo!

from karma-webpack.

martijnarts avatar martijnarts commented on May 14, 2024

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.

robinelvin avatar robinelvin commented on May 14, 2024

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.

luchillo17 avatar luchillo17 commented on May 14, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.