This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect --color settings in outdated.
Fixes #4493
- Loading branch information
Showing
2 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var common = require("../common-tap.js") | ||
var test = require("tap").test | ||
var npm = require("../../") | ||
var mkdirp = require("mkdirp") | ||
var rimraf = require("rimraf") | ||
var mr = require("npm-registry-mock") | ||
var exec = require('child_process').exec | ||
|
||
var pkg = __dirname + '/outdated' | ||
var NPM_BIN = __dirname + '/../../bin/npm-cli.js' | ||
mkdirp.sync(pkg + "/cache") | ||
|
||
function hasControlCodes(str) { | ||
return str.length !== ansiTrim(str).length | ||
} | ||
|
||
function ansiTrim (str) { | ||
var r = new RegExp("\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|" + | ||
"\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)", "g"); | ||
return str.replace(r, "") | ||
} | ||
|
||
// note hard to automate tests for color = true | ||
// as npm kills the color config when it detects | ||
// it's not running in a tty | ||
test("does not use ansi styling", function (t) { | ||
t.plan(3) | ||
exec('node ' + NPM_BIN + ' outdated --color false', { | ||
cwd: pkg | ||
}, function(err, stdout) { | ||
t.ifError(err) | ||
t.ok(stdout, stdout.length) | ||
t.ok(!hasControlCodes(stdout)) | ||
}) | ||
}) | ||
|
||
test("cleanup", function (t) { | ||
rimraf.sync(pkg + "/cache") | ||
t.end() | ||
}) | ||
|