microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.13

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/extension/packager.test.ts

61lines · modeblame

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