Angular Karma e2e with Grunt - angularjs

I am trying to test
In the grunt file
karma: {
e2e: {
configFile: 'karma-e2e.conf.js',
singleRun: true
}
},
Karma file is basically what Yeoman generated for me. Only change is I swithed Chrome for PhantomJS.
karma-e2e.conf.js:
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
'test/e2e/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
I have a very basic test I try to run
describe('E2E: Testing Routes:', function () {
'use strict';
beforeEach(function() {
browser().navigateTo('/');
});
it('test', function() {
browser().navigateTo('#/');
expect(browser().location().path()).toBe("/list_persons");
});
})
This is the output from the test. I googled this error and it suggested that I add a "sleep" in my test. That does not sound like a solution for me.
> Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://local:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket i0eExVxerWfwrirxJXue with id 46269744
PhantomJS 1.9.7 (Linux): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.7 (Linux) E2E: Testing Routes: should jump to the /videos path when / is accessed FAILED
TypeError: 'undefined' is not a function (evaluating '$document.injector()')
PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.068 secs / 0.077 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.
Can anyone help me. What I want to do is to run e2e tests from grunt in PhantomJS.It does not have to be on a listener for filechanges. One simple run on "grunt test" is perfect.
Edit: I changed files to include
files: [
'app/vendor/scripts/angular.js',
'app/vendor/scripts/angular-mocks.js',
'app/vendor/scripts/angular-route.js',
'app/vendor/scripts/jstd-scenario-adapter-config.js',
'app/vendor/scripts/jstd-scenario-adapter.js',
'app/vendor/scripts/angular-scenario.js',
'test/e2e/**/*.js'
],
Now getting this:
Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket ZbZbabDGNCtvVa4Z-LQk with id 99494524
PhantomJS 1.9.7 (Linux): Executed 0 of 0 ERROR (0.036 secs / 0 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.

You have to add this:
singleRun: true,
To your karma config section in your grunt file.
Details:
https://github.com/karma-runner/grunt-karma

Related

karma chrome not loading.its giving up after two attempts

I'm integrating Jasmine and karma for unit testing my ionic app.
I'm following this blog.
When i run the karma start command i keep getting this result.
23 02 2017 16:39:18.508:WARN [karma]: No captured browser, open
23 02 2017 16:39:18.517:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
23 02 2017 16:39:18.517:INFO [launcher]: Launching browser Chrome with unlimited concurrency
23 02 2017 16:39:18.536:INFO [launcher]: Starting browser Chrome
23 02 2017 16:40:18.537:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
23 02 2017 16:40:18.910:INFO [launcher]: Trying to start Chrome again (1/2).
23 02 2017 16:41:18.911:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
23 02 2017 16:41:19.357:INFO [launcher]: Trying to start Chrome again (2/2).
Tried with PhantomJS also
Same error
Launching browser PhantomJS with unlimited concurrency
23 02 2017 17:44:30.214:INFO [launcher]: Starting browser PhantomJS
23 02 2017 17:45:30.215:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
23 02 2017 17:45:30.238:INFO [launcher]: Trying to start PhantomJS again (1/2).
23 02 2017 17:46:30.239:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
23 02 2017 17:46:30.246:INFO [launcher]: Trying to start PhantomJS again (2/2).
23 02 2017 17:47:30.247:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
23 02 2017 17:47:30.254:ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up.
Config
// Karma configuration
// Generated on Thu Feb 23 2017 10:39:27 GMT+0530 (IST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'../www/lib/ionic/js/ionic.bundle.js',
'../www/js/**/*.js',
'../tests/unit-tests/**/*.js',
'../node_modules/angular-mocks/angular-mocks.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// browsers: ['PhantomJS'],
browsers: ['Chrome'],
// customLaunchers: {
// Chrome_no_sandbox: {
// base: 'Chrome',
// flags: ['--no-sandbox']
// }
// },
plugins:[
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-chrome-launcher'
],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
})
}
Please help
Thanks!
This is the top Google result for this question, so even though it's old I hope my answer helps someone.
In our case the issue was caused by multiple files importing from the wrong library. This seems strange since you would think that Karma would throw an error rather than just refusing to open Chrome, but altering our import statements got us past the issue.
import { ChangeDetectionStrategy } from "#angular/core";
NOT AS OUR FILES HAD IT: import { ChangeDetectionStrategy } from "#angular/compiler/src/core";
This says you should try add the below code to karma.conf.js file:
browsers: ['Chrome_no_sandbox'],
customLaunchers: {
Chrome_no_sandbox: {
base: 'Chrome',
flags: ['--no-sandbox']
}
}
Try increasing browserDisconnectTolerance. Reasons could be different, from the wrong path in karma.config to some flaky npm run.

Angular injector mod error in Karma

Getting the following error when I try and run karma and jasmine on a new project
INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket RZqL_zkgcfP2w13UEtJj with id 40849718
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
Error: [$injector:nomod] http://errors.angularjs.org/1.5.5/$injector/nomod?p0=brainiacLms
at /Users/christianeckenrodework/Sites/brainiac/bower_components/angular/angular.min.js:25
This is my karma config
# // Karma configuration
# // Generated on Fri May 13 2016 16:53:01 GMT-0400 (EDT)
module.exports = (config) ->
config.set
basePath: './'
frameworks: [ 'jasmine' ]
files: [
'bower_components/angular/angular.min.js'
'bower_components/angular-mocks/angular-mocks.js'
'web/app.coffee'
'web/controllers/*.coffee'
'test/**/*.coffee'
]
exclude: []
preprocessors: {
'test/**/*.coffee': [ 'coffee' ]
'web/**/*.coffee': [ 'coffee' ]
}
reporters: [ 'progress' ]
port: 9876
colors: true
logLevel: config.LOG_INFO
autoWatch: true
browsers: [ 'PhantomJS' ]
singleRun: false
concurrency: Infinity
As far as I can tell the issue seems to be that it cant find my app module?
Found the answer: the reason my test threw the injector error is because I wasn't including all of my applications dependencies in my karma.conf.js file
I think you'll need to update your configuration file and use a files array like this:
files: [
// bower:js
'bower_components/angular/angular.min.js'
'bower_components/angular-mocks/angular-mocks.js'
// more bower dependences here...
// endbower
'web/app.coffee',
'web/**/*.coffee',
'web/**/*.html',
'test/**/*.coffee',
]
Just make sure include all your script and template files in your configuration file.
Also, if you're using Grunt or Gulp you can inject bower_components automatically in your Karma configuration.

Jasmine-Jquery not loading JSON file

I am learning writing unit test using Karma-Jasmine for my application build on AngularJs. I want to load test data from a json file. I am using Jasmine-Jquery to read json fixtures. In my karma config file I have following:
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
//dependencies...
'../bower_components/jquery/dist/jquery.js',
'../bower_components/angular/angular.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../bower_components/angular-route/angular-route.js',
// main module app.js.
'../public/app.js',
//all the controllers
'../public/app/controllers/CalculatorCtrl.js',
'../public/app/controllers/ScenaryCtrl.js',
//test dependencies...
'../bower_components/jasmine-jquery/lib/jasmine-jquery.js',
//pattern to include all the test files...
'../public/app/**/*Spec.js',
// JSON fixture
{
pattern: '../public/app/**/*.json',
watched: true,
served: true,
included: false }
],
In my spec file I am doing this:
beforeEach(function(){
jasmine.getJSONFixtures().fixturesPath = 'public/app/controllers/test/fixtures/';
var data=getJSONFixture('myjsonfixtures.json');
console.log(data);
});
When I run test cases I get following error in console:
18 09 2015 18:02:03.841:INFO [Chrome 45.0.2454 (Windows 8.1 0.0.0)]: Connected on socket 1bzPssO0gtZ_lqHlAAAA with id 52911560
Chrome 45.0.2454 (Windows 8.1 0.0.0): Executed 0 of 2 SUCCESS (0 secs / 0 secs)
18 09 2015 18:02:04.288:WARN [web-server]: 404: /public/app/controllers/test/fixtures/myjsonfixtures.json?_=1442579524156
Chrome 45.0.2454 (Windows 8.1 0.0.0) ERROR
Uncaught Error: JSONFixture could not be loaded: public/app/controllers/test/fixtures/myjsonfixtures.json (status: error, message: undefined)
at G:/My%20Temp%20Angular/Calculator/Karma%20with%20Jasmine/bower_components/jasmine-jquery/lib/jasmine-jquery.js:260
Chrome 45.0.2454 (Windows 8.1 0.0.0): Executed 0 of 2 ERROR (0.089 secs / 0 secs)
I don't know why the data is not getting loaded. I am not able to catch what I am missing.

WARN [web-server]: 404: /views/nav/offline.html

Anyone knows how to solve/remove this very annoying WARNING?
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.23 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket rrNTMtmcd322dIl7A9fa with id 95590782
WARN [web-server]: 404: /views/nav/offline.html
WARN [web-server]: 404: /views/scan/scan.qr.html
karma.conf.js
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-08-26 using
// generator-karma 0.8.3
module.exports = function (config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-local-storage/angular-local-storage.js',
'bower_components/ionic/release/js/ionic.js',
'bower_components/ionic/release/js/ionic-angular.js',
'app/scripts/**/*.js',
'test/spec/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS'
],
// Which plugins to enable
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine'
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
app.js
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
// ACCOUNT
.state('account', {
abstract: true,
url: '/account',
templateUrl: 'index.html'
})
.state('account.main', {
url: '',
templateUrl: 'views/account/account.main.html'
})
.
.
.
// MENU
.state('menu', {
abstract: true,
url: '/menu',
templateUrl: 'views/nav/menu.html'
})
.state('menu.main', {
url: '/main',
views: {
'menuContent': {
templateUrl: 'views/dash/dash.main.html'
}
}
})
.
.
.
// OFFLINE MENU
.state('offline', {
abstract: true,
url: '/offline',
templateUrl: 'views/nav/offline.html'
})
.state('offline.product', {
url: '/product',
views: {
'menuContent': {
templateUrl: 'views/product/product.list.html'
}
}
})
.state('offline.qr', {
url: '/qr',
views: {
'menuContent': {
templateUrl: 'views/scan/scan.qr.html'
}
}
})
.state('offline.cart', {
url: '/cart',
views: {
'menuContent': {
templateUrl: 'views/cart/cart.list.html'
}
}
})
;
$urlRouterProvider.otherwise('/account');
})
I have also tried this related issue:
how to fix 404 warnings for images during karma unit testing
With no luck.
More Info
I have also tried the following:
1) Adding path to html:
'app/scripts/**/*.js',
'app/views/**/*.html',
'test/spec/**/*.js'
2) Create pattern:
'app/scripts/**/*.js',
'test/spec/**/*.js',
{pattern: 'app/views/**', watched: false, included: false, served: true}
3) Exclude the path to html files:
// list of files / patterns to exclude
exclude: ['app/views/**'],
But nothing works, the warning still exist. I'm assuming that this could be a bug?
Edit 1
I just did what Chad Robinson says, and the next warning is about missing index.html.
So what I did is this:
proxies: {
'/views/': '/app/views/',
'/index.html': '/app/index.html'
}
But there is still warning:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task
Running "newer:jshint:all" (newer) task
No newer files to process.
Running "newer:jshint:test" (newer) task
No newer files to process.
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:test" (concurrent) task
Running "compass:dist" (compass) task
directory .tmp/styles
write .tmp/styles/icomoon.css (0.007s)
write .tmp/styles/override.css (0.055s)
Running "compass:server" (compass) task
Done, without errors.
Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task
Running "newer:jshint:all" (newer) task
No newer files to process.
Running "newer:jshint:test" (newer) task
No newer files to process.
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:test" (concurrent) task
Running "compass:dist" (compass) task
directory .tmp/styles
write .tmp/styles/icomoon.css (0.007s)
write .tmp/styles/override.css (0.054s)
Running "compass:server" (compass) task
Done, without errors.
Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
File .tmp/styles/override.css created.
Running "connect:test" (connect) task
Started connect web server on http://localhost:9001
Running "karma:unit" (karma) task
C:\Grabhut.MobileApp\Grabhut\test\karma.conf.js:73
C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task
Running "newer:jshint:all" (newer) task
No newer files to process.
Running "newer:jshint:test" (newer) task
No newer files to process.
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:test" (concurrent) task
Running "compass:dist" (compass) task
directory .tmp/styles
write .tmp/styles/icomoon.css (0.007s)
write .tmp/styles/override.css (0.054s)
Running "compass:server" (compass) task
Done, without errors.
Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task
Running "newer:jshint:all" (newer) task
No newer files to process.
Running "newer:jshint:test" (newer) task
No newer files to process.
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:test" (concurrent) task
Running "compass:dist" (compass) task
directory .tmp/styles
write .tmp/styles/icomoon.css (0.007s)
write .tmp/styles/override.css (0.055s)
Running "compass:server" (compass) task
Done, without errors.
Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
File .tmp/styles/override.css created.
Running "connect:test" (connect) task
Started connect web server on http://localhost:9001
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.23 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket PFqYQtg4gwm4psBKKJ5T with id 70053285
PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0.001 secs / 0 secs)
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
Execution Time (2014-09-29 02:06:16 UTC)
concurrent:test 6.3s ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 78%
autoprefixer:dist 97ms ■■ 1%
connect:test 433ms ■■■■■■■■■ 5%
karma:unit 1.2s ■■■■■■■■■■■■■■■■■■■■■■■ 15%
Total 8.1s
C:\Grabhut.MobileApp\Grabhut>
What's wrong with Karma?
Edit 2
Karma.conf.js
See karama config update at the bottom:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-08-26 using
// generator-karma 0.8.3
module.exports = function (config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-local-storage/angular-local-storage.js',
'bower_components/ionic/release/js/ionic.js',
'bower_components/ionic/release/js/ionic-angular.js',
'app/scripts/**/*.js',
'test/spec/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'PhantomJS'
],
// Which plugins to enable
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine'
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
proxies: {
'/views/': '/app/views/',
'/index.html': '/app/index.html'
}
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
Based on your Karma config, it looks like you are running this from the root level of your project. But your application is in app/, and your templates are relative to that path... that is, you are accessing /views/nav/offline.html, not /app/views/nav/offline.html. Karma doesn't know what to do with this.
Try a proxy:
proxies = {
'/views/': '/app/views/'
};
This will tell Karma to treat /views/* requests as though they were for /app/views/*. Alternatively, you can move your configuration for Karma down a level, into app/ itself. Then change the include paths and other related items to the correct URLs and the problem will go away. (This is what I do.)

karma running angular test works on Chrome browser but not on PhantomJs

I'm running unit tests in my angular project, and this works fine if I run it with Chrome but, not so much and I use PhantomJS
I have a karma.config.js file like this:
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'lib/*.js',
'web/js/*.js',
'test/spec/*spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'junit'],
// the default configuration
junitReporter: {
outputFile: 'testResult/test-results.xml',
suite: ''
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
and like this (with Chrome) works
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 36.0.1985 (Windows 7)]: Connected on socket oi7YLBSbpVbZSiVI_BPs
Chrome 36.0.1985 (Windows 7): Executed 8 of 8 SUCCESS (0.238 secs / 0.019 secs)
but if I change the browser (to PhantomJS) gives an error
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket Uy390TQWuDGR2pCi_GRy
PhantomJS 1.9.7 (Windows 7) ERROR
TypeError: '[object NodeList]' is not a valid argument for
'Function.prototype.apply' (evaluating 'push.apply')
at C:/Users/Lino Simões/Documents/bitbucket/jenkins-test/lib/angular.js: 2594
PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0.131 secs / 0 secs)
Warning: Task "karma:unit" failed. Used --force, continuing.
so my question is, why does this work with Chrome but not with PhantomJs and what can I change to make it work with PhantomJS
The '[object NodeList]' is not a valid argument issue, when running in PhantomJS 1.x, is already fixed in angular.js v1.3.0-beta.14, see #7851
Try upgrading the angular.js to v1.3.0-beta.14 or newer.
PS. Another solution would be using PhantomJS 2

Resources