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

fixing #1145 #1146

Merged
merged 1 commit into from
May 3, 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
8 changes: 7 additions & 1 deletion src/test-provider/jest-test-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ export class JestTestRun implements JestExtOutput, TestRunProtocol {
if (!this._run && !this.isCancelled) {
const runName = `${this.name} (${this.runCount++})`;

this._run = this.createRun(this.request, runName);
// vscode seems to identify run by the request instance, so we need to create a new request for each run
const request = new vscode.TestRunRequest(
this.request.include,
this.request.exclude,
this.request.profile
);
this._run = this.createRun(request, runName);
this._run.appendOutput(`\r\nTestRun "${runName}" started\r\n`);

// ignore skipped tests if there are more than one test to run
Expand Down
30 changes: 29 additions & 1 deletion tests/test-provider/jest-test-runt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('JestTestRun', () => {
}));

mockRequest = {};
(vscode.TestRunRequest as jest.Mocked<any>).mockClear();
(vscode.TestRunRequest as jest.Mocked<any>).mockImplementation(() => mockRequest);
jestRun = new JestTestRun('test', mockContext, mockRequest, mockCreateTestRun);
});

Expand Down Expand Up @@ -365,10 +367,36 @@ describe('JestTestRun', () => {
expect(run1.end).toHaveBeenCalled();

const newRequest: any = { include: ['test1'] };
(vscode.TestRunRequest as jest.Mocked<any>).mockImplementation(() => newRequest);
jestRun.updateRequest(newRequest);
jestRun.started({} as any);
expect(mockCreateTestRun).toHaveBeenCalledTimes(2);
expect(mockCreateTestRun.mock.calls[1][0]).toBe(newRequest);
expect(mockCreateTestRun.mock.calls[1][0]).toEqual(newRequest);
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(2);
});
});

describe('supports continuous test run', () => {
it('by start/stop underlying TestRun per continuous run session', () => {
jestRun = new JestTestRun('test', mockContext, mockRequest, mockCreateTestRun);

// first run
jestRun.started({} as any);
expect(mockCreateTestRun).toHaveBeenCalledTimes(1);
const run1 = mockCreateTestRun.mock.results[0].value;
expect(run1.started).toHaveBeenCalled();
jestRun.end();
expect(run1.end).toHaveBeenCalled();
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(1);

// 2nd run
jestRun.started({} as any);
expect(mockCreateTestRun).toHaveBeenCalledTimes(2);
const run2 = mockCreateTestRun.mock.results[1].value;
expect(run2.started).toHaveBeenCalled();
jestRun.end();
expect(run2.end).toHaveBeenCalled();
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(2);
});
});
describe('cancel', () => {
Expand Down
Loading