diff --git a/release-notes/release-note-v6.md b/release-notes/release-note-v6.md index 6123c9b25..2f36fb902 100644 --- a/release-notes/release-note-v6.md +++ b/release-notes/release-note-v6.md @@ -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) diff --git a/src/JestExt/core.ts b/src/JestExt/core.ts index aaa263558..381db50be 100644 --- a/src/JestExt/core.ts +++ b/src/JestExt/core.ts @@ -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': diff --git a/tests/JestExt/core.test.ts b/tests/JestExt/core.test.ts index a1cc47644..a9b56b71c 100644 --- a/tests/JestExt/core.test.ts +++ b/tests/JestExt/core.test.ts @@ -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).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).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).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).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 });