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

Fixed missing test error auto focusing for watch mode run #1120

Merged
merged 1 commit into from
Feb 22, 2024
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
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
Loading