This commit is contained in:
Jun Han 2017-08-16 10:27:41 +08:00 коммит произвёл GitHub
Родитель b657b76820
Коммит 95da103e91
6 изменённых файлов: 75 добавлений и 39 удалений

4
.vscode/launch.json поставляемый
Просмотреть файл

@ -10,7 +10,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm"
},
{
@ -21,7 +21,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
"preLaunchTask": "npm"
}
]

Просмотреть файл

@ -30,6 +30,7 @@
},
"activationEvents": [
"*",
"onView:iotHubDevices",
"onCommand:azure-iot-toolkit.sendD2CMessage",
"onCommand:azure-iot-toolkit.startMonitorIoTHubMessage",
"onCommand:azure-iot-toolkit.sendC2DMessage",
@ -268,7 +269,8 @@
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"tslint": "tslint -t verbose src/**/*.ts",
"version": "tsc -v"
"version": "tsc -v",
"test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/mocha": "^2.2.32",

Просмотреть файл

@ -41,18 +41,6 @@ export function activate(context: vscode.ExtensionContext) {
azureIoTExplorer.stopMonitorC2DMessage();
});
let sendMessageToEventHub = vscode.commands.registerCommand("azure-iot-toolkit.sendMessageToEventHub", () => {
azureIoTExplorer.sendMessageToEventHub();
});
let startMonitorEventHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorEventHubMessage", () => {
azureIoTExplorer.startMonitorEventHubMessage();
});
let stopMonitorEventHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorEventHubMessage", () => {
azureIoTExplorer.stopMonitorEventHubMessage();
});
let listDevice = vscode.commands.registerCommand("azure-iot-toolkit.listDevice", () => {
azureIoTExplorer.listDevice();
});
@ -87,9 +75,6 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(sendC2DMessage);
context.subscriptions.push(startMonitorC2DMessage);
context.subscriptions.push(stopMonitorC2DMessage);
context.subscriptions.push(sendMessageToEventHub);
context.subscriptions.push(startMonitorEventHubMessage);
context.subscriptions.push(stopMonitorEventHubMessage);
context.subscriptions.push(listDevice);
context.subscriptions.push(createDevice);
context.subscriptions.push(deleteDevice);

Просмотреть файл

@ -1,22 +1,54 @@
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
import * as assert from "assert";
import * as vscode from "vscode";
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
const extensionId = "formulahendry.azure-iot-toolkit";
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import * as myExtension from '../src/extension';
// Defines a Mocha test suite to group tests of similar kind together
suite("Extension Tests", () => {
// Defines a Mocha unit test
test("Something 1", () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
test("should be present", () => {
assert.ok(vscode.extensions.getExtension(extensionId));
});
});
// tslint:disable-next-line:only-arrow-functions
test("should be able to activate the extension", function (done) {
this.timeout(60 * 1000);
const extension = vscode.extensions.getExtension(extensionId);
if (!extension.isActive) {
extension.activate().then((api) => {
done();
}, () => {
done("Failed to activate extension");
});
} else {
done();
}
});
test("should be able to register iot toolkit commands", () => {
return vscode.commands.getCommands(true).then((commands) => {
const COMMANDS = [
"azure-iot-toolkit.refreshDeviceTree",
"azure-iot-toolkit.getDevice",
"azure-iot-toolkit.sendD2CMessage",
"azure-iot-toolkit.startMonitorIoTHubMessage",
"azure-iot-toolkit.stopMonitorIoTHubMessage",
"azure-iot-toolkit.sendC2DMessage",
"azure-iot-toolkit.startMonitorC2DMessage",
"azure-iot-toolkit.stopMonitorC2DMessage",
"azure-iot-toolkit.listDevice",
"azure-iot-toolkit.createDevice",
"azure-iot-toolkit.deleteDevice",
"azure-iot-toolkit.invokeDeviceMethod",
"azure-iot-toolkit.getDeviceTwin",
"azure-iot-toolkit.updateDeviceTwin",
].sort();
const foundCommands = commands.filter((value) => {
return value.startsWith("azure-iot-toolkit.");
}).sort();
const errorMsg = "Some iot toolkit commands are not registered properly or a new command is not added to the test";
assert.equal(JSON.stringify(foundCommands), JSON.stringify(COMMANDS), errorMsg);
});
});
});

Просмотреть файл

@ -10,13 +10,13 @@
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.
var testRunner = require('vscode/lib/testrunner');
import testRunner = require("vscode/lib/testrunner");
// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true // colored output from test results
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true, // colored output from test results
});
module.exports = testRunner;
module.exports = testRunner;

17
test/utility.test.ts Normal file
Просмотреть файл

@ -0,0 +1,17 @@
import * as assert from "assert";
import * as vscode from "vscode";
import { Constants } from "../src/constants";
import { Utility } from "../src/utility";
suite("Utility Tests ", () => {
test("should be able to get hostname", () => {
let hostname = Utility.getHostName("HostName=iot-hub-test.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=abcdef");
assert.equal(hostname, "iot-hub-test.azure-devices.net");
});
test("should be able to get config", () => {
let iotHubD2CMessageStringify = Utility.getConfigFlag(Constants.IoTHubD2CMessageStringifyKey);
assert.equal(iotHubD2CMessageStringify, true);
});
});