Reputation: 495
I am building my angularjs app using grunt.I have created unit test suite for my application using karma.I am trying to setup continuous integration for my application.Before doing a CI in Jenkins,i was trying to build locally using grunt.
1.Copy all the files from app folders into dist (usually done by grunt task 'grunt build') 2.run unit tests on dist folder. 3.Build Artifacts.
I am looking for examples projects and couldn't find any on building test suites along with application using grunt?Any help for references would be great.
Do we have to run test on dist folder or on local app folder when building application using grunt?? Does karma.conf.js file should go into dist folder??
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:livereload',
'karma:continuous',
'apimocker',
'protractor:run'
]);
### Project structure;
myProject
|
|--app
| |--bower_components
| |--scripts
|
|--dist
| |--bower_components
| |--scripts
|
|--node_modules
|
|--test
| |--specs
|
|--gruntfile.js
|
|--karma.conf.js
grunt.registerTask('CI', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'ngmin',
'copy:dist',
'cdnify',
'cssmin',
'rev',
'usemin',
'test',
'buildArtifacts'
]);
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'requirejs'],
files: [
{pattern: 'app/bower_components/jquery/dist/jquery.js', included: false},
{pattern: 'app/bower_components/angular/angular.js', included: false},
{pattern: 'app/bower_components/angular-mocks/angular-mocks.js', included: false},
{pattern: 'app/bower_components/jasmine/lib/jasmine-core/jasmine.js', included: false},
{pattern: 'app/bower_components/jasmine-jquery/lib/jasmine-jquery.js', included: false},
{pattern: 'app/scripts/*.js', included: false},
{pattern: 'app/scripts/**/*.js', included: false},
{pattern: 'test/**/*Spec.js', included: false},
{pattern: 'test/test-main.js', included: true},
],
exclude: [
'app/scripts/main.js',
'app/scripts/*min.js',
'app/scripts/**/*min.js'
],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-script-launcher',
'karma-jasmine',
'karma-requirejs'
],
singleRun: false
}
);
};
Upvotes: 1
Views: 399
Reputation: 4611
Unit tests need references to all of the app code that we’ll be testing as well as all of the tests that we’ll be writing.
Jasmine (default), Mocha, QUnit
angular-mocks.js library for mocking
our app-specific code must be your original file output from dist folder (e.g all.js)
For instance, a sample unit test Karma config file might look like the following (comments removed for simplicity):
module.exports = function(config) {
config.set({
basePath: '..',
frameworks: ['jasmine'],
files: [
'lib/angular.js',
'lib/angular-route.js',
'test/lib/angular-mocks.js',
'js/**/*.js',
'test/unit/**/*.js'
],
exclude: [],
port: 8080,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Safari'],
singleRun: false
});
};
if you are using a single file for output all js files for example you concatenating all your files into one file e.g all.js then your config must look like this
files: [
'lib/angular.js',
'lib/angular-route.js',
'test/lib/angular-mocks.js',
'js/all.js',
'test/unit/**/*.js'
],
Upvotes: 1