Skip to content

Commit eaa432b

Browse files
committed
Add tests for new test warning behavior
1 parent d14c7b4 commit eaa432b

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

extensions/ql-vscode/test/vscode-tests/no-workspace/query-testing/test-adapter.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TestItem, TestItemCollection, TestRun } from "vscode";
22
import {
33
CancellationTokenSource,
4+
Location,
45
Range,
56
TestRunRequest,
67
Uri,
@@ -75,6 +76,11 @@ describe("test-adapter", () => {
7576
id: `test ${mockTestsInfo.hPath}`,
7677
uri: Uri.file(mockTestsInfo.hPath),
7778
} as TestItem,
79+
{
80+
children: { size: 0 } as TestItemCollection,
81+
id: `test ${mockTestsInfo.kPath}`,
82+
uri: Uri.file(mockTestsInfo.kPath),
83+
} as TestItem,
7884
];
7985
const childElements: IdTestItemPair[] = childItems.map((childItem) => [
8086
childItem.id,
@@ -87,15 +93,15 @@ describe("test-adapter", () => {
8793
id: `dir ${mockTestsInfo.testsPath}`,
8894
uri: Uri.file(mockTestsInfo.testsPath),
8995
children: {
90-
size: 3,
96+
size: 4,
9197
[Symbol.iterator]: childIteratorFunc,
9298
} as TestItemCollection,
9399
} as TestItem;
94100

95101
const request = new TestRunRequest([rootItem]);
96102
await testManager.run(request, new CancellationTokenSource().token);
97103

98-
expect(enqueuedSpy).toHaveBeenCalledTimes(3);
104+
expect(enqueuedSpy).toHaveBeenCalledTimes(4);
99105
expect(passedSpy).toHaveBeenCalledTimes(1);
100106
expect(passedSpy).toHaveBeenCalledWith(childItems[0], 3000);
101107
expect(erroredSpy).toHaveBeenCalledTimes(1);
@@ -112,6 +118,7 @@ describe("test-adapter", () => {
112118
],
113119
4000,
114120
);
121+
expect(failedSpy).toHaveBeenCalledTimes(2);
115122
expect(failedSpy).toHaveBeenCalledWith(
116123
childItems[2],
117124
[
@@ -121,7 +128,22 @@ describe("test-adapter", () => {
121128
],
122129
11000,
123130
);
124-
expect(failedSpy).toHaveBeenCalledTimes(1);
131+
expect(failedSpy).toHaveBeenCalledWith(
132+
childItems[3],
133+
[
134+
{
135+
message: "Test failed",
136+
},
137+
{
138+
message: "abc",
139+
location: new Location(
140+
Uri.file(mockTestsInfo.kPath),
141+
new Range(0, 0, 1, 1),
142+
),
143+
},
144+
],
145+
15000,
146+
);
125147
expect(endSpy).toHaveBeenCalledTimes(1);
126148
});
127149
});

extensions/ql-vscode/test/vscode-tests/no-workspace/query-testing/test-runner-helpers.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const mockTestsInfo = {
1111
dPath: Uri.parse("file:/ab/c/d.ql").fsPath,
1212
gPath: Uri.parse("file:/ab/c/e/f/g.ql").fsPath,
1313
hPath: Uri.parse("file:/ab/c/e/f/h.ql").fsPath,
14+
kPath: Uri.parse("file:/ab/c/e/f/k.ql").fsPath,
1415
};
1516

1617
/**
@@ -89,6 +90,28 @@ function mockRunTests(): jest.Mock<any, any> {
8990
evaluationMs: 6000,
9091
messages: [],
9192
});
93+
yield Promise.resolve({
94+
test: mockTestsInfo.kPath,
95+
pass: false,
96+
diff: ["jkh", "tuv"],
97+
failureStage: "RESULT",
98+
compilationMs: 7000,
99+
evaluationMs: 8000,
100+
// a warning in an otherwise successful test
101+
messages: [
102+
{
103+
position: {
104+
fileName: mockTestsInfo.kPath,
105+
line: 1,
106+
column: 1,
107+
endLine: 2,
108+
endColumn: 2,
109+
},
110+
message: "abc",
111+
severity: "WARNING",
112+
},
113+
],
114+
});
92115
})(),
93116
);
94117

extensions/ql-vscode/test/vscode-tests/no-workspace/query-testing/test-runner.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("test-runner", () => {
9494
eventHandlerSpy,
9595
);
9696

97-
expect(eventHandlerSpy).toHaveBeenCalledTimes(3);
97+
expect(eventHandlerSpy).toHaveBeenCalledTimes(4);
9898

9999
expect(eventHandlerSpy).toHaveBeenNthCalledWith(1, {
100100
test: mockTestsInfo.dPath,
@@ -133,6 +133,27 @@ describe("test-runner", () => {
133133
failureStage: "RESULT",
134134
messages: [],
135135
});
136+
expect(eventHandlerSpy).toHaveBeenNthCalledWith(4, {
137+
test: mockTestsInfo.kPath,
138+
pass: false,
139+
compilationMs: 7000,
140+
evaluationMs: 8000,
141+
diff: ["jkh", "tuv"],
142+
failureStage: "RESULT",
143+
messages: [
144+
{
145+
position: {
146+
fileName: mockTestsInfo.kPath,
147+
line: 1,
148+
column: 1,
149+
endLine: 2,
150+
endColumn: 2,
151+
},
152+
message: "abc",
153+
severity: "WARNING",
154+
},
155+
],
156+
});
136157
});
137158

138159
it("should reregister testproj databases around test run", async () => {

0 commit comments

Comments
 (0)