Skip to content

Commit 3e4756d

Browse files
committed
Add apoloty to run with coverage
1 parent 09f9ecb commit 3e4756d

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/commonRunTestsHandler.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,49 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
143143
console.log(error);
144144
}
145145

146+
// Map of uri strings checked for presence of a coverage.list file, recording the relative path of those that were found
147+
const mapCoverageLists = new Map<string, string>();
148+
for await (const mapInstance of mapTestClasses) {
149+
const key = mapInstance[0];
150+
const pathParts = key.split('/');
151+
pathParts.pop();
152+
const sourceBaseUri = mapInstance[1].uri?.with({ path: mapInstance[1].uri.path.split('/').slice(0, -pathParts.length).join('/') });
153+
if (!sourceBaseUri) {
154+
console.log(`No sourceBaseUri for key=${key}`);
155+
continue;
156+
}
157+
while (pathParts.length > 1) {
158+
const currentPath = pathParts.join('/');
159+
// Check for coverage.list file here
160+
const coverageListUri = sourceBaseUri.with({ path: sourceBaseUri.path.concat(`${currentPath}/coverage.list`) });
161+
if (mapCoverageLists.has(coverageListUri.toString())) {
162+
// Already checked this uri path, and therefore all its ancestors
163+
break;
164+
}
165+
try {
166+
await vscode.workspace.fs.stat(coverageListUri);
167+
mapCoverageLists.set(coverageListUri.toString(), currentPath);
168+
} catch (error) {
169+
if (error.code !== vscode.FileSystemError.FileNotFound().code) {
170+
console.log(`Error checking for ${coverageListUri.toString()}:`, error);
171+
}
172+
mapCoverageLists.set(coverageListUri.toString(), '');
173+
}
174+
pathParts.pop();
175+
}
176+
}
177+
// Copy all coverage.list files found into the corresponding place under testRoot
178+
for await (const [uriString, path] of mapCoverageLists) {
179+
if (path.length > 0) {
180+
const coverageListUri = vscode.Uri.parse(uriString, true);
181+
try {
182+
await vscode.workspace.fs.copy(coverageListUri, testRoot.with({ path: testRoot.path.concat(`${path}/coverage.list`) }));
183+
} catch (error) {
184+
console.log(`Error copying ${coverageListUri.path}:`, error);
185+
}
186+
}
187+
}
188+
146189
// Next, copy the classes into the folder as a package hierarchy
147190
for await (const mapInstance of mapTestClasses) {
148191
const key = mapInstance[0];
@@ -186,11 +229,12 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
186229
}
187230
}
188231

232+
const managerClass = request.profile?.kind === vscode.TestRunProfileKind.Coverage ? "TestCoverage.Manager" : "%UnitTest.Manager";
189233
const configuration = {
190234
"type": "objectscript",
191235
"request": "launch",
192236
"name": `${controller.id.split("-").pop()}Tests:${serverSpec.name}:${namespace}:${username}`,
193-
"program": `##class(%UnitTest.Manager).RunTest("${testSpec}","${runQualifiers}")`,
237+
"program": `##class(${managerClass}).RunTest("${testSpec}","${runQualifiers}")`,
194238

195239
// Extra properties needed by our DebugAdapterTracker
196240
"testingRunIndex": runIndex,

src/localTests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async function resolveItemChildren(item: vscode.TestItem) {
7171
if (localTestController.items.size > 0) {
7272
localTestController.createRunProfile('Run Local Tests', vscode.TestRunProfileKind.Run, runTestsHandler, true);
7373
localTestController.createRunProfile('Debug Local Tests', vscode.TestRunProfileKind.Debug, runTestsHandler);
74+
localTestController.createRunProfile('Run Local Tests with Coverage', vscode.TestRunProfileKind.Coverage, runTestsHandler);
7475
}
7576
}
7677
}

src/serverTests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function resolveItemChildren(item?: vscode.TestItem) {
6666
if (loadedTestController.items.size > 0) {
6767
loadedTestController.createRunProfile('Run Server Tests', vscode.TestRunProfileKind.Run, runTestsHandler, true);
6868
loadedTestController.createRunProfile('Debug Server Tests', vscode.TestRunProfileKind.Debug, runTestsHandler);
69+
loadedTestController.createRunProfile('Run Server Tests with Coverage', vscode.TestRunProfileKind.Coverage, runTestsHandler);
6970
}
7071
}
7172
}

0 commit comments

Comments
 (0)