diff --git a/.vscode/launch.json b/.vscode/launch.json index c77b2ad..e37ef19 100644 --- a/.vscode/launch.json +++ b/.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" } ] diff --git a/package.json b/package.json index 95a4f5a..54ca5e1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/extension.ts b/src/extension.ts index 46f5926..d862591 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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); diff --git a/test/extension.test.ts b/test/extension.test.ts index 5c4a4da..5210df1 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -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)); }); -}); \ No newline at end of file + + // 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); + }); + }); +}); diff --git a/test/index.ts b/test/index.ts index 50bae45..09370a8 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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; \ No newline at end of file +module.exports = testRunner; diff --git a/test/utility.test.ts b/test/utility.test.ts new file mode 100644 index 0000000..ea194f1 --- /dev/null +++ b/test/utility.test.ts @@ -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); + }); +});