From 9c5f0d7a3c76b960d6fde3efc4f9dcd557bbccdf Mon Sep 17 00:00:00 2001 From: Juanfran Date: Wed, 15 Apr 2015 13:21:53 +0200 Subject: [PATCH] testing infrastructure --- gulpfile.js | 80 +++++++++++++++++++++++--------------------- karma.app.conf.js | 12 +++++++ karma.conf.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++ 4 files changed, 152 insertions(+), 38 deletions(-) create mode 100644 karma.app.conf.js create mode 100644 karma.conf.js diff --git a/gulpfile.js b/gulpfile.js index 51d3a389..149d5d1c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,6 +22,8 @@ var gulp = require("gulp"), autoprefixer = require("gulp-autoprefixer"), templateCache = require("gulp-angular-templatecache"), runSequence = require("run-sequence"), + order = require("gulp-order"), + print = require('gulp-print'), del = require("del"); var mainSass = require("./main-sass").files; @@ -54,30 +56,35 @@ paths.sass = [ "!" + paths.app + "/styles/extras/**/*.scss" ]; -paths.coffee = paths.app + "**/*.coffee"; +paths.coffee = [ + paths.app + "coffee/**/*.coffee", + paths.app + "plugins/**/*.coffee", + "!" + paths.app + "**/*.spec.coffee", +]; -paths.js = [ - paths.tmp + "coffee/app.js", - paths.tmp + "coffee/*.js", - paths.tmp + "coffee/modules/controllerMixins.js", - paths.tmp + "coffee/modules/*.js", - paths.tmp + "coffee/modules/common/*.js", - paths.tmp + "coffee/modules/backlog/*.js", - paths.tmp + "coffee/modules/taskboard/*.js", - paths.tmp + "coffee/modules/kanban/*.js", - paths.tmp + "coffee/modules/issues/*.js", - paths.tmp + "coffee/modules/userstories/*.js", - paths.tmp + "coffee/modules/tasks/*.js", - paths.tmp + "coffee/modules/team/*.js", - paths.tmp + "coffee/modules/wiki/*.js", - paths.tmp + "coffee/modules/admin/*.js", - paths.tmp + "coffee/modules/projects/*.js", - paths.tmp + "coffee/modules/locales/*.js", - paths.tmp + "coffee/modules/base/*.js", - paths.tmp + "coffee/modules/resources/*.js", - paths.tmp + "coffee/modules/user-settings/*.js", - paths.tmp + "coffee/modules/integrations/*.js", - paths.tmp + "plugins/**/*.js" +paths.coffee_order = [ + paths.app + "coffee/app.coffee", + paths.app + "coffee/*.coffee", + paths.app + "coffee/modules/controllerMixins.coffee", + paths.app + "coffee/modules/*.coffee", + paths.app + "coffee/modules/common/*.coffee", + paths.app + "coffee/modules/backlog/*.coffee", + paths.app + "coffee/modules/taskboard/*.coffee", + paths.app + "coffee/modules/kanban/*.coffee", + paths.app + "coffee/modules/issues/*.coffee", + paths.app + "coffee/modules/userstories/*.coffee", + paths.app + "coffee/modules/tasks/*.coffee", + paths.app + "coffee/modules/team/*.coffee", + paths.app + "coffee/modules/wiki/*.coffee", + paths.app + "coffee/modules/admin/*.coffee", + paths.app + "coffee/modules/projects/*.coffee", + paths.app + "coffee/modules/locales/*.coffee", + paths.app + "coffee/modules/base/*.coffee", + paths.app + "coffee/modules/resources/*.coffee", + paths.app + "coffee/modules/user-settings/*.coffee", + paths.app + "coffee/modules/integrations/*.coffee", + paths.app + "plugins/*.coffee", + paths.app + "plugins/**/*.coffee" ]; paths.libs = [ @@ -267,17 +274,16 @@ gulp.task("locales", function() { gulp.task("coffee", function() { return gulp.src(paths.coffee) + .pipe(order(paths.coffee_order, {base: '.'})) + .pipe(sourcemaps.init()) .pipe(cache(coffee())) .on("error", function(err) { console.log(err.toString()); this.emit("end"); }) - .pipe(gulp.dest(paths.tmp)); -}); - -gulp.task("plugins-js", function() { - return gulp.src(paths.app + "plugins/**/*.js") - .pipe(gulp.dest(paths.tmp)); + .pipe(concat("app.js")) + .pipe(sourcemaps.write('./maps')) + .pipe(gulp.dest(paths.dist + "js/")); }); gulp.task("jslibs-watch", function() { @@ -293,22 +299,19 @@ gulp.task("jslibs-deploy", function() { .pipe(sourcemaps.init()) .pipe(concat("libs.js")) .pipe(uglify({mangle:false, preserveComments: false})) - .pipe(sourcemaps.write("./")) + .pipe(sourcemaps.write("./maps")) .pipe(gulp.dest(paths.dist + "js/")); }); -gulp.task("app-watch", ["coffee", "plugins-js", "conf", "locales", "app-loader"], function() { - return gulp.src(paths.js) - .pipe(concat("app.js")) - .pipe(gulp.dest(paths.dist + "js/")); -}); +gulp.task("app-watch", ["coffee", "conf", "locales", "app-loader"]); -gulp.task("app-deploy", ["coffee", "plugins-js", "conf", "locales", "app-loader"], function() { - return gulp.src(paths.js) +gulp.task("app-deploy", ["coffee", "conf", "locales", "app-loader"], function() { + return gulp.src(paths.dist) + .pipe(order(paths.coffee_order, {base: '.'})) .pipe(sourcemaps.init()) .pipe(concat("app.js")) .pipe(uglify({mangle:false, preserveComments: false})) - .pipe(sourcemaps.write("./")) + .pipe(sourcemaps.write("./maps")) .pipe(gulp.dest(paths.dist + "js/")); }); @@ -370,6 +373,7 @@ gulp.task("express", function() { app.use("/fonts", express.static(__dirname + "/dist/fonts")); app.use("/plugins", express.static(__dirname + "/dist/plugins")); app.use("/locales", express.static(__dirname + "/dist/locales")); + app.use("/maps", express.static(__dirname + "/dist/maps")); app.all("/*", function(req, res, next) { //Just send the index.html for other files to support HTML5Mode diff --git a/karma.app.conf.js b/karma.app.conf.js new file mode 100644 index 00000000..9a04d7c8 --- /dev/null +++ b/karma.app.conf.js @@ -0,0 +1,12 @@ +window.taigaConfig = { + "api": "http://localhost:8000/api/v1/", + "eventsUrl": null, + "debug": true, + "defaultLanguage": "en", + "publicRegisterEnabled": true, + "feedbackEnabled": true, + "privacyPolicyUrl": null, + "termsOfServiceUrl": null, + "maxUploadFileSize": null, + "contribPlugins": [] +} diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 00000000..33b07d9d --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,84 @@ +// Karma configuration +// Generated on Wed Apr 15 2015 09:44:14 GMT+0200 (CEST) + +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', 'sinon-chai'], + + + // list of files / patterns to load in the browser + files: [ + 'karma.app.conf.js', + 'dist/js/libs.js', + 'node_modules/angular-mocks/angular-mocks.js', + 'dist/js/app.js', + 'dist/js/templates.js', + 'app/coffee/**/*spec.coffee' + ], + + + // 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: { + '**/*.coffee': ['coffee'], + 'dist/js/app.js': ['sourcemap'] + }, + + coffeePreprocessor: { + // options passed to the coffee compiler + options: { + bare: true, + sourceMap: true + }, + // transforming the filenames + transformPath: function(path) { + return path.replace(/\.coffee$/, '.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: ['Chrome'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }); +}; diff --git a/package.json b/package.json index 89c133c1..cf0b2529 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "scss-lint": "gulp scss-lint --fail" }, "devDependencies": { + "angular-mocks": "^1.3.15", "bluebird": "^2.9.21", + "chai": "^2.2.0", "cli-color": "^0.3.3", "coffee-script": "^1.9.1", "del": "^1.1.1", @@ -42,7 +44,9 @@ "gulp-jade": "^1.0.0", "gulp-jade-inheritance": "0.5.0", "gulp-minify-css": "^0.4.6", + "gulp-order": "^1.1.1", "gulp-plumber": "^0.6.6", + "gulp-print": "^1.1.0", "gulp-rename": "^1.2.0", "gulp-replace": "^0.5.3", "gulp-sass": "^1.3.3", @@ -52,9 +56,19 @@ "gulp-uglify": "~1.1.0", "gulp-wrap": "^0.11.0", "inquirer": "^0.8.2", + "karma": "^0.12.31", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^0.1.7", + "karma-coffee-preprocessor": "^0.2.1", + "karma-mocha": "^0.1.10", + "karma-sinon": "^1.0.4", + "karma-sinon-chai": "^0.3.0", + "karma-sourcemap-loader": "^0.3.4", + "mocha": "^2.2.4", "pre-commit": "^1.0.5", "readable-stream": "~1.0.33", "run-sequence": "^1.0.2", + "sinon": "^1.14.1", "through2": "~0.6.3" }, "pre-commit": [