Skip to content

Commit 263dd1b

Browse files
authored
fixing #1145 (#1146)
1 parent 0828289 commit 263dd1b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/test-provider/jest-test-run.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ export class JestTestRun implements JestExtOutput, TestRunProtocol {
6868
if (!this._run && !this.isCancelled) {
6969
const runName = `${this.name} (${this.runCount++})`;
7070

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

7480
// ignore skipped tests if there are more than one test to run

tests/test-provider/jest-test-runt.test.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ describe('JestTestRun', () => {
4444
}));
4545

4646
mockRequest = {};
47+
(vscode.TestRunRequest as jest.Mocked<any>).mockClear();
48+
(vscode.TestRunRequest as jest.Mocked<any>).mockImplementation(() => mockRequest);
4749
jestRun = new JestTestRun('test', mockContext, mockRequest, mockCreateTestRun);
4850
});
4951

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

367369
const newRequest: any = { include: ['test1'] };
370+
(vscode.TestRunRequest as jest.Mocked<any>).mockImplementation(() => newRequest);
368371
jestRun.updateRequest(newRequest);
369372
jestRun.started({} as any);
370373
expect(mockCreateTestRun).toHaveBeenCalledTimes(2);
371-
expect(mockCreateTestRun.mock.calls[1][0]).toBe(newRequest);
374+
expect(mockCreateTestRun.mock.calls[1][0]).toEqual(newRequest);
375+
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(2);
376+
});
377+
});
378+
379+
describe('supports continuous test run', () => {
380+
it('by start/stop underlying TestRun per continuous run session', () => {
381+
jestRun = new JestTestRun('test', mockContext, mockRequest, mockCreateTestRun);
382+
383+
// first run
384+
jestRun.started({} as any);
385+
expect(mockCreateTestRun).toHaveBeenCalledTimes(1);
386+
const run1 = mockCreateTestRun.mock.results[0].value;
387+
expect(run1.started).toHaveBeenCalled();
388+
jestRun.end();
389+
expect(run1.end).toHaveBeenCalled();
390+
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(1);
391+
392+
// 2nd run
393+
jestRun.started({} as any);
394+
expect(mockCreateTestRun).toHaveBeenCalledTimes(2);
395+
const run2 = mockCreateTestRun.mock.results[1].value;
396+
expect(run2.started).toHaveBeenCalled();
397+
jestRun.end();
398+
expect(run2.end).toHaveBeenCalled();
399+
expect(vscode.TestRunRequest).toHaveBeenCalledTimes(2);
372400
});
373401
});
374402
describe('cancel', () => {

0 commit comments

Comments
 (0)