microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.5.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/extension/packager.test.ts

61lines · 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 { Packager } from "../../src/common/packager";
5import { Request } from "../../src/common/node/request";
6
7import * as assert from "assert";
8import * as sinon from "sinon";
9
10suite("packager", function () {
11 suite("extensionContext", function () {
12 let requestStub: Sinon.SinonStub;
13
14 setup(() => {
15 requestStub = sinon.stub(Request, "request");
16 });
17
18 teardown(() => {
19 requestStub.restore();
20 });
21
22 test("isRunning should check correct status URL", function (done) {
23 requestStub.returns(Promise.resolve("packager-status:running"));
24
25 new Packager("/workspace", "/workspace", Packager.DEFAULT_PORT)
26 .isRunning()
27 .then(isRunning => {
28 assert(isRunning);
29 assert(requestStub.firstCall.args[0].match("http://localhost:" + Packager.DEFAULT_PORT));
30 })
31 .then(done, () => {
32 assert.fail(null, null, "packager was expected to be running");
33 done();
34 });
35 });
36
37 test("isRunning should report false if server doesn't respond", function (done) {
38 requestStub.returns(Promise.reject(void 0));
39
40 new Packager("/workspace", "/workspace", 9091)
41 .isRunning()
42 .then(isRunning => assert(!isRunning))
43 .then(done, () => {
44 assert.fail(null, null, "packager was not expected to be running");
45 done();
46 });
47 });
48
49 test("isRunning should report false if request fails", function (done) {
50 requestStub.returns(Promise.resolve("some_random_string"));
51
52 new Packager("/workspace", "/workspace", 10001)
53 .isRunning()
54 .then(isRunning => assert(!isRunning))
55 .then(done, () => {
56 assert.fail(null, null, "packager was not expected to be running");
57 done();
58 });
59 });
60 });
61});
62