Skip to content

Commit 049fdc2

Browse files
author
Akos Kitta
committed
test: gRPC core client init integration test
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 9fff553 commit 049fdc2

8 files changed

+547
-79
lines changed

arduino-ide-extension/src/browser/create/create-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ export class CreateApi {
513513
const result = await resultProvider(response);
514514
const parseEnd = performance.now();
515515
console.debug(
516-
`HTTP ${fetchCount} ${method} ${url} [fetch: ${(
516+
`HTTP ${fetchCount} ${method}${url} [fetch: ${(
517517
fetchEnd - fetchStart
518518
).toFixed(2)} ms, parse: ${(parseEnd - parseStart).toFixed(
519519
2
Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,112 @@
1-
import { join } from 'path';
2-
import { homedir } from 'os';
3-
import { injectable } from '@theia/core/shared/inversify';
4-
import { FileUri } from '@theia/core/lib/node/file-uri';
1+
import {
2+
EnvVariable,
3+
EnvVariablesServer as TheiaEnvVariablesServer,
4+
} from '@theia/core/lib/common/env-variables/env-variables-protocol';
5+
import { isWindows } from '@theia/core/lib/common/os';
6+
import URI from '@theia/core/lib/common/uri';
57
import { BackendApplicationConfigProvider } from '@theia/core/lib/node/backend-application-config-provider';
6-
import { EnvVariablesServerImpl as TheiaEnvVariablesServerImpl } from '@theia/core/lib/node/env-variables/env-variables-server';
8+
import { FileUri } from '@theia/core/lib/node/file-uri';
9+
import {
10+
inject,
11+
injectable,
12+
postConstruct,
13+
} from '@theia/core/shared/inversify';
14+
import { list as listDrives } from 'drivelist';
15+
import { homedir } from 'os';
16+
import { join } from 'path';
17+
18+
@injectable()
19+
export class ConfigDirUriProvider {
20+
private uri: URI | undefined;
21+
22+
configDirUri(): URI {
23+
if (!this.uri) {
24+
this.uri = FileUri.create(
25+
join(homedir(), BackendApplicationConfigProvider.get().configDirName)
26+
);
27+
}
28+
return this.uri;
29+
}
30+
}
731

32+
// Copy-pasted from https://github.com/eclipse-theia/theia/blob/v1.31.1/packages/core/src/node/env-variables/env-variables-server.ts
33+
// to simplify the binding of the config directory location for tests.
834
@injectable()
9-
export class EnvVariablesServer extends TheiaEnvVariablesServerImpl {
10-
protected override readonly configDirUri = Promise.resolve(
11-
FileUri.create(
12-
join(homedir(), BackendApplicationConfigProvider.get().configDirName)
13-
).toString()
14-
);
35+
export class EnvVariablesServer implements TheiaEnvVariablesServer {
36+
@inject(ConfigDirUriProvider)
37+
private readonly configDirUriProvider: ConfigDirUriProvider;
38+
39+
private readonly envs: { [key: string]: EnvVariable } = {};
40+
private readonly homeDirUri = FileUri.create(homedir()).toString();
41+
42+
constructor() {
43+
const prEnv = process.env;
44+
Object.keys(prEnv).forEach((key: string) => {
45+
let keyName = key;
46+
if (isWindows) {
47+
keyName = key.toLowerCase();
48+
}
49+
this.envs[keyName] = { name: keyName, value: prEnv[key] };
50+
});
51+
}
52+
53+
@postConstruct()
54+
protected init(): void {
55+
console.log(
56+
`Configuration directory URI: '${this.configDirUriProvider
57+
.configDirUri()
58+
.toString()}'`
59+
);
60+
}
61+
62+
async getExecPath(): Promise<string> {
63+
return process.execPath;
64+
}
65+
66+
async getVariables(): Promise<EnvVariable[]> {
67+
return Object.keys(this.envs).map((key) => this.envs[key]);
68+
}
69+
70+
async getValue(key: string): Promise<EnvVariable | undefined> {
71+
if (isWindows) {
72+
key = key.toLowerCase();
73+
}
74+
return this.envs[key];
75+
}
76+
77+
async getConfigDirUri(): Promise<string> {
78+
return this.configDirUriProvider.configDirUri().toString();
79+
}
80+
81+
async getHomeDirUri(): Promise<string> {
82+
return this.homeDirUri;
83+
}
84+
85+
async getDrives(): Promise<string[]> {
86+
const uris: string[] = [];
87+
const drives = await listDrives();
88+
for (const drive of drives) {
89+
for (const mountpoint of drive.mountpoints) {
90+
if (this.filterHiddenPartitions(mountpoint.path)) {
91+
uris.push(FileUri.create(mountpoint.path).toString());
92+
}
93+
}
94+
}
95+
return uris;
96+
}
97+
98+
/**
99+
* Filters hidden and system partitions.
100+
*/
101+
private filterHiddenPartitions(path: string): boolean {
102+
// OS X: This is your sleep-image. When your Mac goes to sleep it writes the contents of its memory to the hard disk. (https://bit.ly/2R6cztl)
103+
if (path === '/private/var/vm') {
104+
return false;
105+
}
106+
// Ubuntu: This system partition is simply the boot partition created when the computers mother board runs UEFI rather than BIOS. (https://bit.ly/2N5duHr)
107+
if (path === '/boot/efi') {
108+
return false;
109+
}
110+
return true;
111+
}
15112
}

arduino-ide-extension/src/test/node/boards-service-impl.slow-test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
import { Container } from '@theia/core/shared/inversify';
33
import { expect } from 'chai';
44
import { BoardSearch, BoardsService } from '../../common/protocol';
5-
import {
6-
configureBackendApplicationConfigProvider,
7-
createBaseContainer,
8-
startDaemon,
9-
} from './test-bindings';
5+
import { createBaseContainer, startDaemon } from './test-bindings';
106

117
describe('boards-service-impl', () => {
128
let boardService: BoardsService;
139
let toDispose: DisposableCollection;
1410

1511
before(async function () {
16-
configureBackendApplicationConfigProvider();
1712
this.timeout(20_000);
1813
toDispose = new DisposableCollection();
19-
const container = createContainer();
14+
const container = await createContainer();
2015
await start(container, toDispose);
2116
boardService = container.get<BoardsService>(BoardsService);
2217
});
@@ -94,7 +89,7 @@ describe('boards-service-impl', () => {
9489
});
9590
});
9691

97-
function createContainer(): Container {
92+
async function createContainer(): Promise<Container> {
9893
return createBaseContainer();
9994
}
10095

0 commit comments

Comments
 (0)