Skip to content

Commit

Permalink
collect coverage for jest itself (jestjs#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored Aug 6, 2016
1 parent 9beeee2 commit d8b14f8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ website/src/jest/docs
website/src/jest/blog
lerna-debug.log
npm-debug.log*
coverage
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_js:
- "6"
sudo: false
before_install: npm i -g npm@latest
script:
- npm run test-ci
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"flow-bin": "^0.29.0",
"glob": "^7.0.4",
"graceful-fs": "^4.1.4",
"istanbul-api": "^1.0.0-aplha.10",
"istanbul-lib-coverage": "^1.0.0-alpha.4",
"lerna": "2.0.0-beta.24",
"minimatch": "^3.0.2",
"mkdirp": "^0.5.1",
Expand All @@ -29,6 +31,8 @@
"publish": "npm run build-clean && npm run build && lerna publish",
"test-examples": "node ./scripts/test_examples.js",
"test": "npm run typecheck && npm run lint && npm run build && npm run jest && npm run test-examples",
"test-coverage": "./packages/jest-cli/bin/jest.js --coverage && node ./scripts/mapCoverage",
"test-ci": "npm run typecheck && npm run lint && npm run jest -- --runInBand --coverage && node ./scripts/mapCoverage",
"jest": "./packages/jest-cli/bin/jest.js",
"typecheck": "flow check",
"watch": "npm run build; node ./scripts/watch.js"
Expand All @@ -40,14 +44,22 @@
"packages\/.*\/build"
],
"rootDir": "./",
"collectCoverageFrom": [
"**/packages/**/*.js",
"!**/vendor/**",
"!**/__mocks__/**",
"!**/__tests__/**",
"!integration_tests/**"
],
"coverageReporters": ["json"],
"scriptPreprocessor": "<rootDir>/packages/babel-jest",
"setupTestFrameworkScriptFile": "<rootDir>/testSetupFile.js",
"testPathIgnorePatterns": [
"/node_modules/",
"/examples/",
"integration_tests\/.*\/__tests__",
"integration_tests/.*/__tests__",
"\\.snap$",
"packages\/.*\/build"
"packages/.*/build"
],
"testRegex": ".*-test.\\js"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/__tests__/reporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

jest.disableAutomock();

const JasmineReporter = require('../reporter');

describe('Jasmine2Reporter', () => {
let JasmineReporter;
let chalk;
let reporter;

beforeEach(() => {
JasmineReporter = require('../reporter');
chalk = require('chalk');

reporter = new JasmineReporter({});
Expand Down
49 changes: 49 additions & 0 deletions scripts/mapCoverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

/**
* Because we have a build step, sometimes we can test files from both
* `packages/jest-whatever/build/*` and `packages/jest-whatever/src/*`
*
* If we require file by its relative path like:
* // inside `jest-whatever/src/__tests__/index.js`
* require('../index.js'); // this will require `jest-whatever/src/index.js`
*
* But if we require it by a package name, this will go through node_modules
* and lerna index.js link. So the actual file will be required from `build/`
* // inside another packages
* // this will go through lerna and require `jest-whatever/build/index.js
* require('jest-whatever')
*
* these files are identical (one is preprocessed, another is transformed on
* the fly), but the coverage paths are different.
* This script will map coverage results from both locations to one and
* produce a full coverage report.
*/

const createReporter = require('istanbul-api').createReporter;
const coverage = require('../coverage/coverage-final.json');
const istanbulCoverage = require('istanbul-lib-coverage');

const map = istanbulCoverage.createCoverageMap();
const reporter = createReporter();

const mapFileCoverage = fileCoverage => {
fileCoverage.path = fileCoverage.path
.replace(/(.*packages\/.*\/)(build)(\/.*)/, '$1src$3');
return fileCoverage;
};

Object.keys(coverage).forEach(
filename => map.addFileCoverage(mapFileCoverage(coverage[filename]))
);

reporter.addAll(['json', 'lcov', 'text']);
reporter.write(map);

0 comments on commit d8b14f8

Please sign in to comment.