Skip to content

Commit 7e20f91

Browse files
committed
Enable tests to be run individually
1 parent 536e5bf commit 7e20f91

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/commands/tests.sidebar.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
wrapCommand,
77
} from "../nova_utils.ts";
88
import TestsDataProvider, {
9+
TestFile,
910
UnexpectedLogError,
1011
} from "../tests/TestsDataProvider.ts";
1112

@@ -152,8 +153,11 @@ export function registerRun(testsDataProvider: TestsDataProvider) {
152153
wrapCommand(run),
153154
);
154155

155-
function run() {
156-
testsDataProvider.runTests();
156+
async function run() {
157+
// This command is only available when `TestFile`s, exclusively, are selected.
158+
const selected = testsDataProvider.treeView.selection as TestFile[];
159+
await testsDataProvider.runTests(selected.map((file) => file.path));
160+
testsDataProvider.treeView.reload();
157161
}
158162
}
159163

src/tests/TestsDataProvider.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
171171
throw new Error("This function requires a workspace path.");
172172
}
173173

174+
const ranAll = !tests;
174175
const paths = tests ?? this.files.map((file) => file.path);
175176
const args = ["test", "-A"];
176177

@@ -246,7 +247,6 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
246247

247248
const onExit = new Promise<TestFile[]>((resolve, reject) => {
248249
denoProcess.onDidExit(() => {
249-
// TODO: explore the dangers regarding tests that take long to execute
250250
if (loggingError) {
251251
reject(loggingError);
252252
} else {
@@ -261,25 +261,28 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
261261
}
262262
}
263263

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-
}
264+
if (ranAll) {
265+
const paths = output.map((file) => file.path);
266+
const missingFiles = this.files.filter(
267+
(file) => !paths.includes(file.path),
268+
);
269+
for (
270+
const file of missingFiles
271+
) {
272+
file.children = [new Header("Failed to run")];
273+
}
273274

274-
if (missingFiles.length) {
275-
const configurationErrorNotificationRequest =
276-
new NotificationRequest(
277-
"co.gwil.deno.notifications.unexpectedEmptiness",
278-
);
279-
configurationErrorNotificationRequest.title = "Check the console.";
280-
configurationErrorNotificationRequest.body =
281-
"Deno may be failing to run some tests. Check the extension console for logging.";
282-
nova.notifications.add(configurationErrorNotificationRequest);
275+
if (missingFiles.length) {
276+
const configurationErrorNotificationRequest =
277+
new NotificationRequest(
278+
"co.gwil.deno.notifications.unexpectedEmptiness",
279+
);
280+
configurationErrorNotificationRequest.title =
281+
"Check the console.";
282+
configurationErrorNotificationRequest.body =
283+
"Deno may be failing to run some tests. Check the extension console for logging.";
284+
nova.notifications.add(configurationErrorNotificationRequest);
285+
}
283286
}
284287

285288
resolve(output);

0 commit comments

Comments
 (0)