microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
70f7cae4a697f9868d22dfdd08089a2cd2076772

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/common/commandExecutor.test.ts

103lines · modeblame

bdad2966Joshua 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
4import {CommandExecutor} from "../../common/commandExecutor";
5import {Log} from "../../common/log/log";
6
7import * as assert from "assert";
8import * as semver from "semver";
9import * as sinon from "sinon";
af70238cJoshua Skelton10 years ago10import * as Q from "q";
bdad2966Joshua Skelton10 years ago11
12suite("commandExecutor", function() {
13suite("commonContext", function() {
14teardown(function() {
15let mockedMethods = [Log.logMessage, Log.logCommandStatus];
16
17mockedMethods.forEach((method) => {
18if (method.hasOwnProperty("restore")) {
19(<any>method).restore();
20}
21});
22});
23
24test("should execute a command", function() {
25let ce = new CommandExecutor();
0c4ba74cJoshua Skelton10 years ago26let loggedOutput: string = "";
bdad2966Joshua Skelton10 years ago27
886053d9Joshua Skelton10 years ago28sinon.stub(Log, "logMessage", function(message: string, formatMessage: boolean = true) {
0c4ba74cJoshua Skelton10 years ago29loggedOutput += message;
bdad2966Joshua Skelton10 years ago30console.log(message);
31});
32
33return ce.execute("node -v")
34.then(() => {
0c4ba74cJoshua Skelton10 years ago35let nodeVersion = semver.clean(loggedOutput);
886053d9Joshua Skelton10 years ago36assert(nodeVersion);
bdad2966Joshua Skelton10 years ago37});
38});
39
40test("should reject on bad command", function() {
41let ce = new CommandExecutor();
42
43return ce.execute("bar")
44.then(() => {
45assert.fail("bar should not be a valid command");
46})
47.catch((reason) => {
48console.log(reason.message);
49assert.equal(reason.errorCode, 101);
50assert.equal(reason.errorLevel, 0);
51});
52});
53
54test("should reject on good command that fails", function() {
55let ce = new CommandExecutor();
56
57return ce.execute("node install bad-package")
58.then(() => {
59assert.fail("node should not be able to install bad-package");
60})
61.catch((reason) => {
62console.log(reason.message);
63assert.equal(reason.errorCode, 101);
64assert.equal(reason.errorLevel, 0);
65});
66});
af70238cJoshua Skelton10 years ago67
68test("should spawn a command", function(done: MochaDone) {
69let ce = new CommandExecutor();
0c4ba74cJoshua Skelton10 years ago70let loggedOutput: string = "";
af70238cJoshua Skelton10 years ago71
72sinon.stub(Log, "logMessage", function(message: string, formatMessage: boolean = true) {
0c4ba74cJoshua Skelton10 years ago73loggedOutput += message;
af70238cJoshua Skelton10 years ago74console.log(message);
75});
76
58b0a463Joshua Skelton10 years ago77Q({})
78.then(function () {
b956e11eMeena Kunnathur Balakrishnan10 years ago79return ce.spawn("node", ["-v"]);
58b0a463Joshua Skelton10 years ago80}).done(() => done(), done);
81});
82
b956e11eMeena Kunnathur Balakrishnan10 years ago83test("spawn should reject a bad command", function(done: MochaDone) {
58b0a463Joshua Skelton10 years ago84let ce = new CommandExecutor();
85let loggedOutput: string = "";
86
87sinon.stub(Log, "logMessage", function(message: string, formatMessage: boolean = true) {
88loggedOutput += message;
89console.log(message);
90});
91
92Q({})
93.then(function() {
b956e11eMeena Kunnathur Balakrishnan10 years ago94return ce.spawn("bar", ["-v"]);
58b0a463Joshua Skelton10 years ago95})
96.catch((reason) => {
97console.log(reason.message);
98assert.equal(reason.errorCode, 101);
99assert.equal(reason.errorLevel, 0);
100}).done(() => done(), done);
101});
bdad2966Joshua Skelton10 years ago102});
103});