@samitouri / QOS-React / commits / 839697f60c

Restore coverage in Travis (#7628)

We disabled coverage in Travis because the implementation was crashing ( https://github.com/facebook/react/issues/6290 ). Since we upgraded to Jest 15, the entire coverage implementation is brand new so we should give it another try.

Christopher Chedeau committed Sep 2, 2016 at 14:23 UTC 839697f60c6117e3a562c91142bda4c12acc4146
3 files changed +15 -90
.travis.yml
+2 -8
@@ -71,14 +71,8 @@ script:
71 fi
72 elif [ "$TEST_TYPE" = test ]; then
73 set -e
74 - # Disabling coverage because it's broken:
75 - # https://travis-ci.org/facebook/react/jobs/128163922
76 - if false; then
77 - ./node_modules/.bin/grunt jest:coverage
78 - cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
79 - else
80 - ./node_modules/.bin/grunt jest:normal
81 - fi
74 + ./node_modules/.bin/grunt jest:coverage
75 + cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
76 echo 'Testing in server-render (HTML generation) mode...'
77 printf '\nmodule.exports.useCreateElement = false;\n' \
78 >> src/renderers/dom/shared/ReactDOMFeatureFlags.js
grunt/tasks/jest.js
+6 -81
@@ -1,84 +1,16 @@
1 'use strict';
2
3 -var async = require('async');
4 -var fs = require('fs');
5 -var glob = require('glob');
3 var grunt = require('grunt');
4 var path = require('path');
5
9 -var rootPath = path.resolve('.');
10 -var buildPath = path.join(rootPath, 'build');
11 -var tempConfigPath = path.join(buildPath, 'jest-config.json');
12 -
13 -var config = require(path.join(rootPath, 'package.json')).jest;
14 -
15 -var collectCoverageOnlyFrom = {
16 - 'src/**/*.js': {
17 - ignore: [
18 - 'src/**/__tests__/*.js',
19 - 'src/shared/vendor/third_party/*.js',
20 - 'src/test/*.js',
21 - ],
22 - },
23 -};
24 -
25 -function getCollectCoverageOnlyFrom(callback) {
26 - var patterns = Object.keys(collectCoverageOnlyFrom);
27 - var result = {};
28 -
29 - async.each(patterns, function(pattern) {
30 - var options = Object.assign({ nodir: true }, collectCoverageOnlyFrom[pattern]);
31 - glob(pattern, options, function(err, files) {
32 - (files || []).reduce(function(object, key) {
33 - object[key] = true;
34 - return object;
35 - }, result);
36 -
37 - callback(err);
38 - });
39 - }, function(err) {
40 - callback(err, result);
41 - });
42 -}
43 -
44 -function getJestConfig(callback) {
45 - var rootDir = path.resolve(buildPath, path.resolve(config.rootDir));
46 - getCollectCoverageOnlyFrom(function(err, data) {
47 - callback(err, Object.assign({}, config, {
48 - rootDir: rootDir,
49 - name: 'react',
50 - collectCoverage: true,
51 - collectCoverageOnlyFrom: data,
52 - }));
53 - });
54 -}
55 -
56 -function onError(err) {
57 - grunt.log.error('jest failed');
58 - grunt.log.error(err);
59 -}
60 -
61 -function writeTempConfig(callback) {
62 - getJestConfig(function(err, data) {
63 - if (err) {
64 - callback(err);
65 - } else {
66 - grunt.file.mkdir(buildPath);
67 - fs.writeFile(tempConfigPath, JSON.stringify(data, null, ' '), 'utf8', callback);
68 - }
69 - });
70 -}
71 -
72 -function run(done, configPath) {
6 +function run(done, coverage) {
7 grunt.log.writeln('running jest');
8
9 var args = [
10 path.join('node_modules', 'jest', 'bin', 'jest'),
77 - '--runInBand',
78 - '--no-watchman',
11 ];
80 - if (configPath) {
81 - args.push('--config', configPath);
12 + if (coverage) {
13 + args.push('--coverage');
14 }
15 grunt.util.spawn({
16 cmd: 'node',
@@ -91,7 +23,8 @@ function run(done, configPath) {
23 },
24 }, function(spawnErr, result, code) {
25 if (spawnErr) {
94 - onError(spawnErr);
26 + grunt.log.error('jest failed');
27 + grunt.log.error(spawnErr);
28 } else {
29 grunt.log.ok('jest passed');
30 }
@@ -108,15 +41,7 @@ function runJestNormally() {
41
42 function runJestWithCoverage() {
43 var done = this.async();
111 -
112 - writeTempConfig(function(writeErr) {
113 - if (writeErr) {
114 - onError(writeErr);
115 - return;
116 - }
117 -
118 - run(done, tempConfigPath);
119 - });
44 + run(done, /* coverage */ true);
45 }
46
47 module.exports = {
package.json
+7 -1
@@ -58,7 +58,7 @@
58 "gulp-load-plugins": "^1.2.4",
59 "gulp-util": "^3.0.7",
60 "gzip-js": "~0.3.2",
61 - "jest": "^15.0.1",
61 + "jest": "^15.0.2",
62 "loose-envify": "^1.1.0",
63 "merge-stream": "^1.0.0",
64 "object-assign": "^4.1.0",
@@ -111,6 +111,12 @@
111 "<rootDir>/src",
112 "node_modules/fbjs"
113 ],
114 + "collectCoverageFrom": [
115 + "src/**/*.js",
116 + "!src/**/__tests__/*.js",
117 + "!src/shared/vendor/third_party/*.js",
118 + "!src/test/*.js"
119 + ],
120 "timers": "fake"
121 }
122 }