From: Gustavo Martin Morcuende Date: Wed, 19 Aug 2015 19:17:22 +0000 (+0200) Subject: showcase: gulp task test X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=49afe4df545ecf02112fb3ff01132b03cf778f79;p=JavaScriptForFun showcase: gulp task test --- diff --git a/angularjs/showcase/gulp.config.js b/angularjs/showcase/gulp.config.js index 9362257..bac5508 100644 --- a/angularjs/showcase/gulp.config.js +++ b/angularjs/showcase/gulp.config.js @@ -17,13 +17,18 @@ module.exports = function() { app + '**/*.js', '!' + app + '**/*.spec.js' ], + jsFilesWithSpecs: [ + app + '**/*.module.js', + app + '**/*.js' + ], jsFilesStubs: [ - bower.directory + 'angular-mocks/angular-mocks.js', main + 'stubs/**/*.js' ], index: main + 'index.html', jshintConfigurationFile: '.jshintrc', - jscsConfigurationFile: '.jscsrc' + jscsConfigurationFile: '.jscsrc', + + karmaConf: 'karma.conf.js' }; config.getWiredepOptions = function() { diff --git a/angularjs/showcase/gulpfile.js b/angularjs/showcase/gulpfile.js index ae5f0c5..d45633d 100644 --- a/angularjs/showcase/gulpfile.js +++ b/angularjs/showcase/gulpfile.js @@ -7,11 +7,11 @@ var plugins = require('gulp-load-plugins')({lazy: true}); /** * Arguments: * - * --verbose : Various tasks will produce more output to the console. - * --stubs : Using stubs in index.html (for mocking services, controllers or any other stuff) + * [--verbose] : Various tasks will produce more output to the console. No verbose by default. + * [--stubs] : Using stubs in index.html (for mocking services, controllers or any other stuff) No stubs by default. + * [--environment] : Running tasks in integration or development environment. Development by default. */ - /** * Default tasks * @@ -19,7 +19,6 @@ var plugins = require('gulp-load-plugins')({lazy: true}); gulp.task('help', plugins.taskListing); gulp.task('default', ['help']); - /** * vet (evaluate) the code and create coverage report. * @@ -50,23 +49,43 @@ gulp.task('wiredep', function() { log('Wiring bower dependencies into html'); var wiredep = require('wiredep').stream; - var wiredepOptions = config.getWiredepOptions(); - var jsFiles = args.stubs ? [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs) : config.jsFilesWithoutSpecs; return gulp.src(config.index) - .pipe(wiredep(wiredepOptions)) + .pipe(wiredep(config.getWiredepOptions())) .pipe(inject(jsFiles, '')) .pipe(gulp.dest(config.main)); }); /** - * Runs HTTP server in development mode. + * Runs HTTP server. */ -gulp.task('server-dev', ['wiredep'], function() { - log('Starting server in development mode'); +gulp.task('server', ['wiredep'], function(done) { + var environment = 'development'; + + if (args.environment) { + environment = args.environment; + } - server(true); + log('Starting server in ' + environment + ' mode'); + server(environment); + done(); +}); + +/** + * Runs specs once and exit. + * + * @return {Stream} + */ +gulp.task('test', ['vet'], function(done) { + startTests(true, done); +}); + +/** + * Run specs and wait. Watch for file changes and re-run tests on each change + */ +gulp.task('autotest', function(done) { + startTests(false, done); }); /** @@ -90,14 +109,14 @@ function inject(source, label) { /** * Runs HTTP server. * - * @param {boolean} isDev - development or build mode. + * @param {string=} [environment='development'] development or integration environments. */ -function server(isDev) { +function server(environment) { var nodeOptions = { script: serverConfig.script, delayTime: 1, env: { - 'NODE_ENV': isDev ? 'dev' : 'build' + 'NODE_ENV': environment ? environment : 'development' }, watch: [serverConfig.directory] }; @@ -118,6 +137,30 @@ function server(isDev) { }); } +/** + * Tests runner, karma launcher. + * + * @param {boolean} singleRun True means run once and end (continuous integration), or keep running (development) + * @param {function} done Callback to fire when karma is done + * @return {undefined} + */ +function startTests(singleRun, done) { + var excludeFiles = []; + var karma = require('karma').server; + + karma.start({ + configFile: __dirname + '/karma.conf.js', + exclude: excludeFiles, + singleRun: singleRun + }, doneKarma); + + function doneKarma(result) { + log('Karma completed'); + log('Karma: tests exited with code ' + result); + done(); + } +} + function log(message) { plugins.util.log(plugins.util.colors.blue(message)); -} \ No newline at end of file +} diff --git a/angularjs/showcase/karma.conf.js b/angularjs/showcase/karma.conf.js index 45b43e6..5162ad3 100644 --- a/angularjs/showcase/karma.conf.js +++ b/angularjs/showcase/karma.conf.js @@ -31,9 +31,8 @@ module.exports = function(config) { 'bower_components/bootstrap/dist/js/bootstrap.js', 'bower_components/angular-mocks/angular-mocks.js', //endbower - - 'app/**/*.module.js', - 'app/**/*.js' + 'src/showcase/app/**/*.module.js', + 'src/showcase/app/**/*.js' ], // list of files / patterns to exclude @@ -76,23 +75,23 @@ module.exports = function(config) { }, preprocessors: { - 'app/**/*.js': ['coverage'] + 'src/showcase/app/**/!(*.spec)+(.js)': ['coverage'] }, coverageReporter: { // specify a common output directory - dir: 'test-tmp/coverage', + dir: 'report/coverage', reporters: [ // reporters not supporting the `file` property - { type: 'html', subdir: 'report-html' }, - { type: 'lcov', subdir: 'report-lcov' }, + {type: 'html', subdir: 'report-html'}, + {type: 'lcov', subdir: 'report-lcov'}, // reporters supporting the `file` property, use `subdir` to directly // output them in the `dir` directory - { type: 'cobertura', subdir: '.', file: 'cobertura.txt' }, - { type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' }, - { type: 'teamcity', subdir: '.', file: 'teamcity.txt' }, - { type: 'text', subdir: '.', file: 'text.txt' }, - { type: 'text-summary', subdir: '.', file: 'text-summary.txt' }, + {type: 'cobertura', subdir: '.', file: 'cobertura.txt'}, + {type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt'}, + {type: 'teamcity', subdir: '.', file: 'teamcity.txt'}, + {type: 'text', subdir: '.', file: 'text.txt'}, + {type: 'text-summary', subdir: '.', file: 'text-summary.txt'} ] }, @@ -104,7 +103,7 @@ module.exports = function(config) { // level of logging // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG - logLevel: config.LOG_INFO, + logLevel: config.LOG_INFO // Uncomment the following lines if you are using grunt's server to run the tests // proxies: { diff --git a/angularjs/showcase/package.json b/angularjs/showcase/package.json index 236af8b..dde7445 100644 --- a/angularjs/showcase/package.json +++ b/angularjs/showcase/package.json @@ -19,6 +19,7 @@ "gulp-useref": "~1.3.0", "gulp-util": "~3.0.6", "jshint-stylish": "~2.0.1", + "karma": "~0.13.9", "karma-coverage": "~0.5.0", "karma-jasmine": "~0.3.6", "karma-junit-reporter": "~0.3.3", @@ -28,12 +29,6 @@ "wiredep": "~3.0.0-beta", "yargs": "~3.19.0" }, - "config": { - "backend-port": "8080", - "express-port": "8081", - "backend-server-name": "gumartinm.name", - "backend-server-url": "showcase" - }, "scripts": { "prestart": "wiredep -s app/index.html", "pretest": "wiredep -s karma.conf.js --dependencies --devDependencies", diff --git a/angularjs/showcase/server/server.js b/angularjs/showcase/server/server.js index a291373..0078e28 100644 --- a/angularjs/showcase/server/server.js +++ b/angularjs/showcase/server/server.js @@ -12,13 +12,13 @@ app.use(favicon(__dirname + '/favicon.ico')); app.use(logger('dev')); switch (environment) { - case 'build': - console.log('build mode'); + case 'integration': + console.log('integration mode'); - app.use(express.static('./build/')); + app.use(express.static('./dist/')); // Deep linking - app.use('/*', express.static('./build/index.html')); + app.use('/*', express.static('./dist/index.html')); break; default: console.log('development mode'); diff --git a/angularjs/showcase/src/showcase/app/app.config.js b/angularjs/showcase/src/showcase/app/app.config.js index b86a7f0..3a8490c 100644 --- a/angularjs/showcase/src/showcase/app/app.config.js +++ b/angularjs/showcase/src/showcase/app/app.config.js @@ -18,4 +18,4 @@ $stateProvider.state('welcome', welcome); } ]); -}()); \ No newline at end of file +}()); diff --git a/angularjs/showcase/src/showcase/app/app.module.js b/angularjs/showcase/src/showcase/app/app.module.js index cc245ef..839e77f 100644 --- a/angularjs/showcase/src/showcase/app/app.module.js +++ b/angularjs/showcase/src/showcase/app/app.module.js @@ -8,4 +8,4 @@ 'ui.bootstrap.modal' ]); -}()); \ No newline at end of file +}());