microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.10

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/common/extensionMessaging.test.ts

52lines · modeblame

347157a1Joshua Skelton10 years ago1// 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 ago4import {MessagingHelper} from "../../src/common/extensionMessaging";
347157a1Joshua Skelton10 years ago5
3c172a05Artem Egorov8 years ago6import {RemoteExtension} from "../../src/common/remoteExtension";
725cf712digeff10 years ago7
347157a1Joshua Skelton10 years ago8import * as assert from "assert";
9import * as Q from "q";
7daed3fcArtem Egorov8 years ago10import * as rpc from "noice-json-rpc";
11import * as WebSocket from "ws";
12import WebSocketServer = WebSocket.Server;
347157a1Joshua Skelton10 years ago13
7daed3fcArtem Egorov8 years ago14let mockServer: WebSocketServer;
8f09b17cJoshua Skelton10 years ago15
347157a1Joshua Skelton10 years ago16suite("extensionMessaging", function() {
17suite("commonContext", function() {
d3950d7edigeff10 years ago18const projectRootPath = "/myPath";
7daed3fcArtem Egorov8 years ago19const port: string = MessagingHelper.getPath(projectRootPath);
20setup(function () {
21mockServer = new WebSocketServer({port: <any>port});
22let api = new rpc.Server(mockServer).api();
23api.Extension.expose({
24stopMonitoringLogcat: function () {
25return {data: "STOP_MONITORING_LOGCAT"};
26},
27});
28});
d3950d7edigeff10 years ago29
347157a1Joshua Skelton10 years ago30teardown(function() {
8f09b17cJoshua Skelton10 years ago31if (mockServer) {
32mockServer.close();
347157a1Joshua Skelton10 years ago33}
34});
35
36test("should successfully send a message", function(done: MochaDone) {
c7f1165cdigeff10 years ago37const sender = RemoteExtension.atProjectRootPath(projectRootPath);
347157a1Joshua Skelton10 years ago38mockServer.on("error", done);
39
40Q({})
41.then(function() {
7daed3fcArtem Egorov8 years ago42return sender.stopMonitoringLogcat()
43.then((message: any) => {
44return message.data;
45});
ad7eb7feJoshua Skelton10 years ago46})
7daed3fcArtem Egorov8 years ago47.then(function(message) {
48assert.equal(message, "STOP_MONITORING_LOGCAT");
347157a1Joshua Skelton10 years ago49}).done(() => done(), done);
50});
51});
df1e4c6fdigeff10 years ago52});