Skip to content

Commit 2f07a5b

Browse files
v-czgv-czg
v-czg
authored and
v-czg
committed
add test cases for board/library manager
1 parent 2dd0ccf commit 2f07a5b

File tree

3 files changed

+118
-4
lines changed

3 files changed

+118
-4
lines changed

test/boardmanager.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as assert from "assert";
22
import * as fs from "fs";
3+
import * as os from "os";
34
import * as Path from "path";
45
import * as TypeMoq from "typemoq";
56

67
import * as Resources from "./resources";
78

9+
import ArduinoContext from "..//src/arduinoContext";
810
import { ArduinoApp } from "../src/arduino/arduino";
911
import { ArduinoSettings } from "../src/arduino/arduinoSettings";
1012
import { parseBoardDescriptor } from "../src/arduino/board";
@@ -46,7 +48,7 @@ suite("Arduino: Board Manager.", () => {
4648
assert.equal(platforms[0].name, "Arduino AVR Boards", "Board Manager should display built Arduino AVR Boards");
4749
assert.equal(platforms[0].installedVersion, "1.6.18", "Arduino IDE built-in AVR board package version should be 1.6.18");
4850
assert.equal(platforms[0].rootBoardPath, Path.join(Resources.mockedIDEPackagePath, "arduino", "avr"),
49-
"Should be able to index root board path for installed boards");
51+
"Should be able to index root board path for installed boards");
5052
});
5153

5254
test("should be able to load installed platforms", () => {
@@ -63,7 +65,7 @@ suite("Arduino: Board Manager.", () => {
6365
assert.equal(boardManager.installedBoards.size, 46, "Arduino IDE should contains built-in AVR boards");
6466
assert.equal(boardManager.installedBoards.has("arduino:avr:yun"), true, "should parse installed boards from Arduino IDE built-in packages");
6567
assert.equal(boardManager.installedBoards.has("esp8266:esp8266:huzzah"), true,
66-
"should parse installed boards from custom packages ($sketchbook/hardware directory)");
68+
"should parse installed boards from custom packages ($sketchbook/hardware directory)");
6769
});
6870

6971
test("should parse boards.txt correctly", () => {
@@ -96,4 +98,43 @@ suite("Arduino: Board Manager.", () => {
9698
assert.equal(platformConfig.get("name"), "ESP8266 Modules");
9799
assert.equal(platformConfig.get("version"), "2.2.0");
98100
});
101+
102+
// Arduino: Board Manager: Manage packages for boards.
103+
// tslint:disable-next-line: only-arrow-functions
104+
test("should be able to install boards packages", function(done) {
105+
this.timeout(4 * 60 * 1000);
106+
try {
107+
// Board Manager: install boards packages.
108+
ArduinoContext.arduinoApp.installBoard("Microsoft", "win10", "1.1.2", true).then((result) => {
109+
const arduinoSettings = ArduinoContext.arduinoApp.settings;
110+
const packagePath = Path.join(arduinoSettings.packagePath, "packages", "Microsoft");
111+
// check if the installation succeeds or not
112+
if (util.directoryExistsSync(packagePath)) {
113+
done();
114+
} else {
115+
done(new Error("esp8266 board package install failure, can't find package path :" + packagePath));
116+
}
117+
});
118+
119+
} catch (error) {
120+
done(new Error(error));
121+
}
122+
});
123+
124+
// Arduino: Board Manager: remove boards packages.
125+
// tslint:disable-next-line: only-arrow-functions
126+
test("should be able to remove boards packages", () => {
127+
try {
128+
// Board Manager: remove boards packages.
129+
const arduinoSettings = ArduinoContext.arduinoApp.settings;
130+
const packagePath = Path.join(arduinoSettings.packagePath, "packages", "Microsoft");
131+
if (util.directoryExistsSync(packagePath)) {
132+
ArduinoContext.arduinoApp.uninstallBoard("Microsoft", packagePath);
133+
134+
}
135+
} catch (error) {
136+
assert.fail(true, false, new Error(error).message, new Error(error).name);
137+
}
138+
});
139+
99140
});

test/commands.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ suite("vscode-arduino extension commands test", () => {
2323
}
2424
});
2525

26+
// Arduino: Initialize:Scaffold a VS Code project with an Arduino sketch.
27+
// tslint:disable-next-line: only-arrow-functions
28+
test("should be able to run command: Arduino.initialize", function(done) {
29+
this.timeout(60 * 1000);
30+
try {
31+
// run "Arduino: Boards Manager" command.
32+
vscode.commands.executeCommand("arduino.initialize").then((result) => {
33+
done();
34+
});
35+
36+
} catch (error) {
37+
done(new Error(error));
38+
}
39+
});
40+
41+
// Arduino: Library Manager: Add library to include path.
42+
// tslint:disable-next-line: only-arrow-functions
43+
test("should be able to run command: arduino.addLibPath", function(done) {
44+
this.timeout(60 * 1000);
45+
try {
46+
// Library Manager: Add library to include path.
47+
vscode.commands.executeCommand("arduino.addLibPath", "#include <AzureIoTHub.h>").then((result) => {
48+
done();
49+
});
50+
51+
} catch (error) {
52+
done(new Error(error));
53+
}
54+
});
55+
2656
// Arduino: Boards Manager : Manage packages for boards
2757
// tslint:disable-next-line: only-arrow-functions
2858
test("should be able to run command: arduino.showBoardManager", function(done) {

test/librarymanager.test.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as assert from "assert";
2+
import * as os from "os";
23
import * as Path from "path";
34
import * as TypeMoq from "typemoq";
45

56
import * as Resources from "./resources";
67

8+
import ArduinoContext from "..//src/arduinoContext";
79
import { ArduinoApp } from "../src/arduino/arduino";
810
import { ArduinoSettings } from "../src/arduino/arduinoSettings";
911
import { BoardManager } from "../src/arduino/boardManager";
1012
import { LibraryManager } from "../src/arduino/libraryManager";
13+
import * as util from "../src/common/util";
1114

1215
suite("Arduino: Library Manager.", () => {
1316

@@ -46,7 +49,7 @@ suite("Arduino: Library Manager.", () => {
4649
assert.equal(installedLibraries[0].name, "Ethernet");
4750
assert.equal(installedLibraries[0].builtIn, true);
4851
assert.equal(installedLibraries[0].srcPath, Path.join(Resources.mockedIDELibPath, "Ethernet", "src"),
49-
"Should be able to find src path of install library");
52+
"Should be able to find src path of install library");
5053

5154
assert.equal(installedLibraries[1].name, "AzureIoTHub");
5255
assert.equal(installedLibraries[1].builtIn, false);
@@ -58,8 +61,48 @@ suite("Arduino: Library Manager.", () => {
5861

5962
done();
6063
}).catch((error) => {
61-
done(error);
64+
done(error);
6265
});
6366
});
6467

68+
// Arduino: Library Manager: Install extenal libarary.
69+
// tslint:disable-next-line: only-arrow-functions
70+
test("should be able to Install libraries", function(done) {
71+
this.timeout(3 * 60 * 1000);
72+
try {
73+
// Library Manager: Install extenal libarary.
74+
ArduinoContext.arduinoApp.installLibrary("AzureIoTHub", "1.0.35", true).then((result) => {
75+
// check if the installation succeeds or not
76+
const arduinoSettings = ArduinoContext.arduinoApp.settings;
77+
const libPath = Path.join(arduinoSettings.sketchbookPath, "libraries", "AzureIoTHub");
78+
79+
if (util.directoryExistsSync(libPath)) {
80+
done();
81+
} else {
82+
done(new Error("AzureIoTHub library install failure, can't find library path :" + libPath));
83+
}
84+
});
85+
86+
} catch (error) {
87+
done(new Error(error));
88+
}
89+
});
90+
91+
// Arduino: Library Manager: remove extenal libarary.
92+
// tslint:disable-next-line: only-arrow-functions
93+
test("should be able to remove libraries", () => {
94+
try {
95+
// Library Manager: remove extenal libarary.
96+
const arduinoSettings = ArduinoContext.arduinoApp.settings;
97+
const libPath = Path.join(arduinoSettings.sketchbookPath, "libraries", "AzureIoTHub");
98+
99+
if (util.directoryExistsSync(libPath)) {
100+
ArduinoContext.arduinoApp.uninstallLibrary("AzureIoTHub", libPath);
101+
}
102+
103+
} catch (error) {
104+
assert.fail(true, false, new Error(error).message, new Error(error).name);
105+
}
106+
});
107+
65108
});

0 commit comments

Comments
 (0)