Comments (3)
Just declare your shims in your package. Browserify will only bundle it if you actually require it. You'll also need the depends
option:
"browserify": {
"transform": [
"browserify-shim"
]
},
"browser": {
"angular": "./bower_components/angular/angular.js",
"angular-mocks": "./bower_components/angular-mocks/angular-mocks.js"
},
"browserify-shim": {
"angular": {
"exports": "angular"
},
"angular-mocks": {
"depends": "angular"
}
}
For what it's worth though, I've moved entirely to the global config for several reasons. The main one is that I write a lot of reusable angular modules with CommonJS and then use them in Angular projects. If you use the path-based shim config, you have to rely on browserify to dedupe your modules and all modules that depend on Angular must use an identical version. Also you need to have bower installed globally and run bower i
as an install script for your reusable modules. It ends up being horribly unmaintainable and buggy.
As of #1 you can just stick angular and angular-mocks in the file array before your test glob and your bundle will be added after angular-mocks.
from karma-browserify.
Hi, thks for your answer.
I ended up leaving the all configuration for browserify in the package.config file.
Then in karma my files section looks like this
...
files: [
'./scripts/**/*.js'
],
...
I like to have my tests files along with the source code instead of a separate tests folder.
Finally my test start like this:
require('angular-mocks');
require('./app');
describe('myService', function () {
var service = null;
beforeEach(angular.mock.module('myApp'));
beforeEach(inject(function ($injector) {
service = $injector.get('myApp.myService');
}));
it('should exist', function () {
expect(service).toBeDefined();
});
it('add should succeed', function () {
expect(service.add(1, 3)).toBe(4);
});
it('sub should succeed', function () {
expect(service.sub(1, 3)).toBe(-2);
})
});
because angular-mocks has a dependency on it will also load angular.
This works like a charm.
The only thing (but it's not really an issue) is that i have to do angular.mock.module(...)
to load the module in the beforeEach
instead of classical module(...)
from karma-browserify.
That's a limitation born from the fact that Angular choose to export multiple things from angular-mocks. That concept isn't compatible with CommonJS where there's only one module.exports
. Browserify could do something clever and attach the exports to a base object but that's not really its place.
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.