Skip to content

Commit b1bd233

Browse files
committed
Improvements and fixes
1 parent 883871c commit b1bd233

4 files changed

Lines changed: 65 additions & 57 deletions

File tree

src/debugTracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class DebugTracker implements vscode.DebugAdapterTracker {
3434
return;
3535
}
3636
const line: string = (message.body.output as string).replace(/\n/, '');
37-
//console.log(`${line}`);
37+
this.run.appendOutput(line + '\r\n');
3838
if (this.className === undefined) {
3939
const classBegin = line.match(/^ ([%\dA-Za-z][\dA-Za-z\.]*) begins \.\.\.$/);
4040
if (classBegin) {

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export async function activate(context: vscode.ExtensionContext) {
8383
context.subscriptions.push(loadedTestController);
8484
await setupServerTestsController();
8585

86-
historyBrowserController = vscode.tests.createTestController(`${extensionId}-History`, '$(history) Testing History');
86+
historyBrowserController = vscode.tests.createTestController(`${extensionId}-History`, '$(history) Recent History');
8787
context.subscriptions.push(historyBrowserController);
8888
await setupHistoryExplorerController();
8989

src/historyExplorer.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ export async function setupHistoryExplorerController() {
3838
}
3939
}
4040

41-
const refresh = (token?: vscode.CancellationToken) => {
42-
historyBrowserController.items.replace([historyBrowserController.createTestItem('-', 'loading...')]);
43-
replaceRootItems(historyBrowserController);
44-
}
45-
refresh();
46-
4741
// Add a manual Refresh button
48-
historyBrowserController.refreshHandler = refresh;
42+
historyBrowserController.refreshHandler = (token?: vscode.CancellationToken) => {
43+
historyBrowserController.items.replace([historyBrowserController.createTestItem('-', 'loading...')]);
44+
replaceRootItems(historyBrowserController);
45+
}
4946

5047
}
5148

@@ -170,7 +167,9 @@ async function addTestMethods(item: vscode.TestItem, controller: vscode.TestCont
170167
if (response) {
171168
const run = controller.createTestRun(new vscode.TestRunRequest(), `Item '${item.label}' history`, false);
172169
response?.data?.result?.content?.forEach(element => {
173-
const child = controller.createTestItem(`${item.id}:${element.ID}`, `${element.Name}`);
170+
const methodName: string = element.Name;
171+
// We drop the first 4 characters of the method name because they should always be "Test"
172+
const child = controller.createTestItem(`${item.id}:${element.ID}`, `${methodName.slice(4)}`);
174173
child.canResolveChildren = true;
175174
item.children.add(child);
176175

src/serverTests.ts

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ async function resolveItemChildren(item: vscode.TestItem) {
2222
{ query: `CALL %Dictionary.ClassDefinition_SubclassOf('%UnitTest.TestCase', '${(namespace === "%SYS" ? "" : "@")}')` },
2323
);
2424
if (response) {
25-
response?.data?.result?.content?.forEach(async element => {
25+
for await (const element of response?.data?.result?.content) {
2626
const fullClassName: string = element.Name;
27-
28-
const tiClass = loadedTestController.createTestItem(
29-
`${item.id}:${fullClassName}`,
30-
fullClassName,
31-
vscode.Uri.from({
32-
scheme: item.uri?.scheme === "isfs" ? "isfs" : "isfs-readonly",
33-
authority: item.id.toLowerCase(),
34-
path: "/" + fullClassName.replace(/\./g, "/") + ".cls"
35-
})
36-
);
37-
const symbols = await vscode.commands.executeCommand<vscode.ProviderResult<vscode.SymbolInformation[] | vscode.DocumentSymbol[]>>('vscode.executeDocumentSymbolProvider', tiClass.uri);
38-
if (symbols?.length === 1 && symbols[0].kind === vscode.SymbolKind.Class) {
39-
const symbol = symbols[0];
40-
tiClass.range = (symbol as vscode.DocumentSymbol).range || (symbol as vscode.SymbolInformation).location.range;
41-
(symbol as vscode.DocumentSymbol).children.forEach(childSymbol => {
42-
if (childSymbol.kind === vscode.SymbolKind.Method && childSymbol.name.startsWith("Test")) {
43-
const testMethodName = childSymbol.name;
44-
const tiMethod = loadedTestController.createTestItem(
45-
`${tiClass.id}:${testMethodName}`,
46-
testMethodName.slice(4),
47-
tiClass.uri
48-
);
49-
tiMethod.range = childSymbol.range;
50-
tiClass.children.add(tiMethod);
51-
}
52-
});
53-
}
54-
if (tiClass.children.size > 0) {
55-
item.children.add(tiClass);
56-
}
57-
});
27+
const tiClass = loadedTestController.createTestItem(
28+
`${item.id}:${fullClassName}`,
29+
fullClassName,
30+
vscode.Uri.from({
31+
scheme: item.uri?.scheme === "isfs" ? "isfs" : "isfs-readonly",
32+
authority: item.id.toLowerCase(),
33+
path: "/" + fullClassName.replace(/\./g, "/") + ".cls",
34+
query: item.uri?.query
35+
})
36+
);
37+
const symbols = await vscode.commands.executeCommand<vscode.ProviderResult<vscode.SymbolInformation[] | vscode.DocumentSymbol[]>>('vscode.executeDocumentSymbolProvider', tiClass.uri);
38+
if (symbols?.length === 1 && symbols[0].kind === vscode.SymbolKind.Class) {
39+
const symbol = symbols[0];
40+
tiClass.range = (symbol as vscode.DocumentSymbol).range || (symbol as vscode.SymbolInformation).location.range;
41+
(symbol as vscode.DocumentSymbol).children.forEach(childSymbol => {
42+
if (childSymbol.kind === vscode.SymbolKind.Method && childSymbol.name.startsWith("Test")) {
43+
const testMethodName = childSymbol.name;
44+
const tiMethod = loadedTestController.createTestItem(
45+
`${tiClass.id}:${testMethodName}`,
46+
testMethodName.slice(4),
47+
tiClass.uri
48+
);
49+
tiMethod.range = childSymbol.range;
50+
tiClass.children.add(tiMethod);
51+
}
52+
});
53+
}
54+
if (tiClass.children.size > 0) {
55+
item.children.add(tiClass);
56+
}
57+
}
5858
}
5959
}
6060
}
@@ -82,14 +82,6 @@ export async function setupServerTestsController() {
8282
export async function runTestsHandler(request: vscode.TestRunRequest, cancellation: vscode.CancellationToken) {
8383
logger.info('runTestsHandler invoked');
8484

85-
const run = loadedTestController.createTestRun(
86-
request,
87-
'Test Results',
88-
true
89-
);
90-
91-
run.appendOutput('Fake output from fake run of fake server tests.\r\nTODO');
92-
9385
// For each authority (i.e. server:namespace) accumulate a map of the class-level Test nodes in the tree.
9486
// We don't yet support running only some TestXXX methods in a testclass
9587
const mapAuthorities = new Map<string, Map<string, vscode.TestItem>>();
@@ -121,7 +113,6 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
121113
// Mark each leaf item (a TestXXX method in a class) as enqueued and note its .cls file for copying.
122114
// Every leaf must have a uri.
123115
if (test.children.size === 0 && test.uri && test.parent) {
124-
run.enqueued(test);
125116
const authority = test.uri.authority;
126117
const mapTestClasses = mapAuthorities.get(authority) || new Map<string, vscode.TestItem>();
127118
mapTestClasses.set(test.uri.path, test.parent);
@@ -132,11 +123,23 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
132123
test.children.forEach(test => queue.push(test));
133124
}
134125

126+
if (mapAuthorities.size === 0) {
127+
// Nothing included
128+
vscode.window.showWarningMessage(`Empty test run`);
129+
return;
130+
}
131+
135132
if (cancellation.isCancellationRequested) {
136133
// TODO what?
137134
}
138135

139136
for await (const mapInstance of mapAuthorities) {
137+
138+
const run = loadedTestController.createTestRun(
139+
request,
140+
'Test Results',
141+
true
142+
);
140143
const authority = mapInstance[0];
141144
const mapTestClasses = mapInstance[1];
142145
const firstClassTestItem = Array.from(mapTestClasses.values())[0];
@@ -157,21 +160,25 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
157160
}
158161
for await (const mapInstance of mapTestClasses) {
159162
const key = mapInstance[0];
160-
const uri = mapInstance[1].uri;
163+
const classTest = mapInstance[1];
164+
const uri = classTest.uri;
161165
const keyParts = key.split('/');
162166
const clsFile = keyParts.pop() || '';
163-
const directoryUri = testRoot.with({path: testRoot.path.concat(keyParts.join('/'))});
167+
const directoryUri = testRoot.with({path: testRoot.path.concat(keyParts.join('/') + '/')});
164168
// This will always be true since every test added to the map above required a uri
165169
if (uri) {
166170
try {
167171
await vscode.workspace.fs.copy(uri, directoryUri.with({path: directoryUri.path.concat(clsFile)}));
168172
} catch (error) {
169173
console.log(error);
174+
continue;
170175
}
176+
classTest.children.forEach((methodTest) => {
177+
run.enqueued(methodTest);
178+
});
171179
}
172180
}
173181

174-
// Find this user's most recent TestInstance
175182
const serverSpec: IServerSpec = {
176183
username: server.username,
177184
name: server.serverName,
@@ -183,6 +190,8 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
183190
}
184191
}
185192
const namespace: string = server.namespace.toUpperCase();
193+
/*
194+
// Find this user's most recent TestInstance (TODO - unused, can be removed)
186195
const response = await makeRESTRequest(
187196
"POST",
188197
serverSpec,
@@ -196,6 +205,7 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
196205
const latestInstanceId = response?.data?.result?.content?.[0]?.ID;
197206
console.log(latestInstanceId);
198207
}
208+
*/
199209

200210
// Run tests through the debugger but only stop at breakpoints etc if user chose "Debug Test" instead of "Run Test"
201211
const runIndex = allTestRuns.push(run) - 1;
@@ -208,7 +218,8 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
208218
"testIdBase": firstClassTestItem.id.split(":", 2).join(":")
209219
};
210220
const sessionOptions: vscode.DebugSessionOptions = {
211-
noDebug: request.profile?.kind !== vscode.TestRunProfileKind.Debug
221+
noDebug: request.profile?.kind !== vscode.TestRunProfileKind.Debug,
222+
suppressDebugToolbar: request.profile?.kind !== vscode.TestRunProfileKind.Debug
212223
}
213224
if (!await vscode.debug.startDebugging(folder, configuration, sessionOptions)) {
214225
await vscode.window.showErrorMessage(`Failed to launch testing`, { modal: true });
@@ -218,6 +229,4 @@ export async function runTestsHandler(request: vscode.TestRunRequest, cancellati
218229
}
219230
}
220231
}
221-
222-
//run.end();
223232
}

0 commit comments

Comments
 (0)