Created
December 29, 2015 08:25
-
-
Save AlecTaylor/283d71a8719e6f58d1df to your computer and use it in GitHub Desktop.
Karma related things from https://github.com/mwaylabs/generator-m-ionic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
describe('module: main, controller: FooCtrl', function () { | |
// load the controller's module | |
beforeEach(module('main')); | |
// load all the templates to prevent unexpected $http requests from ui-router | |
beforeEach(module('ngHtml2Js')); | |
// instantiate controller | |
var FooCtrl; | |
beforeEach(inject(function ($controller) { | |
FooCtrl = $controller('FooCtrl'); | |
})); | |
it('should do something', function () { | |
expect(!!FooCtrl).toBe(true); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// gulp | |
var gulp = require('gulp'); | |
var path = require('path'); | |
var paths = gulp.paths; | |
var options = gulp.options; | |
// plugins | |
var $ = require('gulp-load-plugins')(); | |
// modules | |
var Server = require('karma').Server; | |
var bs = require('browser-sync'); | |
// KARMA | |
function runKarma (singleRun, done) { | |
new Server({ | |
configFile: path.join(__dirname, '/../karma.conf.js'), | |
singleRun: singleRun, | |
autoWatch: !singleRun | |
}, done).start(); | |
} | |
gulp.task('karma', ['linting'], function (done) { | |
runKarma(true, done); | |
}); | |
gulp.task('karma:auto', ['linting'], function (done) { | |
runKarma(false, done); | |
}); | |
// PROTRACTOR | |
// Downloads the selenium webdriver | |
gulp.task('webdriver-update', $.protractor.webdriver_update); | |
gulp.task('webdriver-standalone', $.protractor.webdriver_standalone); | |
function runProtractor (done) { | |
gulp.src(paths.protractor) | |
.pipe($.protractor.protractor({ | |
configFile: 'protractor.conf.js' | |
})) | |
.on('error', function (err) { | |
// Make sure failed tests cause gulp to exit non-zero | |
throw err; | |
}) | |
.on('end', function () { | |
bs.exit(); | |
done(); | |
}); | |
} | |
gulp.task('protractor', ['serve', 'linting', 'webdriver-update'], function (done) { | |
runProtractor(done); | |
}); | |
var protractorBuildDeps = ['serve-build', 'webdriver-update']; | |
if (options.build !== false) { | |
protractorBuildDeps.push('build'); | |
} | |
gulp.task('protractor-build', protractorBuildDeps, function (done) { | |
gulp.start('linting'); | |
runProtractor(done); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var minimist = require('minimist'); | |
var requireDir = require('require-dir'); | |
var chalk = require('chalk'); | |
var fs = require('fs'); | |
// config | |
gulp.paths = { | |
dist: 'www', | |
jsFiles: ['app/**/*.js', '!app/bower_components/**/*.js'], | |
jsonFiles: ['app/**/*.json', '!app/bower_components/**/*.json'], | |
templates: ['app/*/templates/**/*'], | |
karma: ['test/karma/**/*.js'], | |
protractor: ['test/protractor/**/*.js'] | |
}; | |
// OPTIONS | |
var options = gulp.options = minimist(process.argv.slice(2)); | |
// set defaults | |
var task = options._[0]; // only for first task | |
var gulpSettings; | |
if (fs.existsSync('./gulp/.gulp_settings.json')) { | |
gulpSettings = require('./gulp/.gulp_settings.json'); | |
var defaults = gulpSettings.defaults; | |
if (defaults) { | |
// defaults present for said task? | |
if (task && task.length && defaults[task]) { | |
var taskDefaults = defaults[task]; | |
// copy defaults to options object | |
for (var key in taskDefaults) { | |
// only if they haven't been explicitly set | |
if (options[key] === undefined) { | |
options[key] = taskDefaults[key]; | |
} | |
} | |
} | |
} | |
} | |
// environment | |
options.env = options.env || 'dev'; | |
// print options | |
if (defaults && defaults[task]) { | |
console.log(chalk.green('defaults for task \'' + task + '\': '), defaults[task]); | |
} | |
// cordova command one of cordova's build commands? | |
if (options.cordova) { | |
var cmds = ['build', 'run', 'emulate', 'prepare', 'serve']; | |
for (var i = 0, cmd; ((cmd = cmds[i])); i++) { | |
if (options.cordova.indexOf(cmd) >= 0) { | |
options.cordovaBuild = true; | |
break; | |
} | |
} | |
} | |
// load tasks | |
requireDir('./gulp'); | |
// default task | |
gulp.task('default', function () { | |
// cordova build command & gulp build | |
if (options.cordovaBuild && options.build !== false) { | |
return gulp.start('cordova-with-build'); | |
} | |
// cordova build command & no gulp build | |
else if (options.cordovaBuild && options.build === false) { | |
return gulp.start('cordova-only-resources'); | |
} | |
// cordova non-build command | |
else if (options.cordova) { | |
return gulp.start('cordova'); | |
} | |
// just watch when cordova option not present | |
else { | |
return gulp.start('watch'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Karma configuration | |
// Generated on Wed Jul 01 2015 13:51:22 GMT+0200 (CEST) | |
'use strict'; | |
module.exports = function (config) { | |
// retrieve main files from bower | |
var wiredep = require('wiredep'); | |
var bowerFiles = wiredep({devDependencies: true}).js; | |
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 | |
// phantomjs-shim for Function.prototype.bind https://github.com/karma-runner/karma/issues/1107, should become unnecessary with phantomjs 2.0 | |
frameworks: ['jasmine', 'angular-filesort', 'phantomjs-shim'], | |
plugins: [ | |
'karma-ng-html2js-preprocessor', 'karma-phantomjs-launcher', 'karma-jasmine', 'karma-angular-filesort', 'karma-phantomjs-shim' | |
], | |
// sort app/**/*.js files | |
angularFilesort: { | |
whitelist: [ | |
'app/!(bower_components)/**/*.js' | |
] | |
}, | |
// list of files / patterns to load in the browser | |
files: bowerFiles.concat([ | |
// other | |
'app/!(bower_components)/**/*.js', | |
// test | |
'test/karma/**/*.js', | |
// templates | |
'app/**/templates/*.html' | |
]), | |
// 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: { | |
'app/**/templates/*.html': ['ng-html2js'] | |
}, | |
// use template cache to avoid unexpected $http requests from ui-router | |
// https://github.com/angular-ui/ui-router/issues/212#issuecomment-69974072 | |
ngHtml2JsPreprocessor: { | |
moduleName: 'ngHtml2Js', | |
stripPrefix: 'app/' // the path must be relative to the app.js | |
}, | |
// 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 | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment