Skip to content

Commit

Permalink
fixing #1145 (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed May 3, 2024
1 parent 0828289 commit 263dd1b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
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

0 comments on commit 263dd1b

Please sign in to comment.