microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/common/extensionMessaging.test.ts
52lines · modeblame
347157a1Joshua Skelton10 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
7daed3fcArtem Egorov8 years ago | 4 | import {MessagingHelper} from "../../src/common/extensionMessaging"; |
347157a1Joshua Skelton10 years ago | 5 | |
3c172a05Artem Egorov8 years ago | 6 | import {RemoteExtension} from "../../src/common/remoteExtension"; |
725cf712digeff10 years ago | 7 | |
347157a1Joshua Skelton10 years ago | 8 | import * as assert from "assert"; |
| 9 | import * as Q from "q"; | |
7daed3fcArtem Egorov8 years ago | 10 | import * as rpc from "noice-json-rpc"; |
| 11 | import * as WebSocket from "ws"; | |
| 12 | import WebSocketServer = WebSocket.Server; | |
347157a1Joshua Skelton10 years ago | 13 | |
7daed3fcArtem Egorov8 years ago | 14 | let mockServer: WebSocketServer; |
8f09b17cJoshua Skelton10 years ago | 15 | |
347157a1Joshua Skelton10 years ago | 16 | suite("extensionMessaging", function() { |
| 17 | suite("commonContext", function() { | |
d3950d7edigeff10 years ago | 18 | const projectRootPath = "/myPath"; |
7daed3fcArtem Egorov8 years ago | 19 | const port: string = MessagingHelper.getPath(projectRootPath); |
| 20 | setup(function () { | |
| 21 | mockServer = new WebSocketServer({port: <any>port}); | |
| 22 | let api = new rpc.Server(mockServer).api(); | |
| 23 | api.Extension.expose({ | |
| 24 | stopMonitoringLogcat: function () { | |
| 25 | return {data: "STOP_MONITORING_LOGCAT"}; | |
| 26 | }, | |
| 27 | }); | |
| 28 | }); | |
d3950d7edigeff10 years ago | 29 | |
347157a1Joshua Skelton10 years ago | 30 | teardown(function() { |
8f09b17cJoshua Skelton10 years ago | 31 | if (mockServer) { |
| 32 | mockServer.close(); | |
347157a1Joshua Skelton10 years ago | 33 | } |
| 34 | }); | |
| 35 | | |
| 36 | test("should successfully send a message", function(done: MochaDone) { | |
c7f1165cdigeff10 years ago | 37 | const sender = RemoteExtension.atProjectRootPath(projectRootPath); |
347157a1Joshua Skelton10 years ago | 38 | mockServer.on("error", done); |
| 39 | | |
| 40 | Q({}) | |
| 41 | .then(function() { | |
7daed3fcArtem Egorov8 years ago | 42 | return sender.stopMonitoringLogcat() |
| 43 | .then((message: any) => { | |
| 44 | return message.data; | |
| 45 | }); | |
ad7eb7feJoshua Skelton10 years ago | 46 | }) |
7daed3fcArtem Egorov8 years ago | 47 | .then(function(message) { |
| 48 | assert.equal(message, "STOP_MONITORING_LOGCAT"); | |
347157a1Joshua Skelton10 years ago | 49 | }).done(() => done(), done); |
| 50 | }); | |
| 51 | }); | |
df1e4c6fdigeff10 years ago | 52 | }); |