diff --git a/packages/angular/cli/bin/ng b/packages/angular/cli/bin/ng index 6114439119ad..7fb032affdcb 100755 --- a/packages/angular/cli/bin/ng +++ b/packages/angular/cli/bin/ng @@ -3,8 +3,14 @@ // Provide a title to the process in `ps`. // Due to an obscure Mac bug, do not start this title with any symbol. -process.title = 'ng'; +try { + process.title = 'ng ' + Array.from(process.argv).slice(2).join(' '); +} catch(_) { + // If an error happened above, use the most basic title. + process.title = 'ng'; +} +// Some older versions of Node do not support let or const. var version = process.version.substr(1).split('.'); if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) { process.stderr.write( diff --git a/tests/legacy-cli/e2e/tests/misc/title.ts b/tests/legacy-cli/e2e/tests/misc/title.ts new file mode 100644 index 000000000000..1e5cc5f763a6 --- /dev/null +++ b/tests/legacy-cli/e2e/tests/misc/title.ts @@ -0,0 +1,16 @@ +import { execAndWaitForOutputToMatch, execWithEnv, killAllProcesses } from '../../utils/process'; + + +export default async function() { + try { + await execAndWaitForOutputToMatch('ng', ['build', '--watch'], /./); + + const output = await execWithEnv('ps', ['x'], { COLUMNS: '200' }); + + if (!output.stdout.match(/ng build --watch/)) { + throw new Error('Title of the process was not properly set.'); + } + } finally { + await killAllProcesses(); + } +} diff --git a/tests/legacy-cli/e2e/utils/process.ts b/tests/legacy-cli/e2e/utils/process.ts index ff2aa66d6e93..7da400f46797 100644 --- a/tests/legacy-cli/e2e/utils/process.ts +++ b/tests/legacy-cli/e2e/utils/process.ts @@ -1,3 +1,4 @@ +import { SpawnOptions } from "child_process"; import * as child_process from 'child_process'; import { terminal } from '@angular-devkit/core'; import { Observable, concat, defer, EMPTY, from} from 'rxjs'; @@ -11,6 +12,7 @@ const treeKill = require('tree-kill'); interface ExecOptions { silent?: boolean; waitForMatch?: RegExp; + env?: { [varname: string]: string }; } @@ -26,6 +28,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise `"${x}"`).join(' ')}\`${flags}...`)); console.log(terminal.blue(`CWD: ${cwd}`)); - const spawnOptions: any = {cwd}; + const spawnOptions: SpawnOptions = {cwd, env}; if (process.platform.startsWith('win')) { args.unshift('/c', cmd); @@ -146,6 +149,10 @@ export function silentExec(cmd: string, ...args: string[]) { return _exec({ silent: true }, cmd, args); } +export function execWithEnv(cmd: string, args: string[], env: { [varname: string]: string }) { + return _exec({ env }, cmd, args); +} + export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) { if (cmd === 'ng' && args[0] === 'serve') { // Accept matches up to 20 times after the initial match.