From afe44c652b5f93022d44a40a06ef302001d84263 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 1 May 2020 01:39:21 -0700 Subject: [PATCH] force color support in CI --- package-lock.json | 15 ++++++++++++++- package.json | 3 ++- test/colors.js | 18 +++++++++++++++++- test/reporters/detail.js | 17 ++++++++++++++++- test/reporters/install.js | 17 ++++++++++++++++- test/reporters/json.js | 17 ++++++++++++++++- test/reporters/quiet.js | 17 ++++++++++++++++- 7 files changed, 97 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 39eb09c..0f91dd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "npm-audit-report", - "version": "1.3.3", + "version": "2.0.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -382,6 +382,11 @@ } } }, + "caller": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/caller/-/caller-1.0.1.tgz", + "integrity": "sha1-uFGGD3Dhlds9J3OVqhp+I+ow7PU=" + }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -1706,6 +1711,14 @@ "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, + "require-inject": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/require-inject/-/require-inject-1.4.4.tgz", + "integrity": "sha512-5Y5ctRN84+I4iOZO61gm+48tgP/6Hcd3VZydkaEM3MCuOvnHRsTJYQBOc01faI/Z9at5nsCAJVHhlfPA6Pc0Og==", + "requires": { + "caller": "^1.0.1" + } + }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", diff --git a/package.json b/package.json index 74a30c0..f913e77 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "author": "Adam Baldwin", "license": "ISC", "dependencies": { - "chalk": "^4.0.0" + "chalk": "^4.0.0", + "require-inject": "^1.4.4" }, "devDependencies": { "tap": "^14.10.7" diff --git a/test/colors.js b/test/colors.js index 435df77..beade87 100644 --- a/test/colors.js +++ b/test/colors.js @@ -1,5 +1,21 @@ -const colors = require('../lib/colors.js') const t = require('tap') +const requireInject = require('require-inject') +// force color support when in CI, so tests do the right thing +const cs = { + hasBasic: true, + has256: true, + has16m: true, + level: 3, +} +const colors = requireInject('../lib/colors.js', { + 'chalk': requireInject('chalk', { + 'supports-color': Object.assign(() => cs, { + stdout: cs, + stderr: cs, + }) + }) +}) +t.formatSnapshot = ({report, exitCode}) => `${report}\nexitCode=${exitCode}` t.test('with colors', async t => { const c = colors(true) diff --git a/test/reporters/detail.js b/test/reporters/detail.js index 1a8efb5..67d7a22 100644 --- a/test/reporters/detail.js +++ b/test/reporters/detail.js @@ -1,6 +1,21 @@ const t = require('tap') const fixture = require('../fixtures/index.js') -const Report = require('../..') +const requireInject = require('require-inject') +// force color support when in CI, so tests do the right thing +const cs = { + hasBasic: true, + has256: true, + has16m: true, + level: 3, +} +const Report = requireInject('../..', { + 'chalk': requireInject('chalk', { + 'supports-color': Object.assign(() => cs, { + stdout: cs, + stderr: cs, + }) + }) +}) t.formatSnapshot = ({report, exitCode}) => `${report}\nexitCode=${exitCode}` for (const f of fixture.files) { diff --git a/test/reporters/install.js b/test/reporters/install.js index ea2b0b5..c0e46de 100644 --- a/test/reporters/install.js +++ b/test/reporters/install.js @@ -1,6 +1,21 @@ const t = require('tap') const fixture = require('../fixtures/index.js') -const Report = require('../..') +const requireInject = require('require-inject') +// force color support when in CI, so tests do the right thing +const cs = { + hasBasic: true, + has256: true, + has16m: true, + level: 3, +} +const Report = requireInject('../..', { + 'chalk': requireInject('chalk', { + 'supports-color': Object.assign(() => cs, { + stdout: cs, + stderr: cs, + }) + }) +}) t.formatSnapshot = ({report, exitCode}) => `${report}\nexitCode=${exitCode}` for (const f of fixture.files) { diff --git a/test/reporters/json.js b/test/reporters/json.js index 70965ad..23e27f5 100644 --- a/test/reporters/json.js +++ b/test/reporters/json.js @@ -1,6 +1,21 @@ const t = require('tap') const fixture = require('../fixtures/index.js') -const Report = require('../..') +const requireInject = require('require-inject') +// force color support when in CI, so tests do the right thing +const cs = { + hasBasic: true, + has256: true, + has16m: true, + level: 3, +} +const Report = requireInject('../..', { + 'chalk': requireInject('chalk', { + 'supports-color': Object.assign(() => cs, { + stdout: cs, + stderr: cs, + }) + }) +}) t.formatSnapshot = ({report, exitCode}) => `${report}\nexitCode=${exitCode}` for (const f of fixture.files) { diff --git a/test/reporters/quiet.js b/test/reporters/quiet.js index b5b7386..3176423 100644 --- a/test/reporters/quiet.js +++ b/test/reporters/quiet.js @@ -1,6 +1,21 @@ const t = require('tap') const fixture = require('../fixtures/index.js') -const Report = require('../..') +const requireInject = require('require-inject') +// force color support when in CI, so tests do the right thing +const cs = { + hasBasic: true, + has256: true, + has16m: true, + level: 3, +} +const Report = requireInject('../..', { + 'chalk': requireInject('chalk', { + 'supports-color': Object.assign(() => cs, { + stdout: cs, + stderr: cs, + }) + }) +}) t.formatSnapshot = ({report, exitCode}) => `${report}\nexitCode=${exitCode}` for (const f of fixture.files) {