-
-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathcore-service-impl.slow-test.ts
125 lines (112 loc) · 4.13 KB
/
core-service-impl.slow-test.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { CancellationTokenSource } from '@theia/core/lib/common/cancellation';
import { CommandRegistry } from '@theia/core/lib/common/command';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import { isWindows } from '@theia/core/lib/common/os';
import { FileUri } from '@theia/core/lib/common/file-uri';
import { Container, injectable } from '@theia/core/shared/inversify';
import { expect } from 'chai';
import {
BoardsService,
CoreService,
SketchesService,
isCompileSummary,
} from '../../common/protocol';
import { createBaseContainer, startDaemon } from './node-test-bindings';
const testTimeout = 30_000;
const setupTimeout = 5 * 60 * 1_000; // five minutes
const avr = 'arduino:avr';
const uno = 'arduino:avr:uno';
describe('core-service-impl', () => {
let container: Container;
let toDispose: DisposableCollection;
beforeEach(async function () {
this.timeout(setupTimeout);
toDispose = new DisposableCollection();
container = await createContainer();
await start(container, toDispose);
});
afterEach(() => toDispose.dispose());
describe('compile', () => {
it('should execute a command with the compile summary, including the build path', async function () {
this.timeout(testTimeout);
const coreService = container.get<CoreService>(CoreService);
const sketchesService = container.get<SketchesService>(SketchesService);
const commandService =
container.get<TestCommandRegistry>(TestCommandRegistry);
const sketch = await sketchesService.createNewSketch();
await coreService.compile({
fqbn: uno,
sketch,
optimizeForDebug: false,
sourceOverride: {},
verbose: true,
});
const executedBuildDidCompleteCommands =
commandService.executedCommands.filter(
([command]) =>
command === 'arduino.languageserver.notifyBuildDidComplete'
);
expect(executedBuildDidCompleteCommands.length).to.be.equal(1);
const [, args] = executedBuildDidCompleteCommands[0];
expect(args.length).to.be.equal(1);
const arg = args[0];
expect(isCompileSummary(arg)).to.be.true;
expect('buildOutputUri' in arg).to.be.true;
expect(arg.buildOutputUri).to.be.not.undefined;
const tempBuildPaths = await sketchesService.tempBuildPath(sketch);
if (isWindows) {
expect(tempBuildPaths.length).to.be.greaterThan(1);
} else {
expect(tempBuildPaths.length).to.be.equal(1);
}
const { buildOutputUri } = arg;
const buildOutputPath = FileUri.fsPath(buildOutputUri).toString();
expect(tempBuildPaths.includes(buildOutputPath)).to.be.true;
});
});
});
async function start(
container: Container,
toDispose: DisposableCollection
): Promise<void> {
await startDaemon(container, toDispose, async (container) => {
const boardService = container.get<BoardsService>(BoardsService);
const searchResults = await boardService.search({ query: avr });
const platform = searchResults.find(({ id }) => id === avr);
if (!platform) {
throw new Error(`Could not find platform: ${avr}`);
}
await boardService.install({ item: platform, skipPostInstall: true });
});
}
async function createContainer(): Promise<Container> {
return createBaseContainer({
additionalBindings: (bind, rebind) => {
bind(TestCommandRegistry).toSelf().inSingletonScope();
rebind(CommandRegistry).toService(TestCommandRegistry);
},
});
}
@injectable()
class TestCommandRegistry extends CommandRegistry {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly executedCommands: [string, any[]][] = [];
override async executeCommand<T>(
commandId: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
): Promise<T | undefined> {
const { token } = new CancellationTokenSource();
this.onWillExecuteCommandEmitter.fire({
commandId,
args,
token,
waitUntil: () => {
// NOOP
},
});
this.executedCommands.push([commandId, args]);
this.onDidExecuteCommandEmitter.fire({ commandId, args });
return undefined;
}
}