Skip to content

Commit

Permalink
Fixed missing test error auto focusing for watch mode run (jest-commu…
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz authored Feb 22, 2024
1 parent df87aa1 commit cfe5d96
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
3 changes: 2 additions & 1 deletion release-notes/release-note-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ This release is a patch release with the following changes:

**Bug Fixes**
- Fixed an outputConfig initialization bug that did not honor "testing.openTesting": "openOnTestFailure" setting correctly. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)

- Fixed missing test error auto focusing for watch mode run. ([#1120](https://github.com/jest-community/vscode-jest/pull/1120) - @connectdotz)

**New Command**
- Added a new command `"Jest: Disable Auto Focus Test Output"` to easily disable TEST RESULTS panel auto focus. It will set the output to the "neutral" mode, i.e., no auto focusing. ([#1119](https://github.com/jest-community/vscode-jest/pull/1119) - @connectdotz)

Expand Down
6 changes: 6 additions & 0 deletions src/JestExt/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ export class JestExt {
case 'end': {
const state = event.error ? 'exec-error' : 'done';
this.updateStatusBar({ state });

// testError should be persistent per run-cycle. Not clear up this flag at end end of the cycle
// could cause the processes with multiple run cycles, such as watch mode, to failed to act properly.
if (event.process.userData?.testError) {
event.process.userData.testError = undefined;
}
break;
}
case 'exit':
Expand Down
48 changes: 41 additions & 7 deletions tests/JestExt/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,13 +1362,47 @@ describe('JestExt', () => {
onRunEvent({ type: 'start', process });
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
});
it('notify outputManager for test-error event', () => {
const sut = newJestExt();
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
const process = { id: 'a process id', request: { type: 'watch' } };
onRunEvent({ type: 'test-error', process });
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('test-error', expect.anything());
describe('when test errors occurred', () => {
it('will notify outputManager', () => {
const sut = newJestExt();
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
const process = { id: 'a process id', request: { type: 'watch' } };
onRunEvent({ type: 'test-error', process });
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith(
'test-error',
expect.anything()
);
});
it('will only notify outputManager once per run cycle', () => {
const sut = newJestExt();
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
const process = { id: 'a process id', request: { type: 'watch' } };

onRunEvent({ type: 'test-error', process, userData: {} });
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith(
'test-error',
expect.anything()
);
mockOutputManager.showOutputOn.mockClear();

onRunEvent({ type: 'test-error', process });
expect(mockOutputManager.showOutputOn).not.toHaveBeenCalledWith(
'test-error',
expect.anything()
);
});
it('will reset testError state when test run ended', () => {
const sut = newJestExt();
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
const process: any = { id: 'a process id', request: { type: 'watch' } };

onRunEvent({ type: 'test-error', process });
expect(process.userData?.testError).toEqual(true);

onRunEvent({ type: 'end', process });
expect(process.userData?.testError).toBeUndefined();
});
});
it('when setting changed, output setting will change accordingly', () => {
const runMode = new RunMode({ type: 'watch', deferred: false });
Expand Down

0 comments on commit cfe5d96

Please sign in to comment.