Karma tests don't run - tdd

I am trying to execute a web app that I developed. The web app is hosted in Weblogic and has the following access URL:
http://localhost:7001/webapp/
The problem I have is that the test are not being executed, it is only popping up a Firefox window where I can see "Karma v0.12.28 - connected". This is my karma.conf.js file:
// Karma configuration
// Generated on Fri Mar 21 2014 15:43:33 GMT+0000 (GMT)
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: './',
// frameworks to use
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: [
{pattern: 'src/webapp/javascript-webapp/**/*.hb', included: false, watched: false, served: true},
{pattern: 'src/webapp/xsltforms/xsltforms.js', included: false, watched: false, served: true},
{pattern: 'src/webapp/xsltforms/utils/exsltforms/exsltforms.js', included: false, watched: false, served: true},
{pattern: 'src/webapp/xsltforms/utils/ckeditor/ckeditor.js', included: false, watched: false, served: true},
{pattern: 'src/webapp/javascript-webapp/**/*.js', included: false},
{pattern: 'src/webapp/test/jasmine-tests/**/*.js', included: false},
{pattern: 'src/webapp/test/jasmine-tests/fixtures/*.html', included: false},
'karma-main.js'
],
// list of files to exclude
exclude: [
//Broken Tests?
'src/webapp/test/jasmine-tests/form/jasmine.forms.js',
'src/webapp/test/jasmine-tests/stepeditor/jasmine.tabsview.js',
'src/webapp/test/jasmine-tests/mobile/jasmine.webapp.appcachelistener.js',
'src/webapp/test/jasmine-tests/jasmine.webapp.richtexteditorconfig.js',
'src/webapp/test/jasmine-tests/group/casenote/views/jasmine.casenoteeditordialogview.js'
],
preprocessors: {
'**/*.html': []
},
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress', 'junit'],
junitReporter: {
outputFile: 'target/test-reports/jasmine-results.xml'
},
// web server port
//port: 9876,
port: 7001,
runnerPort: 9000,
// 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, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Firefox'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 600000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
Any hint?
Thanks.

Related

Setting up Jasmine: Getting undefined is not an object in jasmine.js

I am trying to do the initial set up of jasmine to write unit tests for my code. When I run 'karma start unit-tests.conf.js' I keep encountering this error:
I am not sure what it means. If you can't read the error it goes like this:
PhantomJS 2.1.1 (Windows 8 0/0/0) Error
TypeError: undefined is not an object (evaluating 'spacDefinitions.length')
at C:/Users/GoogleDrive/.../node_modules/jasmine-core/lib/jasmine-core/jasmine.js:830
Below is my config file. Did I not configure it correctly? Is there anything I am missing?
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/ionic/js/ionic.bundle.js',
'lib/angular-mocks/angular-mocks.js',
'js/*',
'index.controller.js',
'layout/mainView.directive.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'],
// 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
})
}
Thank you for any help!
In your karma config i don't see entry for angular.min.js in 'files' section. replace your files section with:-
files: [
'lib/ionic/js/ionic.bundle.js',
'lib/angular.min.js',
'lib/angular-mocks/angular-mocks.js',
'js/*',
'index.controller.js',
'layout/mainView.directive.js',
],
Assuming angular.min.js is placed in lib folder.
It should work.

nwjs and karma-mocha not playing nice

I am having issues testing my NW.js app using Karma. Tests that used to work now don't after updating ??? (I'm not sure which update killed me)
START:
13 07 2016 08:33:30.517:INFO [karma]: Karma v1.1.1 server started at http://localhost:9876/
13 07 2016 08:33:30.519:INFO [launcher]: Launching browser NodeWebkitTest with unlimited concurrency
13 07 2016 08:33:30.531:INFO [launcher]: Starting browser node-webkit
13 07 2016 08:33:36.221:INFO [Chrome 41.0.2272 (Windows 7 0.0.0)]: Connected on socket /#6fJGXLlwDNlOGXukAAAA with id 21855637
Chrome 41.0.2272 (Windows 7 0.0.0) ERROR
Uncaught TypeError: Cannot read property 'setup' of undefined
at C:/Users/ethomps2/IdeaProjects/evidentia3/node_modules/karma-mocha/lib/adapter.js:209
Finished in 0.331 secs / 0 secs
At the point in the adapter where it is failing, the adapter is looking for window.mocha.
Here is my karma config:
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: ['mocha', 'chai', 'sinon'],
'plugins': [
'karma-nodewebkit-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-coverage',
'karma-mocha-reporter'
],
// list of files / patterns to load in the browser
files: [
<my code including test files>
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../build/js/controllers/*.js': ['coverage'],
'../build/js/services/*.js': ['coverage'],
'../build/js/filters/*.js': ['coverage'],
'../build/js/directives/*.js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
// 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: ['NodeWebkitTest'],
customLaunchers: {
'NodeWebkitTest': {
base: 'NodeWebkit',
paths: ['node_modules'],
options: {
"name": "Evidentia",
"main": "index.html",
"description": "Evidence management software for your genealogy research",
"version": "3.0.0",
"ver": "300",
"webkit": {
"page-cache": false
},
"window": {
"title": "Evidentia",
"icon": "img/Evidentia128x128.png",
"toolbar": true,
"frame": true,
"width": 1100,
"height": 700,
"show": false
}
}
}
},
// optionally, configure the reporter
coverageReporter: {
type: 'html',
dir: '../coverage/',
instrumenterOptions: {
istanbul: {noCompact: true}
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
};
As you can see I am using karma-nodewebkit-launcher as my browser. My understanding was that nwjs global got linked to the window.
Use karma-nodewebkit-mocha in your project.
See https://github.com/karma-runner/karma-mocha/issues/184 for more details.

testing angular app using karma and jasmine having error:

I am new to angular.js. I am trying to run Karma unit tests for my application but have found a lot of problems as it expects I install all required dependencies like node.js, npm, karma etc.
Now when i goto the my project directory and run this command karma start karma i have this error:
C:\wamp\www\First-angular-App>karma start karma.conf
ERROR [config]: Invalid config file!
SyntaxError: Unexpected string
karma.conf
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
exclude: [ ],
files: [ 'First-angular-App/source/index.html', 'First-angular-App/source/myApp.js' 'First-angular-App/source/myAppCtrl.js' ]
preprocessor
preprocessors: { },
reporters: ['progress'],
port: 9876,
colors: true,
config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
changes
autoWatch: false,
launcher browsers: ['Chrome'],
singleRun: true
});
};
Why its giving me the error invalid config file ?
Probably it should looks like - please take a look for two comments added to configuration.
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
exclude: [ ],
files: [ 'First-angular-App/source/index.html', 'First-angular-App/source/myApp.js', 'First-angular-App/source/myAppCtrl.js' ],
// preprocessor - mark this as comment
preprocessors: { },
reporters: ['progress'],
port: 9876,
colors: true,
// config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - one more comment
logLevel: config.LOG_INFO,
// changes - mark this as comment
autoWatch: false,
// launcher
browsers: ['Chrome'],
singleRun: true
});
};

No provider for Jasmine-jquery?

I'm using Yeoman+Angular Generator for my application and I have been running around hard to get along with Jasmine! This is where I am stuck. I want to be able to use jQuery selectors with Jasmine tests. I have installed the karma-jasmine and karma-jasmine-jquery packages. Then I installed it for bower (I'm new and I have no idea what should be installed for what!). I have manually added the path in my karma.conf.js, but I still get the message that says this:
Running "karma:unit" (karma) task
Warning: No provider for "framework:jasmine-jquery"! (Resolving: framework:jasmine-jquery) Use --force to continue.
This is how my karma config looks like:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-09-12 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-jquery', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
'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-bootstrap/ui-bootstrap.js',
'app/scripts/**/*.js',
//'test/mock/**/*.js',
'test/spec/**/*.js',
'app/views/*.html'
],
// 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',
'karma-ng-html2js-preprocessor'
],
preprocessors: {
'app/views/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
stripPrefix: 'app/',
moduleName: 'views'
},
// 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_'
});
};
I had the same problem as this. Fixed it by adding karma-jasmine-jquery to the plugins array in karma.conf.js. This is my karma.conf in full.
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-jquery', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/scripts/**/*.js',
'test/mock/**/*.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-jquery',
'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_'
});
};
The other change I made is that as per the jasmine-jquery docs it requires jasmine version of at least 0.2.0. The generator gives version of 0.1.5 (at least it did for me yesterday). So to fix this I ran 'npm install karma-jasmine#0.2.0 --save-dev'. The save dev should do this but make sure you have the correct packages listed in the devDependencies in the root package.json for me I have:
"karma-jasmine": "^0.2.0",
"karma-jasmine-jquery": "^0.1.1",
Obviously these should correspond with the actual packages in node-modules
Hope it helps
C

Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?

I'm trying to run my karma (version v0.10.2) unit tests on teamcity (version 7.1).
When I run karma start --reporters teamcity --single-run I get the following error:
Can not load "teamcity", it is not registered! Perhaps you are missing some plugin?
I have installed the karma-teamcity-reporter module, but that hasn't helped.
The following are installed in my local node_modules folder:
karma
karma-chrome-launcher
karma-coffee-preprocessor
karma-coverage
karma-firefox-launcher
karma-html2js-preprocessor
karma-jasmine
karma-phantomjs-launcher
karma-requirejs
karma-script-launcher
karma-teamcity-reporter
Here is my karma.conf.js:
I'm running karma version v0.10.2. Here's my karma.conf.js:
module.exports = function(karma) {
karma.set({
// base path, that will be used to resolve files and exclude
basePath: '../../myapplication.web',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
// list of files / patterns to load in the browser
files: [
'Scripts/jquery/jquery-2.0.2.min.js',
'Scripts/jquery-ui/jquery-ui-1.10.3.min.js',
'Scripts/daterangepicker/daterangepicker.js',
'Scripts/angular/angular.js',
'Scripts/angular/restangular/underscore-min.js',
'Scripts/angular/restangular/restangular-min.js',
'Scripts/angular/angular-*.js',
'Scripts/angular/angular-test/angular-*.js',
'Scripts/angular/angular-ui/*.js',
'Scripts/angular/angular-strap/*.js',
'Scripts/angular/angular-http-auth/*.js',
'Scripts/sinon/*.js',
'Scripts/moment/moment.min.js',
'uifw/scripts/ui-framework-angular.js',
'app/app.js',
'app/**/*.js',
'Tests/unit/**/*.js'
],
// list of files to exclude
exclude: [
'Scripts/angular/angular-test/angular-scenario.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress', 'coverage', 'teamcity'],
preprocessors : {
'app/**/*.js': ['coverage']
},
coverageReporter : {
type: 'html',
dir: 'Tests/coverage/'
},
// web server port
port : 9876,
// cli runner port
runnerPort : 9100,
// enable / disable colors in the output (reporters and logs)
colors : true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel : karma.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch : true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout : 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun : true
});
};
If I run karma start karma.conf.js it runs correctly. What am I doing wrong?
Turned out I needed to add karma-teamcity-reporter to the plugins section to get this to work:
...
plugins: [
'karma-teamcity-reporter',
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
...

Resources