diff --git a/karma.conf.js b/karma.conf.js index 202a482..aed6f8d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,7 +6,9 @@ var conf = require('./gulp/conf'); var argv = require("yargs").argv; -var singleRun = false; +var singleRun = (argv.singleRun !== undefined && argv.singleRun); +var coverage = (argv.coverage === undefined || argv.coverage); + if (argv.singleRun) { singleRun = true; @@ -32,17 +34,15 @@ var karmaPlugins = [ var karmaReporters = ['spec']; -if (argv.coverage) { - //projectFiles = ['./src/shim.ts', './src/app/index.ts', './src/**/*.spec.ts']; - singleRun = true; - karmaPlugins.push('karma-coverage'); - //karmaPlugins.push('karma-webpack'); - + +if (coverage) { + karmaPlugins.push('karma-coverage'); karmaReporters.push('coverage'); } + var _ = require('lodash'); var wiredep = require('wiredep'); @@ -124,7 +124,7 @@ module.exports = function (config) { }; - if (argv.coverage) { + if (coverage) { /*configuration.webpack = { module: { diff --git a/package.json b/package.json index d0d5ba3..69500ff 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,11 @@ "moment": "^2.11.2" }, "scripts": { - "coverage": "karma start --coverage & npm run remap-coverage", + "coverage": "karma start --single-run & npm run remap-coverage", "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts", - "test-single": "webpack && karma start --single-run", - "test": "concurrently \"webpack -w\" \"karma start\"", + "test-single": "karma start --single-run", + "test-and-coverage": "karma start & npm run remap-coverage", + "test": "webpack -w --test", "postinstall": "npm install -g bower && bower install && typings install", "start": "concurrently \"webpack -w\" \"gulp serve\"", "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts" @@ -66,6 +67,7 @@ "lodash": "~3.10.1", "main-bower-files": "~2.9.0", "ng-forward": "0.0.1-alpha.12", + "on-build-webpack": "^0.1.0", "phantomjs": "~1.9.18", "phantomjs-polyfill": "0.0.2", "reflect-metadata": "^0.1.3", diff --git a/webpack.config.js b/webpack.config.js index f7de5be..c9785c9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,65 +4,102 @@ var argv = require("yargs").argv; var path = require("path"); var glob = require("glob"); +var WebpackOnBuildPlugin = require('on-build-webpack'); + var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); var extension = ".js"; if (argv.production) { - extension = ".min.js" + extension = ".min.js" } var testFiles = glob.sync("./src/**/*.[sS]pec.ts"); var uglifyLoaderConfig = { - // I want to uglify with mangling only app files, not thirdparty libs - test: /\.js$/, - exclude: /.spec.js/, // excluding .spec files - loader: "uglify" + // I want to uglify with mangling only app files, not thirdparty libs + test: /\.js$/, + exclude: /.spec.js/, // excluding .spec files + loader: "uglify" }; var testingFiles = glob.sync("./src/app/**/*.[sS]pec.ts"); var webpackConfig = { - entry: { - noosfero: './src/app/index.ts', - 'noosfero-specs': './src/specs.ts' - }, + watchDelay: 300, + entry: { + noosfero: './src/app/index.ts', + 'noosfero-specs': './src/specs.ts' + }, - plugins: [ new CommonsChunkPlugin("commons.js")], + plugins: [new CommonsChunkPlugin("commons.js")], - output: { - path: path.join(__dirname, "src"), - filename: "[name]" + extension, - }, - - /*plugins: [ new webpack.optimize.CommonsChunkPlugin("common.js") ],*/ + output: { + path: path.join(__dirname, "src"), + filename: "[name]" + extension, + }, - resolve: { - // Add `.ts` and `.tsx` as a resolvable extension. - extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] - }, - // Source maps support (or 'inline-source-map' also works) - devtool: 'source-map', - - module: { - loaders: [{ - test: /\.css$/, - loader: "style!css" - }, { - test: /\.scss$/, - loaders: ["style", "css?sourceMap", "sass?sourceMap"] - }, { - test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, - loader: 'url-loader?limit=100000' - }, { - test: /\.tsx?$/, - loader: 'ts-loader' - }] - } + /*plugins: [ new webpack.optimize.CommonsChunkPlugin("common.js") ],*/ + + resolve: { + // Add `.ts` and `.tsx` as a resolvable extension. + extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] + }, + // Source maps support (or 'inline-source-map' also works) + devtool: 'source-map', + + module: { + loaders: [{ + test: /\.css$/, + loader: "style!css" + }, { + test: /\.scss$/, + loaders: ["style", "css?sourceMap", "sass?sourceMap"] + }, { + test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, + loader: 'url-loader?limit=100000' + }, { + test: /\.tsx?$/, + loader: 'ts-loader' + }] + } }; if (argv.production) { - webpackConfig.module.loaders.push(uglifyLoaderConfig); + webpackConfig.module.loaders.push(uglifyLoaderConfig); +} + +var testProcess = null; +var child_process = require("child_process"); +var count = 0; +var stdinPatched = false; +if (argv.test) { + webpackConfig.plugins.push( + new WebpackOnBuildPlugin(function (stats) { + // webpack in watch mode call this twice for just one compilation + if (!stdinPatched) { + process.stdin.on('data', function (info) { + if (info == '\n') { + if (!testProcess) { + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); + testProcess.on('exit', function () { testProcess = null }); + } + } + }); + stdinPatched = true; + } + + // so, here we are checking if the process is still running before trigger another test execution + if (testProcess == null) { + console.log("Starting tests execution..."); + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); + + testProcess.on('exit', function () { testProcess = null }); + } else { + console.log("Test still running... Sorry webpack!! :)"); + } + + }) + ); } module.exports = webpackConfig; -- libgit2 0.21.2