Skip to content

Commit

Permalink
Add coveralls.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 22, 2015
1 parent aad8024 commit 9b0ef92
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ static
_SpecRunner.html
__benchmarks__
build/
coverage/
.module-cache
*.gem
docs/.bundle
Expand Down
86 changes: 74 additions & 12 deletions grunt/tasks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,87 @@

'use strict';

var assign = require('object-assign');
var async = require('async');
var fs = require('fs');
var glob = require('glob');
var grunt = require('grunt');
var path = require('path');

var rootPath = path.resolve('.');
var buildPath = path.join(rootPath, 'build');
var tempConfigPath = path.join(buildPath, 'jest-config.json');

var config = require(path.join(rootPath, 'package.json')).jest;

function getCollectCoverageOnlyFrom(callback) {
var coverageFrom = config.collectCoverageOnlyFrom;
var patterns = Object.keys((config.collectCoverage && coverageFrom) || {});
var result = {};

async.each(patterns, function(pattern) {
var options = assign({ nodir: true }, coverageFrom[pattern]);
glob(pattern, options, function(err, files) {
(files || []).reduce(function(object, key) {
object[key] = true;
return object;
}, result);

callback(err);
});
}, function(err) {
callback(err, result);
});
}

function getJestConfig(callback) {
var rootDir = path.resolve(buildPath, path.resolve(config.rootDir));
getCollectCoverageOnlyFrom(function(err, data) {
callback(err, assign({}, config, {
rootDir: rootDir,
collectCoverageOnlyFrom: data,
}));
});
}

function onError(err) {
grunt.log.error('jest failed');
grunt.log.error(err);
}

function writeTempConfig(callback) {
getJestConfig(function(err, data) {
if (err) {
callback(err);
} else {
fs.writeFile(tempConfigPath, JSON.stringify(data, null, ' '), 'utf8', callback);
}
});
}

module.exports = function() {
var done = this.async();

grunt.log.writeln('running jest (this may take a while)');
grunt.util.spawn({
cmd: 'node',
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')],
opts: {stdio: 'inherit', env: {NODE_ENV: 'test'}},
}, function(err, result, code) {
if (err) {
grunt.log.error('jest failed');
grunt.log.error(err);
} else {
grunt.log.ok('jest passed');

writeTempConfig(function(writeErr) {
if (writeErr) {
onError(writeErr);
return;
}
grunt.log.writeln(result.stdout);
grunt.util.spawn({
cmd: 'node',
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest'), '--config', tempConfigPath],
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
} else {
grunt.log.ok('jest passed');
}
grunt.log.writeln(result.stdout);

done(code === 0);
done(code === 0);
});
});
};
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"private": true,
"version": "0.15.0-alpha",
"devDependencies": {
"async": "^1.5.0",
"babel": "^5.8.29",
"babel-eslint": "4.1.5",
"benchmark": "^1.0.0",
"browserify": "^12.0.1",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
"coveralls": "^2.11.6",
"del": "^2.0.2",
"derequire": "^2.0.3",
"envify": "^3.0.0",
Expand All @@ -17,6 +19,7 @@
"eslint-plugin-react-internal": "file:eslint-rules",
"fbjs": "^0.4.0",
"fbjs-scripts": "^0.5.0",
"glob": "^6.0.1",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-compare-size": "^0.4.0",
Expand Down Expand Up @@ -54,6 +57,16 @@
"test": "jest"
},
"jest": {
"collectCoverage": true,
"collectCoverageOnlyFrom": {
"src/**/*.js": {
"ignore": [
"src/**/__tests__/*.js",
"src/shared/vendor/third_party/*.js",
"src/test/*.js"
]
}
},
"modulePathIgnorePatterns": [
"/.module-cache/",
"/react/build/"
Expand Down

0 comments on commit 9b0ef92

Please sign in to comment.