From 40905db8e15c2ff6cb01c9b46aab1bb8964f3453 Mon Sep 17 00:00:00 2001 From: Dmitrii Abramov Date: Thu, 27 Apr 2017 23:23:41 -0700 Subject: [PATCH] Parallel coverage (resolve conflicts) --- packages/jest-cli/src/TestRunner.js | 2 +- packages/jest-cli/src/reporters/CoverageWorker.js | 14 ++++++++++---- .../src/reporters/__tests__/CoverageWorker-test.js | 12 +++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/jest-cli/src/TestRunner.js b/packages/jest-cli/src/TestRunner.js index d6e15f6e8863..11c42348f711 100644 --- a/packages/jest-cli/src/TestRunner.js +++ b/packages/jest-cli/src/TestRunner.js @@ -313,7 +313,7 @@ class TestRunner { } else { const exit = () => process.exit(1); this._dispatcher - .onRunComplete(contexts, this._config, aggregatedResults) + .onRunComplete(contexts, this._globalConfig, aggregatedResults) .then(exit) .catch(exit); } diff --git a/packages/jest-cli/src/reporters/CoverageWorker.js b/packages/jest-cli/src/reporters/CoverageWorker.js index ab23232eb195..7b1e4bbd892c 100644 --- a/packages/jest-cli/src/reporters/CoverageWorker.js +++ b/packages/jest-cli/src/reporters/CoverageWorker.js @@ -9,14 +9,15 @@ */ 'use strict'; -import type {Config, Path} from 'types/Config'; +import type {GlobalConfig, ProjectConfig, Path} from 'types/Config'; import type {SerializableError} from 'types/TestResult'; const fs = require('fs'); const generateEmptyCoverage = require('../generateEmptyCoverage'); type CoverageWorkerData = {| - config: Config, + globalConfig: GlobalConfig, + config: ProjectConfig, untestedFilePath: Path, |}; @@ -43,12 +44,17 @@ process.on('uncaughtException', err => { }); module.exports = ( - {config, untestedFilePath}: CoverageWorkerData, + {globalConfig, config, untestedFilePath}: CoverageWorkerData, callback: WorkerCallback, ) => { try { const source = fs.readFileSync(untestedFilePath).toString(); - const result = generateEmptyCoverage(source, untestedFilePath, config); + const result = generateEmptyCoverage( + source, + untestedFilePath, + globalConfig, + config, + ); callback(null, result); } catch (e) { callback(formatCoverageError(e, untestedFilePath), undefined); diff --git a/packages/jest-cli/src/reporters/__tests__/CoverageWorker-test.js b/packages/jest-cli/src/reporters/__tests__/CoverageWorker-test.js index 6720cc2c0bec..d6630c74ce02 100644 --- a/packages/jest-cli/src/reporters/__tests__/CoverageWorker-test.js +++ b/packages/jest-cli/src/reporters/__tests__/CoverageWorker-test.js @@ -13,9 +13,10 @@ jest.mock('fs').mock('../../generateEmptyCoverage'); const fs = require('fs'); const generateEmptyCoverage = require('../../generateEmptyCoverage'); -const config = {collectCoverage: true}; +const globalConfig = {collectCoverage: true}; +const config = {}; const worker = require('../CoverageWorker'); -const workerOptions = {config, untestedFilePath: 'asdf'}; +const workerOptions = {globalConfig, config, untestedFilePath: 'asdf'}; describe('CoverageWorker', () => { it('resolves to the result of generateEmptyCoverage upon success', () => { @@ -24,7 +25,12 @@ describe('CoverageWorker', () => { generateEmptyCoverage.mockImplementation(() => 42); return new Promise(resolve => { worker(workerOptions, (err, result) => { - expect(generateEmptyCoverage).toBeCalledWith(validJS, 'asdf', config); + expect(generateEmptyCoverage).toBeCalledWith( + validJS, + 'asdf', + globalConfig, + config, + ); expect(result).toEqual(42); resolve(); });