Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update doc to warn potential partial coverage in watch mode #654

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

-->

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/JestProcessManagement/JestProcessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class JestProcessManager {
}
this.removeJestProcessReference(exitedJestProcess);
const jestProcessInWatchMode = this.run({
watchMode: WatchMode.Watch,
watchMode,
keepAlive,
exitCallback,
});
Expand Down
62 changes: 36 additions & 26 deletions tests/JestProcessManagement/JestProcessManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down