From 3eb9a7a5bb71836384f82a5b7d7129a09f69c594 Mon Sep 17 00:00:00 2001 From: connectdotz Date: Thu, 28 Jan 2021 17:45:27 -0500 Subject: [PATCH] update doc and correct watchMode passing --- CHANGELOG.md | 1 + README.md | 2 + .../JestProcessManager.ts | 2 +- .../JestProcessManager.test.ts | 62 +++++++++++-------- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe3b5f60..44fd26621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Please add your own contribution below inside the Master section Bug-fixes within the same version aren't needed ## Master +* update doc to give warning on potential incorrect coverage in watch mode - @connectdotz --> diff --git a/README.md b/README.md index 70ed805d6..4cb59717a 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ The coverage mode, along with watch mode, are shown in StatusBar: _(The initial coverage mode is `off` but can be changed by adding `"jest.showCoverageOnLoad": true` in settings.)_ +**Warning** +Coverage info might be less than what it actual is in "watch" mode (with `--watch` flag), where only changed files/tests are run (see facebook/jest#1284). To ensure absolutely correct coverage, we did consider using `--watchAll` with coverage, which could have significant performance impact. Not sure which problem is worse, therefore no change has been made, we are still default to `--watch` even with coverage on. (Maybe a new customization setting to override it if enough people want it... PR is welcome.) ### How to customize coverage overlay Coverage overlay determines how the coverage info is shown to users. This extension provides 2 customization points: 1. coverage style via `jest.coverageFormatter` diff --git a/src/JestProcessManagement/JestProcessManager.ts b/src/JestProcessManagement/JestProcessManager.ts index 625055b2b..9f4795d1d 100644 --- a/src/JestProcessManagement/JestProcessManager.ts +++ b/src/JestProcessManagement/JestProcessManager.ts @@ -42,7 +42,7 @@ export class JestProcessManager { } this.removeJestProcessReference(exitedJestProcess); const jestProcessInWatchMode = this.run({ - watchMode: WatchMode.Watch, + watchMode, keepAlive, exitCallback, }); diff --git a/tests/JestProcessManagement/JestProcessManager.test.ts b/tests/JestProcessManagement/JestProcessManager.test.ts index 5d081bd7a..6c85d3d20 100644 --- a/tests/JestProcessManagement/JestProcessManager.test.ts +++ b/tests/JestProcessManagement/JestProcessManager.test.ts @@ -161,36 +161,46 @@ describe('JestProcessManager', () => { ); }); - it('binds the provided exit handler to the both jest processes', () => { - const eventEmitterForWatchMode = new EventEmitter(); - const onExitMock = jest - .fn() - .mockImplementationOnce((callback) => { - eventEmitter.on('debuggerProcessExit', callback); - }) - .mockImplementationOnce((callback) => { - eventEmitterForWatchMode.on('debuggerProcessExit', callback); - }); + it.each([[WatchMode.Watch], [WatchMode.WatchAll]])( + 'pass watchMode $s and bind the provided exit handler to the both jest processes', + (watchMode) => { + const eventEmitterForWatchMode = new EventEmitter(); + const onExitMock = jest + .fn() + .mockImplementationOnce((callback) => { + eventEmitter.on('debuggerProcessExit', callback); + }) + .mockImplementationOnce((callback) => { + eventEmitterForWatchMode.on('debuggerProcessExit', callback); + }); - jestProcessMock.mockImplementation(() => ({ - onExit: onExitMock, - })); + jestProcessMock.mockImplementation(() => ({ + onExit: onExitMock, + })); - jestProcessManager.startJestProcess({ - exitCallback: exitHandler, - watchMode: WatchMode.Watch, - }); + jestProcessManager.startJestProcess({ + exitCallback: exitHandler, + watchMode, + }); - eventEmitter.emit('debuggerProcessExit', { stopRequested: () => false, watchMode: false }); - eventEmitterForWatchMode.emit('debuggerProcessExit', { - stopRequested: () => false, - watchMode: true, - }); + eventEmitter.emit('debuggerProcessExit', { stopRequested: () => false, watchMode: false }); + eventEmitterForWatchMode.emit('debuggerProcessExit', { + stopRequested: () => false, + watchMode: true, + }); - expect(exitHandler).toHaveBeenCalledTimes(2); - expect(exitHandler.mock.calls[0][0].watchMode).toBe(false); - expect(exitHandler.mock.calls[1][0].watchMode).toBe(true); - }); + //verify watchMode has been passed on correctly + expect(jestProcessMock).toHaveBeenCalledTimes(2); + expect(jestProcessMock.mock.calls.map((c) => c[0].watchMode)).toEqual([ + WatchMode.None, + watchMode, + ]); + + expect(exitHandler).toHaveBeenCalledTimes(2); + expect(exitHandler.mock.calls[0][0].watchMode).toBe(false); + expect(exitHandler.mock.calls[1][0].watchMode).toBe(true); + } + ); it('the exit handler for the non-watch mode passes the jest process representing the watch mode as the second argument', () => { const eventEmitterForWatchMode = new EventEmitter();