Skip to content

Commit cfe5d96

Browse files
authored
Fixed missing test error auto focusing for watch mode run (#1120)
1 parent df87aa1 commit cfe5d96

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

Diff for: release-notes/release-note-v6.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ This release is a patch release with the following changes:
5050

5151
**Bug Fixes**
5252
- 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)
53-
53+
- Fixed missing test error auto focusing for watch mode run. ([#1120](https://github.com/jest-community/vscode-jest/pull/1120) - @connectdotz)
54+
5455
**New Command**
5556
- 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)
5657

Diff for: src/JestExt/core.ts

+6
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ export class JestExt {
204204
case 'end': {
205205
const state = event.error ? 'exec-error' : 'done';
206206
this.updateStatusBar({ state });
207+
208+
// testError should be persistent per run-cycle. Not clear up this flag at end end of the cycle
209+
// could cause the processes with multiple run cycles, such as watch mode, to failed to act properly.
210+
if (event.process.userData?.testError) {
211+
event.process.userData.testError = undefined;
212+
}
207213
break;
208214
}
209215
case 'exit':

Diff for: tests/JestExt/core.test.ts

+41-7
Original file line numberDiff line numberDiff line change
@@ -1362,13 +1362,47 @@ describe('JestExt', () => {
13621362
onRunEvent({ type: 'start', process });
13631363
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
13641364
});
1365-
it('notify outputManager for test-error event', () => {
1366-
const sut = newJestExt();
1367-
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
1368-
const process = { id: 'a process id', request: { type: 'watch' } };
1369-
onRunEvent({ type: 'test-error', process });
1370-
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
1371-
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('test-error', expect.anything());
1365+
describe('when test errors occurred', () => {
1366+
it('will notify outputManager', () => {
1367+
const sut = newJestExt();
1368+
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
1369+
const process = { id: 'a process id', request: { type: 'watch' } };
1370+
onRunEvent({ type: 'test-error', process });
1371+
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith('run', expect.anything());
1372+
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith(
1373+
'test-error',
1374+
expect.anything()
1375+
);
1376+
});
1377+
it('will only notify outputManager once per run cycle', () => {
1378+
const sut = newJestExt();
1379+
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
1380+
const process = { id: 'a process id', request: { type: 'watch' } };
1381+
1382+
onRunEvent({ type: 'test-error', process, userData: {} });
1383+
expect(mockOutputManager.showOutputOn).toHaveBeenCalledWith(
1384+
'test-error',
1385+
expect.anything()
1386+
);
1387+
mockOutputManager.showOutputOn.mockClear();
1388+
1389+
onRunEvent({ type: 'test-error', process });
1390+
expect(mockOutputManager.showOutputOn).not.toHaveBeenCalledWith(
1391+
'test-error',
1392+
expect.anything()
1393+
);
1394+
});
1395+
it('will reset testError state when test run ended', () => {
1396+
const sut = newJestExt();
1397+
const onRunEvent = (sut.events.onRunEvent.event as jest.Mocked<any>).mock.calls[0][0];
1398+
const process: any = { id: 'a process id', request: { type: 'watch' } };
1399+
1400+
onRunEvent({ type: 'test-error', process });
1401+
expect(process.userData?.testError).toEqual(true);
1402+
1403+
onRunEvent({ type: 'end', process });
1404+
expect(process.userData?.testError).toBeUndefined();
1405+
});
13721406
});
13731407
it('when setting changed, output setting will change accordingly', () => {
13741408
const runMode = new RunMode({ type: 'watch', deferred: false });

0 commit comments

Comments
 (0)