How to set up gulp, jasmine, karma, karma-htmlfile-reporter to generate a html file that looks like jasmine output. Time lapse: 1 week into 15 mins.
- node
- npm
- gulp
- karma-cli
- vinyl-source-stream
- phantomjs
C:\Users\[your name]\AppData\Roaming\npm\node_modules
and remove it.
$ cd to new dir - c:\yourlocationetc\
$ npm init - to generate own package.json file
$ npm install gulp karma karma-jasmine karma-phantomjs-launcher karma-htmlfile-reporter --save-dev
jasmineSpecTests/spec/helloworld.spec.js
describe("hello world", function() {
it('should somePlugin() === "somePlugin"', function () {
expect(somePlugin()).toBe('somePlugin2ddd');
});
});
www/lib/somePlugin.js
var somePlugin = function(){
return 'somePlugin2';
};
karma.conf.js
// Karma configuration
// Generated on Thu Mar 10 2016 22:53:05 GMT+0000 (GMT Standard Time)
// Then customized
// https://github.com/nikku/karma-browserify
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
// relative to karma.conf.js
basePath: './',
// list of files / patterns to load in the browser
files: [
'www/lib/*.js', // source files first...
'jasmineSpecTests/**/*spec.js' // test files next...
],
frameworks: ['jasmine'],
reporters: ['progress', 'html'],
// the default configuration
htmlReporter: {
outputFile: 'jasmineSpecTests/testOutput/units.html',
// Optional
pageTitle: 'Unit Tests',
subPageTitle: 'A sample project description',
groupSuites: true,
useCompactStyle: true,
useLegacyStyle: true
},
logLevel: config.LOG_DEBUG,
browsers: ['PhantomJS'],
singleRun: true
})
}
var gulp = require('gulp');
var KarmaTestServer = require('karma').Server;
gulp.task('testKarma', function (done) {
new KarmaTestServer({
configFile: require('path').resolve('karma.conf.js'),
singleRun: true
}, function(error){
error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
done(error);
}).start();
});
gulp.task('test', ['testKarma']);
gulp test
jasmineSpecTests/testOutput/units.html