Skip to content

Commit cea62e3

Browse files
committed
Added unit test for getExecPath
1 parent 6618816 commit cea62e3

File tree

7 files changed

+512
-58
lines changed

7 files changed

+512
-58
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ node_modules/
22
# .node_modules is a hack for the electron builder.
33
.node_modules/
44
lib/
5-
build/
65
downloads/
6+
build/
77
!electron/build/
88
src-gen/
99
browser-app/webpack.config.js
1010
electron-app/webpack.config.js
11-
.DS_Store
1211
/workspace/static
12+
.DS_Store
1313
# switching from `electron` to `browser` in dev mode.
1414
.browser_modules
1515
# LS logs
1616
inols*.log
17+
yarn-error.log

arduino-ide-extension/package.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"@theia/search-in-workspace": "next",
2323
"@theia/terminal": "next",
2424
"@theia/workspace": "next",
25-
"@types/google-protobuf": "^3.7.1",
2625
"@types/dateformat": "^3.0.1",
26+
"@types/google-protobuf": "^3.7.1",
2727
"@types/ps-tree": "^1.1.0",
2828
"@types/react-select": "^3.0.0",
2929
"@types/which": "^1.3.1",
@@ -47,19 +47,37 @@
4747
"generate-protocol": "node ./scripts/generate-protocol.js",
4848
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
4949
"build": "tsc && ncp ./src/node/cli-protocol/ ./lib/node/cli-protocol/ && yarn lint",
50-
"watch": "tsc -w"
50+
"watch": "tsc -w",
51+
"test": "mocha \"./test/**/*.test.ts\""
52+
},
53+
"mocha": {
54+
"require": [
55+
"ts-node/register",
56+
"reflect-metadata/Reflect"
57+
],
58+
"reporter": "spec",
59+
"colors": true,
60+
"watch-extensions": "ts,tsx",
61+
"timeout": 10000
5162
},
5263
"devDependencies": {
64+
"@types/chai": "^4.2.7",
65+
"@types/chai-string": "^1.4.2",
66+
"@types/mocha": "^5.2.7",
67+
"chai": "^4.2.0",
68+
"chai-string": "^1.5.0",
5369
"decompress": "^4.2.0",
5470
"decompress-targz": "^4.1.1",
5571
"decompress-unzip": "^4.0.1",
5672
"download": "^7.1.0",
5773
"grpc-tools": "^1.8.0",
5874
"grpc_tools_node_protoc_ts": "^2.5.8",
75+
"mocha": "^7.0.0",
5976
"moment": "^2.24.0",
6077
"ncp": "^2.0.0",
6178
"rimraf": "^2.6.1",
6279
"shelljs": "^0.8.3",
80+
"ts-node": "^8.6.2",
6381
"tslint": "^5.5.0",
6482
"typescript": "3.5.3",
6583
"uuid": "^3.2.1",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as os from 'os';
2+
import { expect, use } from 'chai';
3+
import { NullLogger } from './logger';
4+
import { getExecPath } from '../../lib/node/exec-util'
5+
6+
use(require('chai-string'));
7+
8+
describe('getExecPath', () => {
9+
it('should resolve arduino-cli', async () => {
10+
const path = await getExecPath('arduino-cli', new NullLogger(), 'version');
11+
if (os.platform() === 'win32')
12+
expect(path).to.endsWith('\\arduino-cli.exe');
13+
else
14+
expect(path).to.endsWith('/arduino-cli');
15+
});
16+
17+
it('should resolve arduino-language-server', async () => {
18+
const path = await getExecPath('arduino-language-server', new NullLogger());
19+
if (os.platform() === 'win32')
20+
expect(path).to.endsWith('\\arduino-language-server.exe');
21+
else
22+
expect(path).to.endsWith('/arduino-language-server');
23+
});
24+
25+
it('should resolve clangd', async () => {
26+
const path = await getExecPath('clangd', new NullLogger(), '--version', os.platform() !== 'win32');
27+
if (os.platform() === 'win32')
28+
expect(path).to.endsWith('\\clangd.exe');
29+
else
30+
expect(path).to.endsWith('/clangd');
31+
});
32+
});
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { ILogger, Loggable, LogLevel } from '@theia/core';
2+
3+
export class NullLogger implements ILogger {
4+
logLevel = 0;
5+
6+
setLogLevel(logLevel: number): Promise<void> {
7+
this.logLevel = logLevel;
8+
return Promise.resolve();
9+
}
10+
getLogLevel(): Promise<number> {
11+
return Promise.resolve(this.logLevel);
12+
}
13+
isEnabled(logLevel: number): Promise<boolean> {
14+
return Promise.resolve(logLevel >= this.logLevel);
15+
}
16+
ifEnabled(logLevel: number): Promise<void> {
17+
if (logLevel >= this.logLevel)
18+
return Promise.resolve();
19+
else
20+
return Promise.reject();
21+
}
22+
log(logLevel: any, loggable: any, ...rest: any[]) {
23+
return Promise.resolve();
24+
}
25+
26+
isTrace(): Promise<boolean> {
27+
return this.isEnabled(LogLevel.TRACE);
28+
}
29+
ifTrace(): Promise<void> {
30+
return this.ifEnabled(LogLevel.TRACE);
31+
}
32+
trace(arg: any | Loggable, ...params: any[]): Promise<void> {
33+
return this.log(LogLevel.TRACE, arg, ...params);
34+
}
35+
36+
isDebug(): Promise<boolean> {
37+
return this.isEnabled(LogLevel.DEBUG);
38+
}
39+
ifDebug(): Promise<void> {
40+
return this.ifEnabled(LogLevel.DEBUG);
41+
}
42+
debug(arg: any | Loggable, ...params: any[]): Promise<void> {
43+
return this.log(LogLevel.DEBUG, arg, ...params);
44+
}
45+
46+
isInfo(): Promise<boolean> {
47+
return this.isEnabled(LogLevel.INFO);
48+
}
49+
ifInfo(): Promise<void> {
50+
return this.ifEnabled(LogLevel.INFO);
51+
}
52+
info(arg: any | Loggable, ...params: any[]): Promise<void> {
53+
return this.log(LogLevel.INFO, arg, ...params);
54+
}
55+
56+
isWarn(): Promise<boolean> {
57+
return this.isEnabled(LogLevel.WARN);
58+
}
59+
ifWarn(): Promise<void> {
60+
return this.ifEnabled(LogLevel.WARN);
61+
}
62+
warn(arg: any | Loggable, ...params: any[]): Promise<void> {
63+
return this.log(LogLevel.WARN, arg, ...params);
64+
}
65+
66+
isError(): Promise<boolean> {
67+
return this.isEnabled(LogLevel.ERROR);
68+
}
69+
ifError(): Promise<void> {
70+
return this.ifEnabled(LogLevel.ERROR);
71+
}
72+
error(arg: any | Loggable, ...params: any[]): Promise<void> {
73+
return this.log(LogLevel.ERROR, arg, ...params);
74+
}
75+
76+
isFatal(): Promise<boolean> {
77+
return this.isEnabled(LogLevel.FATAL);
78+
}
79+
ifFatal(): Promise<void> {
80+
return this.ifEnabled(LogLevel.FATAL);
81+
}
82+
fatal(arg: any | Loggable, ...params: any[]): Promise<void> {
83+
return this.log(LogLevel.FATAL, arg, ...params);
84+
}
85+
86+
child(name: string): ILogger {
87+
return this;
88+
}
89+
}

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
GITHUB_TOKEN: $(Personal.GitHub.Token)
3535
THEIA_ELECTRON_SKIP_REPLACE_FFMPEG: 1
3636
displayName: Build
37+
- script: yarn test
38+
displayName: Test
3739
- bash: |
3840
./electron/packager/conf-node-gyp.sh
3941
yarn --cwd ./electron/packager/

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"rebuild:browser": "theia rebuild:browser",
1919
"rebuild:electron": "theia rebuild:electron",
2020
"start": "yarn --cwd ./browser-app start",
21-
"watch": "lerna run watch --parallel"
21+
"watch": "lerna run watch --parallel",
22+
"test": "lerna run test"
2223
},
2324
"workspaces": [
2425
"arduino-ide-extension",

0 commit comments

Comments
 (0)