Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 65ed13a

Browse files
add test cases for board/library manager
add test cases for board/library manager
2 parents f5019fe + 5bb7c8b commit 65ed13a

File tree

5 files changed

+125
-8
lines changed

5 files changed

+125
-8
lines changed

test/boardmanager.test.ts

+44-2
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+
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,44 @@ 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("Microsoft 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+
assert.equal(util.directoryExistsSync(packagePath), false,
134+
"Package path still exist after calling uninstall package,remove the board package failure");
135+
}
136+
} catch (error) {
137+
assert.fail(true, false, new Error(error).message, new Error(error).name);
138+
}
139+
});
140+
99141
});

test/commands.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as assert from "assert";
66
import * as vscode from "vscode";
77

88
// Defines a Mocha test suite to group tests of similar kind together
9-
suite("vscode-arduino extension commands test", () => {
9+
suite("Arduino: Commands Tests", () => {
1010
// tslint:disable-next-line: only-arrow-functions
1111
setup(function(done) {
1212
// Ensure that extension is activate while testing
@@ -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/extension.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as os from "os";
77
import * as vscode from "vscode";
88

99
// Defines a Mocha test suite to group tests of similar kind together
10-
suite("Arduino Extension Tests", () => {
10+
suite("Arduino: Extension Tests", () => {
1111
test("should be present", () => {
1212
assert.ok(vscode.extensions.getExtension("vsciot-vscode.vscode-arduino"));
1313
});
@@ -29,7 +29,7 @@ suite("Arduino Extension Tests", () => {
2929
}
3030
});
3131

32-
test("should be able to register Arduino commands", () => {
32+
test("should be able to register arduino commands", () => {
3333
return vscode.commands.getCommands(true).then((commands) => {
3434
const ARDUINO_COMMANDS = [
3535
"arduino.verify",

test/librarymanager.test.ts

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as assert from "assert";
2+
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,50 @@ 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+
assert.equal(util.directoryExistsSync(libPath), false,
102+
"Library path still exist after calling uninstall library,remove the library failure");
103+
}
104+
105+
} catch (error) {
106+
assert.fail(true, false, new Error(error).message, new Error(error).name);
107+
}
108+
});
109+
65110
});

test/verify.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from "vscode";
88
// Defines a Mocha test suite to group tests of similar kind together
99
suite("Arduino: Verify: Build (verify) your sketch files.", () => {
1010
// tslint:disable-next-line: only-arrow-functions
11-
test("should be able to run command: Arduino verify", function(done) {
11+
test("should be able to run command: arduino verify", function(done) {
1212
this.timeout(3 * 60 * 1000);
1313
try {
1414
// Press ctrl+alt+r to run "arduino:verify" command.

0 commit comments

Comments
 (0)