Comments (11)
Did a little investigation and this would have worked with karma-bro < 0.7
from karma-browserify.
So the reason this is happening is that the bundle gets reset on rebuilds:
https://github.com/Nikku/karma-browserify/blob/master/lib/bro.js#L208
Immediate fix is to do this in prebundle
:
bundle.require('./foo', {expose: 'foo'});
bundle.on('reset', function () {
bundle.require('./foo', {expose: 'foo'});
});
external
among other bundle configuration calls is not reset on reset
. Technically running prebundle
on every run wouldn't break anything but it would balloon arrays like b._external with long running watchify instances. I think the answer here is to provide an extra hook that runs on every bundle
call but I'll wait on @nikku's thoughts before we ship anything.
from karma-browserify.
Thanks for digging @bendrucker.
To pre-empt questions about why on earth I'd want or need to do this: I have a project, "foo", which contains some plugins. These plugins depend on "foo-plugintool", an external dependency which in turn depends on "foo". When testing, I'd like that require('foo')
to resolve back to the working copy of the project rather than the released version. Hope that makes sense.
from karma-browserify.
Haha, I already had an update for that behavior implemented but reverted it again because no reported a bug on it yet.
The intention during early karma-bro times was to actually be able to configure the whole bundle thing once. Too bad browserify nowadays resets file configurations and so forth.
My suggestion is: We fire a custom event users can listen to that resembles the configuration before actual bundling for the users:
bundle.on('prebundle', function () {
bundle.require('./foo', {expose: 'foo'});
});
We could then rename the actual method to something like configure
or the like to indicate manual configuration of browserify. Prebundle is definitely the wrong name for what it offers today.
from karma-browserify.
Looks like this is absolutely equivalent:
bundle.on('reset', function () {
bundle.require('./foo', {expose: 'foo'});
});
The initial configuration is not needed as we always reset the bundle prior to any bundling operations.
from karma-browserify.
You're right. Honestly I'm inclined to just document this. The gain from having a clearer event name isn't worth creating code that isn't portable (i.e. wouldn't work with regular watchify). configure
makes sense but would also mean a major version change.
from karma-browserify.
This sounds fine as far as it goes, but it seems that it introduces another related bug. If you do
bundle.on('reset', function () {
bundle.require('./foo', {expose: 'foo'});
});
then certainly require('foo')
works, but oddly require('./foo')
no longer does. This is at odds with the usual behaviour of browserify AFAICT. If I have foo.js
:
module.exports = 4;
and relative.js
:
var foo = require('./foo');
console.log("foo =", foo);
then I can still browserify this using
browserify -r ./foo.js:foo relative.js | node
and the relative require continues to work.
from karma-browserify.
This is related to #52 and a browserify/watchify bug. It looks as if watchify cannot handle files that are required using their relative path names and a global alias at the same time.
As much as I can tell there are two options to fix this, none of them is without pain.
from karma-browserify.
We are going to fix this in karma-browserify by exposing all files via their absolute path.
This is something watchify requires. In order for the above code to work, you should use
bundle.require('abs-path-to-foo', {expose: 'foo'});
from karma-browserify.
Forget what I posted before 😀.
The next version of karma-browserify will remove the prebundle hook in favor of a configure hook.
Users may hook into prebundle actions by listening to the prebundle
event.
Example configuration:
{
files: [ ],
preprocessors: [ ],
browserify: {
configure: function(b) {
b.on('prebundle', function() {
b.external('lib/external.js');
});
}
}
}
from karma-browserify.
Thank you! 🍰
from karma-browserify.
Related Issues (20)
- intellij karma runner doesn't use watchify for bundle rebuild HOT 3
- Cannot read property 'bundleFile' of undefined HOT 2
- Error: Cannot find module HOT 2
- Use global transforms HOT 4
- ERROR [framework.browserify]: Error: Cannot find module HOT 2
- attempting to use node-underscorify with karma-browserify fails HOT 2
- Missing repo nikku/node-browserify breaks older versions (<4.0) HOT 1
- Karma not working with Firefox(FirefoxHeadless) when loading with html page. HOT 1
- Unable to browserify file HOT 1
- Install issues due to browserify peerDependecy condition HOT 1
- karma-browserify HOT 1
- lodash vulnerability reported by "npm audit" HOT 1
- When packaged, my test coverage is always 100% HOT 4
- release with PhantomJS removed? HOT 1
- promisify is not a function HOT 2
- Using karma-browserify with WASM HOT 2
- Cannot use import statement outside a module only on karma-browserify HOT 3
- Support for Browserify v17 HOT 2
- Breaking change coming for karma-browserify/lib/preprocessor.js HOT 4
- Support watchify <= 4 HOT 2
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-browserify.