Skip to content

fix: errors from tns doctor are not visible in CI environment #4404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,27 @@ export function versionCompare(version1: string | IVersionData, version2: string
}

export function isInteractive(): boolean {
return process.stdout.isTTY && process.stdin.isTTY;
const isInteractive = isRunningInTTY() && !isCIEnvironment();
return isInteractive;
}

/**
* Checks if current process is running in Text Terminal (TTY)
*/
function isRunningInTTY(): boolean {
return process.stdout &&
process.stdout.isTTY &&
process.stdin &&
process.stdin.isTTY;
}

function isCIEnvironment(): boolean {
// The following CI environments set their own environment variables that we respect:
// travis: "CI",
// circleCI: "CI",
// jenkins: "JENKINS_HOME"

return !!(process.env && (process.env.CI || process.env.JENKINS_HOME));
}

export function toBoolean(str: any): boolean {
Expand Down
51 changes: 51 additions & 0 deletions lib/common/test/unit-tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,55 @@ const test = require("./test");`,
});
});
});

describe("isInteractive", () => {
const originalEnv = process.env;
const originalStdoutIsTTY = process.stdout.isTTY;
const originalStdinIsTTY = process.stdin.isTTY;
beforeEach(() => {
process.env.CI = "";
process.env.JENKINS_HOME = "";
});

afterEach(() => {
process.env = originalEnv;
process.stdout.isTTY = originalStdoutIsTTY;
process.stdin.isTTY = originalStdinIsTTY;
});

it("returns false when stdout is not TTY", () => {
(<any>process.stdout).isTTY = false;
(<any>process.stdin).isTTY = true;
assert.isFalse(helpers.isInteractive());
});

it("returns false when stdin is not TTY", () => {
(<any>process.stdin).isTTY = false;
(<any>process.stdout).isTTY = true;
assert.isFalse(helpers.isInteractive());
});

it("returns false when stdout and stdin are TTY, but CI env var is set", () => {
(<any>process.stdout).isTTY = true;
(<any>process.stdin).isTTY = true;
process.env.CI = "true";

assert.isFalse(helpers.isInteractive());
});

it("returns false when stdout and stdin are TTY, but JENKINS_HOME env var is set", () => {
(<any>process.stdout).isTTY = true;
(<any>process.stdin).isTTY = true;
process.env.JENKINS_HOME = "/usr/local/lib/jenkins";

assert.isFalse(helpers.isInteractive());
});

it("returns true when stdout and stdin are TTY and neither CI or JENKINS_HOME are set", () => {
(<any>process.stdout).isTTY = true;
(<any>process.stdin).isTTY = true;

assert.isTrue(helpers.isInteractive());
});
});
});
11 changes: 0 additions & 11 deletions test/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ describe("doctorService", () => {
filesContents: {
file1: `const application = require("application");
const Observable = require("data/observable").Observable;
`
},
expectedShortImports: [
{ file: "file1", line: 'const application = require("application");' },
{ file: "file1", line: 'const Observable = require("data/observable").Observable;' },
]
},
{
filesContents: {
file1: `const application = require("application");
const Observable = require("data/observable").Observable;
`
},
expectedShortImports: [
Expand Down
13 changes: 11 additions & 2 deletions test/services/platform-environment-requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { PlatformEnvironmentRequirements } from '../../lib/services/platform-env
import * as stubs from "../stubs";
import { assert } from "chai";
import { EOL } from "os";
const helpers = require("../../lib/common/helpers");

const originalIsInteractive = helpers.isInteractive;
const platform = "android";
const cloudBuildsErrorMessage = `In order to test your application use the $ tns login command to log in with your account and then $ tns cloud build command to build your app in the cloud.`;
const manuallySetupErrorMessage = `To be able to build for ${platform}, verify that your environment is configured according to the system requirements described at `;
Expand Down Expand Up @@ -34,6 +36,14 @@ function createTestInjector() {
}

describe("platformEnvironmentRequirements ", () => {
beforeEach(() => {
helpers.isInteractive = () => true;
});

afterEach(() => {
helpers.isInteractive = originalIsInteractive;
});

describe("checkRequirements", () => {
let testInjector: IInjector = null;
let platformEnvironmentRequirements: IPlatformEnvironmentRequirements = null;
Expand Down Expand Up @@ -221,8 +231,7 @@ describe("platformEnvironmentRequirements ", () => {

describe("when console is non interactive", () => {
beforeEach(() => {
(<any>process).stdout.isTTY = false;
(<any>process.stdin).isTTY = false;
helpers.isInteractive = () => false;
mockDoctorService({ canExecuteLocalBuild: false });
});

Expand Down