Code Monkey home page Code Monkey logo

Comments (6)

klaascuvelier avatar klaascuvelier commented on June 5, 2024

Thanks for bringing this to my attention.
I'm suspicious this is a configuration issue rather than a preprocessor issue, but I'll look into it asap.

from karma-rollup-preprocessor.

ccampbell avatar ccampbell commented on June 5, 2024

I am running into this same issue. When I have karma set to watch my test directory then any change to a test file cause it to be rebuilt with the rollup preprocessor, but changes to the src files imported by the test files are never recompiled. I have to manually kill and restart karma each time I change a src file which is very frustrating.

Any ideas on how to fix this?

from karma-rollup-preprocessor.

mjeanroy avatar mjeanroy commented on June 5, 2024

Same behavior here. When test file is updated, rollup preprocessor does its job perfectly, otherwise when an src file is updated, rollup preprocessor does not run at all (it seems to not be executed by karma).

@ccampbell A quick workaround, instead of restarting karma, is to save your test file again to force rollup preprocessor to do its magic again.

from karma-rollup-preprocessor.

ccampbell avatar ccampbell commented on June 5, 2024

@mjeanroy in my experience, that only works to recompile the test code and not the src code.

What I have found is that if my karma config is referencing {pattern: 'test/*-test.js'} in the files section then saving a src file does nothing, but a test file will rebuild the files in the test directory.

If my karma config is referencing {patten: 'test/specificfile-test.js'} in the files section then saving a src file does nothing, but a test file will rebuild both the files in the test directory as well as the files in the src directory. So I have been using that when I want to have the tests run as I'm changing src code, but it is a bit annoying.

from karma-rollup-preprocessor.

brianmhunt avatar brianmhunt commented on June 5, 2024

This problem is picky. Here's a SO post I made on it as I've tried several workarounds.
I have also created a repository for demonstrating the issue.

from karma-rollup-preprocessor.

jlmakes avatar jlmakes commented on June 5, 2024

Edit: This has been fixed in the latest 3.0.0 release @CrowdHailer @ccampbell @mjeanroy.


I believe I've wrapped my head around the problem, thanks to @brianmhunt and his work.

Let's say we have 2 files:

// foo.js
export { data: 'bar' }
// foo.spec.js
import foo from './foo.js';

expect(foo).to.be.defined;

We would end up with a new temporary file served to the Karma browser, something like this:

// foo.spec.bundle.js
var foo = { data: 'bar' };

expect(foo).to.be.defined;

Rollup simply imports the contents of the files it finds in the import statement at the time of bundling. So when we change foo.js...

// foo.js
- export { data: 'bar' }
+ export { data: 'wunderbar' }

Karma will re-run our tests because we've set it up to watch all our files, but because foo.spec.js hasn't changed, our test bundle is still the same:

// foo.spec.bundle.js
var foo = { data: 'bar' };

expect(foo).to.be.defined;

But if we update foo.spec.js:

// foo.spec.js
import foo from './foo.js';

expect(foo).to.be.defined;
+expect(foo.data).to.equal('wunderbar');

It will trigger Rollup to re-bundle that file, and it will grab foo.js again (which has changed since the last time it bundled) and we'll get:

// foo.spec.bundle.js
var foo = { data: 'wunderbar' };

expect(foo).to.be.defined;
expect(foo.data).to.equal('wunderbar');

The reason @brianmhunt's PR solves this problem, is because it forces all bundles to be recompiled (by manually changing the modified and accessed times) when any of the files they import change.

So in our above example, when foo.js was changed, it would change the accessed and modified times of foo.spec.js, triggering Karma's watch handler to rebundle foo.spec.bundle.js 🎉

from karma-rollup-preprocessor.

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.