-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.ts
More file actions
61 lines (51 loc) · 2 KB
/
Copy pathtesting.ts
File metadata and controls
61 lines (51 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { serviceToken } from '@kkdev92/vscode-ext-kit';
import { createTestHost } from '@kkdev92/vscode-ext-kit/testing';
import { CountProjects } from './commands-and-services.js';
import { app } from './extension.js';
interface ProjectIndex {
count(): number;
rebuild(signal: AbortSignal): Promise<number>;
}
const ProjectIndex = serviceToken<ProjectIndex>('sample.projectIndex');
// The *production* plan, on fakes. Not a rebuild of it for testing: `app.plan`
// is the very object the extension host would run, and no VS Code module is
// loaded to get at it.
export async function countsProjects(): Promise<number> {
const host = createTestHost({ plan: app.plan });
await host.start();
const count = await host.application.commands.execute(CountProjects);
await host.stop();
// Nothing left registered or undisposed: the assertion that catches a leak
// introduced three refactors from now.
const leaks = host.leaks();
if (leaks.registrations !== 0 || leaks.resources !== 0) {
throw new Error('the application leaked');
}
return count;
}
export async function countsWithAStubbedIndex(): Promise<number> {
const host = createTestHost({
plan: app.plan,
// Replace one singleton; the rest of the graph is untouched, and the plan
// itself is not modified.
configureServices: (services) => {
services.replaceSingleton(ProjectIndex, () => ({
count: () => 99,
rebuild: () => Promise.resolve(99),
}));
},
});
await host.start();
const count = await host.application.commands.execute(CountProjects);
await host.stop();
return count;
}
export async function readsASetting(): Promise<void> {
const host = createTestHost({ plan: app.plan });
// Arrange a scoped value the way VS Code would resolve it, then report the
// change with the leaf key VS Code actually reports.
host.settings._set('sample.projects', 'enabled', 'globalValue', false);
await host.start();
host.settings._fireChange(['sample.projects.enabled']);
await host.stop();
}