Commit babe9d57a4b2c8a2936f458e08e6c829813fd5e8
1 parent
fa922ca9
Exists in
master
and in
1 other branch
testing scripts adjustments
Showing
3 changed files
with
89 additions
and
50 deletions
Show diff stats
karma.conf.js
... | ... | @@ -6,7 +6,9 @@ var conf = require('./gulp/conf'); |
6 | 6 | |
7 | 7 | var argv = require("yargs").argv; |
8 | 8 | |
9 | -var singleRun = false; | |
9 | +var singleRun = (argv.singleRun !== undefined && argv.singleRun); | |
10 | +var coverage = (argv.coverage === undefined || argv.coverage); | |
11 | + | |
10 | 12 | |
11 | 13 | if (argv.singleRun) { |
12 | 14 | singleRun = true; |
... | ... | @@ -32,17 +34,15 @@ var karmaPlugins = [ |
32 | 34 | |
33 | 35 | var karmaReporters = ['spec']; |
34 | 36 | |
35 | -if (argv.coverage) { | |
36 | - //projectFiles = ['./src/shim.ts', './src/app/index.ts', './src/**/*.spec.ts']; | |
37 | - singleRun = true; | |
38 | 37 | |
39 | - karmaPlugins.push('karma-coverage'); | |
40 | - //karmaPlugins.push('karma-webpack'); | |
41 | - | |
38 | + | |
39 | +if (coverage) { | |
40 | + karmaPlugins.push('karma-coverage'); | |
42 | 41 | karmaReporters.push('coverage'); |
43 | 42 | } |
44 | 43 | |
45 | 44 | |
45 | + | |
46 | 46 | var _ = require('lodash'); |
47 | 47 | var wiredep = require('wiredep'); |
48 | 48 | |
... | ... | @@ -124,7 +124,7 @@ module.exports = function (config) { |
124 | 124 | }; |
125 | 125 | |
126 | 126 | |
127 | - if (argv.coverage) { | |
127 | + if (coverage) { | |
128 | 128 | |
129 | 129 | /*configuration.webpack = { |
130 | 130 | module: { | ... | ... |
package.json
... | ... | @@ -7,10 +7,11 @@ |
7 | 7 | "moment": "^2.11.2" |
8 | 8 | }, |
9 | 9 | "scripts": { |
10 | - "coverage": "karma start --coverage & npm run remap-coverage", | |
10 | + "coverage": "karma start --single-run & npm run remap-coverage", | |
11 | 11 | "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts", |
12 | - "test-single": "webpack && karma start --single-run", | |
13 | - "test": "concurrently \"webpack -w\" \"karma start\"", | |
12 | + "test-single": "karma start --single-run", | |
13 | + "test-and-coverage": "karma start & npm run remap-coverage", | |
14 | + "test": "webpack -w --test", | |
14 | 15 | "postinstall": "npm install -g bower && bower install && typings install", |
15 | 16 | "start": "concurrently \"webpack -w\" \"gulp serve\"", |
16 | 17 | "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts" |
... | ... | @@ -66,6 +67,7 @@ |
66 | 67 | "lodash": "~3.10.1", |
67 | 68 | "main-bower-files": "~2.9.0", |
68 | 69 | "ng-forward": "0.0.1-alpha.12", |
70 | + "on-build-webpack": "^0.1.0", | |
69 | 71 | "phantomjs": "~1.9.18", |
70 | 72 | "phantomjs-polyfill": "0.0.2", |
71 | 73 | "reflect-metadata": "^0.1.3", | ... | ... |
webpack.config.js
... | ... | @@ -4,65 +4,102 @@ var argv = require("yargs").argv; |
4 | 4 | var path = require("path"); |
5 | 5 | var glob = require("glob"); |
6 | 6 | |
7 | +var WebpackOnBuildPlugin = require('on-build-webpack'); | |
8 | + | |
7 | 9 | var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); |
8 | 10 | |
9 | 11 | var extension = ".js"; |
10 | 12 | if (argv.production) { |
11 | - extension = ".min.js" | |
13 | + extension = ".min.js" | |
12 | 14 | } |
13 | 15 | |
14 | 16 | var testFiles = glob.sync("./src/**/*.[sS]pec.ts"); |
15 | 17 | |
16 | 18 | var uglifyLoaderConfig = { |
17 | - // I want to uglify with mangling only app files, not thirdparty libs | |
18 | - test: /\.js$/, | |
19 | - exclude: /.spec.js/, // excluding .spec files | |
20 | - loader: "uglify" | |
19 | + // I want to uglify with mangling only app files, not thirdparty libs | |
20 | + test: /\.js$/, | |
21 | + exclude: /.spec.js/, // excluding .spec files | |
22 | + loader: "uglify" | |
21 | 23 | }; |
22 | 24 | |
23 | 25 | var testingFiles = glob.sync("./src/app/**/*.[sS]pec.ts"); |
24 | 26 | |
25 | 27 | var webpackConfig = { |
26 | - entry: { | |
27 | - noosfero: './src/app/index.ts', | |
28 | - 'noosfero-specs': './src/specs.ts' | |
29 | - }, | |
28 | + watchDelay: 300, | |
29 | + entry: { | |
30 | + noosfero: './src/app/index.ts', | |
31 | + 'noosfero-specs': './src/specs.ts' | |
32 | + }, | |
30 | 33 | |
31 | - plugins: [ new CommonsChunkPlugin("commons.js")], | |
34 | + plugins: [new CommonsChunkPlugin("commons.js")], | |
32 | 35 | |
33 | - output: { | |
34 | - path: path.join(__dirname, "src"), | |
35 | - filename: "[name]" + extension, | |
36 | - }, | |
37 | - | |
38 | - /*plugins: [ new webpack.optimize.CommonsChunkPlugin("common.js") ],*/ | |
36 | + output: { | |
37 | + path: path.join(__dirname, "src"), | |
38 | + filename: "[name]" + extension, | |
39 | + }, | |
39 | 40 | |
40 | - resolve: { | |
41 | - // Add `.ts` and `.tsx` as a resolvable extension. | |
42 | - extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] | |
43 | - }, | |
44 | - // Source maps support (or 'inline-source-map' also works) | |
45 | - devtool: 'source-map', | |
46 | - | |
47 | - module: { | |
48 | - loaders: [{ | |
49 | - test: /\.css$/, | |
50 | - loader: "style!css" | |
51 | - }, { | |
52 | - test: /\.scss$/, | |
53 | - loaders: ["style", "css?sourceMap", "sass?sourceMap"] | |
54 | - }, { | |
55 | - test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, | |
56 | - loader: 'url-loader?limit=100000' | |
57 | - }, { | |
58 | - test: /\.tsx?$/, | |
59 | - loader: 'ts-loader' | |
60 | - }] | |
61 | - } | |
41 | + /*plugins: [ new webpack.optimize.CommonsChunkPlugin("common.js") ],*/ | |
42 | + | |
43 | + resolve: { | |
44 | + // Add `.ts` and `.tsx` as a resolvable extension. | |
45 | + extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'] | |
46 | + }, | |
47 | + // Source maps support (or 'inline-source-map' also works) | |
48 | + devtool: 'source-map', | |
49 | + | |
50 | + module: { | |
51 | + loaders: [{ | |
52 | + test: /\.css$/, | |
53 | + loader: "style!css" | |
54 | + }, { | |
55 | + test: /\.scss$/, | |
56 | + loaders: ["style", "css?sourceMap", "sass?sourceMap"] | |
57 | + }, { | |
58 | + test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, | |
59 | + loader: 'url-loader?limit=100000' | |
60 | + }, { | |
61 | + test: /\.tsx?$/, | |
62 | + loader: 'ts-loader' | |
63 | + }] | |
64 | + } | |
62 | 65 | }; |
63 | 66 | |
64 | 67 | if (argv.production) { |
65 | - webpackConfig.module.loaders.push(uglifyLoaderConfig); | |
68 | + webpackConfig.module.loaders.push(uglifyLoaderConfig); | |
69 | +} | |
70 | + | |
71 | +var testProcess = null; | |
72 | +var child_process = require("child_process"); | |
73 | +var count = 0; | |
74 | +var stdinPatched = false; | |
75 | +if (argv.test) { | |
76 | + webpackConfig.plugins.push( | |
77 | + new WebpackOnBuildPlugin(function (stats) { | |
78 | + // webpack in watch mode call this twice for just one compilation | |
79 | + if (!stdinPatched) { | |
80 | + process.stdin.on('data', function (info) { | |
81 | + if (info == '\n') { | |
82 | + if (!testProcess) { | |
83 | + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); | |
84 | + testProcess.on('exit', function () { testProcess = null }); | |
85 | + } | |
86 | + } | |
87 | + }); | |
88 | + stdinPatched = true; | |
89 | + } | |
90 | + | |
91 | + // so, here we are checking if the process is still running before trigger another test execution | |
92 | + if (testProcess == null) { | |
93 | + console.log("Starting tests execution..."); | |
94 | + testProcess = child_process.spawn("npm", ["run", "coverage"], { stdio: 'inherit' }); | |
95 | + | |
96 | + testProcess.on('exit', function () { testProcess = null }); | |
97 | + } else { | |
98 | + console.log("Test still running... Sorry webpack!! :)"); | |
99 | + } | |
100 | + | |
101 | + }) | |
102 | + ); | |
66 | 103 | } |
67 | 104 | |
68 | 105 | module.exports = webpackConfig; | ... | ... |