Skip to content

Commit 105182a

Browse files
committed
Enable all permissions
This includes highly precise measuring of time, I think, as well as loading dynamic libraries. Remove VS Code settings folder I swear I'm not a traitor! I just use the thing sometimes 😊. Remove aosdijfoaisjdf.test.ts This is what I get for git commit -a…ing.
1 parent 6bbda91 commit 105182a

File tree

2 files changed

+68
-19
lines changed

2 files changed

+68
-19
lines changed

src/commands/tests.sidebar.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
FileTextMode,
23
NotificationRequest,
34
nova,
45
Process,
@@ -56,6 +57,69 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) {
5657
);
5758

5859
async function runAll() {
60+
const hiddenWorkspaceDataPath = nova.path.join(
61+
nova.extension.workspaceStoragePath,
62+
"state.json",
63+
);
64+
65+
console.log(hiddenWorkspaceDataPath);
66+
67+
function warningWasShown(path: string): boolean {
68+
try {
69+
const file = nova.fs.open(path) as FileTextMode;
70+
const data = JSON.parse(file.readlines().join("\n"));
71+
file.close();
72+
return data.warningWasShown;
73+
} catch {
74+
// I hope it's OK to create so many `File` objects.
75+
try {
76+
nova.fs.mkdir(nova.extension.workspaceStoragePath);
77+
} catch (e) {
78+
throw new Error(
79+
"Could not access the extension's workspace storage path.",
80+
{ cause: e },
81+
);
82+
}
83+
nova.fs.open(path, "x").close();
84+
console.log("hi");
85+
const file = nova.fs.open(path, "w");
86+
console.log("hii");
87+
file.write(JSON.stringify({ warningWasShown: false }));
88+
console.log("hiii");
89+
file.close();
90+
return warningWasShown(path);
91+
}
92+
}
93+
94+
if (!warningWasShown(hiddenWorkspaceDataPath)) {
95+
const permissionsNotificationRequest = new NotificationRequest(
96+
"co.gwil.deno.notifications.findSymbolUnavailable",
97+
);
98+
permissionsNotificationRequest.title =
99+
"Tests are awarded all permissions.";
100+
permissionsNotificationRequest.body =
101+
"Test files may access environment variables, load dynamic libraries, measure time in high resolution, utilize the network, read files and write files. This is not configurable at the moment.";
102+
permissionsNotificationRequest.actions = ["Cancel", "Allow"];
103+
104+
const response = await nova.notifications.add(
105+
permissionsNotificationRequest,
106+
);
107+
if (response.actionIdx == 0) {
108+
return;
109+
}
110+
111+
const oldFile = nova.fs.open(hiddenWorkspaceDataPath) as FileTextMode;
112+
const data = JSON.parse(oldFile.readlines().join("\n"));
113+
console.log(JSON.stringify(data));
114+
oldFile.close();
115+
nova.fs.remove(hiddenWorkspaceDataPath);
116+
nova.fs.open(hiddenWorkspaceDataPath, "x").close();
117+
const file = nova.fs.open(hiddenWorkspaceDataPath, "w");
118+
data.warningWasShown = true;
119+
file.write(JSON.stringify(data));
120+
file.close();
121+
}
122+
59123
try {
60124
await testsDataProvider.runTests();
61125
testsDataProvider.treeView.reload();

src/tests/TestsDataProvider.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Color,
33
ColorComponents,
44
ColorFormat, // It is, actually, read. I think this message is due to a @ts-expect-error.
5-
getOverridableBoolean,
65
nova,
76
Process,
87
TreeDataProvider,
@@ -46,7 +45,6 @@ class Test implements Element {
4645
this.passed ? passedColorComponents : failedColorComponents,
4746
);
4847
item.descriptiveText = this.passed ? "Passed" : "Failed";
49-
item.contextValue = "test";
5048

5149
return item;
5250
}
@@ -83,8 +81,6 @@ export class TestFile implements Element {
8381
: TreeItemCollapsibleState.None;
8482
item.contextValue = "file";
8583
item.identifier = this.path;
86-
item.command = "co.gwil.deno.sidebars.tests.commands.open";
87-
8884
return item;
8985
}
9086
}
@@ -165,26 +161,15 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
165161
// 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.
166162
}
167163

168-
runTests(tests?: string[]) {
164+
runTests() {
169165
if (!nova.workspace.path) {
170166
throw new Error("This function requires a workspace path.");
171167
}
172168

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

186171
const options = {
187-
args: ["deno", ...args, ...paths],
172+
args: ["deno", "test", "-A", ...paths],
188173
cwd: nova.workspace.path,
189174
};
190175
const denoProcess = new Process("/usr/bin/env", options);
@@ -242,10 +227,10 @@ export default class TestsDataProvider implements TreeDataProvider<Element> {
242227
const onExit = new Promise((resolve, reject) => {
243228
denoProcess.onDidExit(() => {
244229
// TODO: explore the dangers regarding tests that take long to execute
230+
this.files = output;
245231
if (loggingError) {
246232
reject(loggingError);
247233
} else {
248-
this.files = output;
249234
resolve(output);
250235
}
251236
});

0 commit comments

Comments
 (0)