microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
620c8eda81e893aba9c58355cb03624bb3ce8de1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

test/common/extensionMessaging.test.ts

52lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import {MessagingHelper} from "../../src/common/extensionMessaging";
5
6import {RemoteExtension} from "../../src/common/remoteExtension";
7
8import * as assert from "assert";
9import * as Q from "q";
10import * as rpc from "noice-json-rpc";
11import * as WebSocket from "ws";
12import WebSocketServer = WebSocket.Server;
13
14let mockServer: WebSocketServer;
15
16suite("extensionMessaging", function() {
17 suite("commonContext", function() {
18 const projectRootPath = "/myPath";
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 });
29
30 teardown(function() {
31 if (mockServer) {
32 mockServer.close();
33 }
34 });
35
36 test("should successfully send a message", function(done: MochaDone) {
37 const sender = RemoteExtension.atProjectRootPath(projectRootPath);
38 mockServer.on("error", done);
39
40 Q({})
41 .then(function() {
42 return sender.stopMonitoringLogcat()
43 .then((message: any) => {
44 return message.data;
45 });
46 })
47 .then(function(message) {
48 assert.equal(message, "STOP_MONITORING_LOGCAT");
49 }).done(() => done(), done);
50 });
51 });
52});
53