Skip to content

Commit 048f9f0

Browse files
committed
Attempt to improve error detection
Update message for accuracy Remove debug logging Remove unnecessary logging Suggest to users that Deno may be failing to run tests Provide feedback even when tests take long
1 parent 105182a commit 048f9f0

File tree

3 files changed

+72
-15
lines changed

3 files changed

+72
-15
lines changed

src/commands/tests.sidebar.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import {
33
NotificationRequest,
44
nova,
55
Process,
6-
TextEditor,
7-
Transferrable,
8-
Workspace,
96
wrapCommand,
107
} from "../nova_utils.ts";
118
import TestsDataProvider, {
@@ -62,8 +59,6 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
6259
"state.json",
6360
);
6461

65-
console.log(hiddenWorkspaceDataPath);
66-
6762
function warningWasShown(path: string): boolean {
6863
try {
6964
const file = nova.fs.open(path) as FileTextMode;
@@ -81,11 +76,8 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
8176
);
8277
}
8378
nova.fs.open(path, "x").close();
84-
console.log("hi");
8579
const file = nova.fs.open(path, "w");
86-
console.log("hii");
8780
file.write(JSON.stringify({ warningWasShown: false }));
88-
console.log("hiii");
8981
file.close();
9082
return warningWasShown(path);
9183
}
@@ -110,7 +102,6 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
110102

111103
const oldFile = nova.fs.open(hiddenWorkspaceDataPath) as FileTextMode;
112104
const data = JSON.parse(oldFile.readlines().join("\n"));
113-
console.log(JSON.stringify(data));
114105
oldFile.close();
115106
nova.fs.remove(hiddenWorkspaceDataPath);
116107
nova.fs.open(hiddenWorkspaceDataPath, "x").close();
@@ -120,6 +111,16 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
120111
file.close();
121112
}
122113

114+
const timeoutID = setTimeout(() => {
115+
const stillRunningNotificationRequest = new NotificationRequest(
116+
"co.gwil.deno.notifications.runningTests",
117+
);
118+
stillRunningNotificationRequest.title = "The tests are still being run.";
119+
stillRunningNotificationRequest.body =
120+
"It's just taking a while. Please wait.";
121+
nova.notifications.add(stillRunningNotificationRequest);
122+
}, 3 * 1000);
123+
123124
try {
124125
await testsDataProvider.runTests();
125126
testsDataProvider.treeView.reload();
@@ -139,6 +140,8 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
139140
// shown as a Nova message regardless; doesn't produce a crash
140141
throw e;
141142
}
143+
} finally {
144+
clearTimeout(timeoutID);
142145
}
143146
}
144147
}

src/sidebars.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { TreeItem } from "./nova_utils.ts";
33
export interface Element {
44
toTreeItem: () => TreeItem;
55
children: Element[];
6+
path?: string;
7+
uri?: string;
8+
shouldDisambiguate?: boolean;
69
}
710

811
export class Header implements Element {

src/tests/TestsDataProvider.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
Color,
33
ColorComponents,
44
ColorFormat, // It is, actually, read. I think this message is due to a @ts-expect-error.
5+
getOverridableBoolean,
6+
NotificationRequest,
57
nova,
68
Process,
79
TreeDataProvider,
@@ -45,6 +47,7 @@ class Test implements Element {
4547
this.passed ? passedColorComponents : failedColorComponents,
4648
);
4749
item.descriptiveText = this.passed ? "Passed" : "Failed";
50+
item.contextValue = "test";
4851

4952
return item;
5053
}
@@ -81,6 +84,8 @@ export class TestFile implements Element {
8184
: TreeItemCollapsibleState.None;
8285
item.contextValue = "file";
8386
item.identifier = this.path;
87+
item.command = "co.gwil.deno.sidebars.tests.commands.open";
88+
8489
return item;
8590
}
8691
}
@@ -161,15 +166,26 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
161166
// The above process is carried out instead of replacing the `this.files` property. I prefer this because it does not remove test results from the sidebar.
162167
}
163168

164-
runTests() {
169+
runTests(tests?: string[]) {
165170
if (!nova.workspace.path) {
166171
throw new Error("This function requires a workspace path.");
167172
}
168173

169-
const paths = this.files.map((file) => file.path);
174+
const paths = tests ?? this.files.map((file) => file.path);
175+
const args = ["test", "-A"];
176+
177+
if (getOverridableBoolean("co.gwil.deno.config.enableUnstable")) {
178+
args.push("--unstable");
179+
}
180+
const potentialImportMapLocation = nova.workspace.config.get(
181+
"co.gwil.deno.config.import-map",
182+
);
183+
if (potentialImportMapLocation) {
184+
args.push("--import-map=" + potentialImportMapLocation);
185+
}
170186

171187
const options = {
172-
args: ["deno", "test", "-A", ...paths],
188+
args: ["deno", ...args, ...paths],
173189
cwd: nova.workspace.path,
174190
};
175191
const denoProcess = new Process("/usr/bin/env", options);
@@ -184,10 +200,14 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
184200
const output: TestFile[] = [];
185201

186202
let loggingError: UnexpectedLogError | null = null;
187-
denoProcess.onStdout((line) => {
203+
denoProcess.onStderr((line) => {
188204
// remove newline
189205
line = line.slice(0, -1);
190206
console.log(line);
207+
});
208+
denoProcess.onStdout((line) => {
209+
line = line.slice(0, -1);
210+
191211
// remove control (?) characters that make output colorful
192212
line = line.replace(
193213
CONTROL_REGEXP,
@@ -224,13 +244,44 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
224244
}
225245
});
226246

227-
const onExit = new Promise((resolve, reject) => {
247+
const onExit = new Promise<TestFile[]>((resolve, reject) => {
228248
denoProcess.onDidExit(() => {
229249
// TODO: explore the dangers regarding tests that take long to execute
230-
this.files = output;
231250
if (loggingError) {
232251
reject(loggingError);
233252
} else {
253+
for (const file of output) {
254+
const analogousIndex = this.files.findIndex(
255+
(oldFile) => oldFile.path == file.path,
256+
);
257+
if (analogousIndex != -1) {
258+
this.files[analogousIndex] = file;
259+
} else {
260+
this.files.push(file);
261+
}
262+
}
263+
264+
const paths = output.map((file) => file.path);
265+
const missingFiles = this.files.filter(
266+
(file) => !paths.includes(file.path),
267+
);
268+
for (
269+
const file of missingFiles
270+
) {
271+
file.children = [new Header("Failed to run")];
272+
}
273+
274+
if (missingFiles.length) {
275+
const configurationErrorNotificationRequest =
276+
new NotificationRequest(
277+
"co.gwil.deno.notifications.unexpectedEmptiness",
278+
);
279+
configurationErrorNotificationRequest.title = "Expecting more?";
280+
configurationErrorNotificationRequest.body =
281+
"Deno may be failing to run some tests. Check the extension console for logging.";
282+
nova.notifications.add(configurationErrorNotificationRequest);
283+
}
284+
234285
resolve(output);
235286
}
236287
});

0 commit comments

Comments
 (0)