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 · modepreview

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import { Packager } from "../../src/common/packager";
import { Request } from "../../src/common/node/request";

import * as assert from "assert";
import * as sinon from "sinon";

suite("packager", function () {
    suite("extensionContext", function () {
        let requestStub: Sinon.SinonStub;

        setup(() => {
            requestStub = sinon.stub(Request, "request");
        });

        teardown(() => {
            requestStub.restore();
        });

        test("isRunning should check correct status URL", function (done) {
            requestStub.returns(Promise.resolve("packager-status:running"));

            new Packager("/workspace", "/workspace", Packager.DEFAULT_PORT)
                .isRunning()
                .then(isRunning => {
                    assert(isRunning);
                    assert(requestStub.firstCall.args[0].match("http://localhost:" + Packager.DEFAULT_PORT));
                })
                .then(done, () => {
                    assert.fail(null, null, "packager was expected to be running");
                    done();
                });
        });

        test("isRunning should report false if server doesn't respond", function (done) {
            requestStub.returns(Promise.reject(void 0));

            new Packager("/workspace", "/workspace", 9091)
                .isRunning()
                .then(isRunning => assert(!isRunning))
                .then(done, () => {
                    assert.fail(null, null, "packager was not expected to be running");
                    done();
                });
        });

        test("isRunning should report false if request fails", function (done) {
            requestStub.returns(Promise.resolve("some_random_string"));

            new Packager("/workspace", "/workspace", 10001)
                .isRunning()
                .then(isRunning => assert(!isRunning))
                .then(done, () => {
                    assert.fail(null, null, "packager was not expected to be running");
                    done();
                });
        });
    });
});