@wdio/reporter 9.0.0-alpha.78 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js DELETED
@@ -1,271 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RunnerStats = exports.TestStats = exports.HookStats = exports.SuiteStats = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_events_1 = require("node:events");
9
- const utils_js_1 = require("./utils.js");
10
- const suite_js_1 = __importDefault(require("./stats/suite.js"));
11
- exports.SuiteStats = suite_js_1.default;
12
- const hook_js_1 = __importDefault(require("./stats/hook.js"));
13
- exports.HookStats = hook_js_1.default;
14
- const test_js_1 = __importDefault(require("./stats/test.js"));
15
- exports.TestStats = test_js_1.default;
16
- const runner_js_1 = __importDefault(require("./stats/runner.js"));
17
- exports.RunnerStats = runner_js_1.default;
18
- class WDIOReporter extends node_events_1.EventEmitter {
19
- options;
20
- outputStream;
21
- failures = 0;
22
- suites = {};
23
- hooks = {};
24
- tests = {};
25
- currentSuites = [];
26
- counts = {
27
- suites: 0,
28
- tests: 0,
29
- hooks: 0,
30
- passes: 0,
31
- skipping: 0,
32
- failures: 0
33
- };
34
- retries = 0;
35
- runnerStat;
36
- isContentPresent = false;
37
- specs = [];
38
- currentSpec;
39
- constructor(options) {
40
- super();
41
- this.options = options;
42
- // ensure the report directory exists
43
- if (this.options.outputDir) {
44
- try {
45
- node_fs_1.default.mkdirSync(this.options.outputDir, { recursive: true });
46
- }
47
- catch (err) {
48
- throw new Error(`Couldn't create output directory at "${this.options.outputDir}": ${err.stack}`);
49
- }
50
- }
51
- this.outputStream = (this.options.stdout || !this.options.logFile) && this.options.writeStream
52
- ? this.options.writeStream
53
- : node_fs_1.default.createWriteStream(this.options.logFile);
54
- let currentTest;
55
- const rootSuite = new suite_js_1.default({
56
- title: '(root)',
57
- fullTitle: '(root)',
58
- file: ''
59
- });
60
- this.currentSuites.push(rootSuite);
61
- this.on('client:beforeCommand', this.onBeforeCommand.bind(this));
62
- this.on('client:afterCommand', this.onAfterCommand.bind(this));
63
- this.on('client:beforeAssertion', this.onBeforeAssertion.bind(this));
64
- this.on('client:afterAssertion', this.onAfterAssertion.bind(this));
65
- this.on('runner:start', /* istanbul ignore next */ (runner) => {
66
- rootSuite.cid = runner.cid;
67
- this.specs.push(...runner.specs);
68
- this.runnerStat = new runner_js_1.default(runner);
69
- this.onRunnerStart(this.runnerStat);
70
- });
71
- this.on('suite:start', /* istanbul ignore next */ (params) => {
72
- /**
73
- * the jasmine framework doesn't give us information about the file
74
- * therefore we need to propagate these information into params
75
- */
76
- if (!params.file) {
77
- params.file = !params.parent
78
- ? this.specs.shift() || 'unknown spec file'
79
- : this.currentSpec;
80
- this.currentSpec = params.file;
81
- }
82
- const suite = new suite_js_1.default(params);
83
- const currentSuite = this.currentSuites[this.currentSuites.length - 1];
84
- currentSuite.suites.push(suite);
85
- this.currentSuites.push(suite);
86
- this.suites[suite.uid] = suite;
87
- this.onSuiteStart(suite);
88
- });
89
- this.on('hook:start', /* istanbul ignore next */ (hook) => {
90
- const hookStats = new hook_js_1.default(hook);
91
- const currentSuite = this.currentSuites[this.currentSuites.length - 1];
92
- currentSuite.hooks.push(hookStats);
93
- currentSuite.hooksAndTests.push(hookStats);
94
- this.hooks[hook.uid] = hookStats;
95
- this.onHookStart(hookStats);
96
- });
97
- this.on('hook:end', /* istanbul ignore next */ (hook) => {
98
- const hookStats = this.hooks[hook.uid];
99
- hookStats.complete((0, utils_js_1.getErrorsFromEvent)(hook));
100
- this.counts.hooks++;
101
- this.onHookEnd(hookStats);
102
- });
103
- this.on('test:start', /* istanbul ignore next */ (test) => {
104
- test.retries = this.retries;
105
- currentTest = new test_js_1.default(test);
106
- const currentSuite = this.currentSuites[this.currentSuites.length - 1];
107
- currentSuite.tests.push(currentTest);
108
- currentSuite.hooksAndTests.push(currentTest);
109
- this.tests[test.uid] = currentTest;
110
- this.onTestStart(currentTest);
111
- });
112
- this.on('test:pass', /* istanbul ignore next */ (test) => {
113
- const testStat = this.tests[test.uid];
114
- testStat.pass();
115
- this.counts.passes++;
116
- this.counts.tests++;
117
- this.onTestPass(testStat);
118
- });
119
- this.on('test:skip', (test) => {
120
- const testStat = this.tests[test.uid];
121
- currentTest.skip(test.pendingReason);
122
- this.counts.skipping++;
123
- this.counts.tests++;
124
- this.onTestSkip(testStat);
125
- });
126
- this.on('test:fail', /* istanbul ignore next */ (test) => {
127
- const testStat = this.tests[test.uid];
128
- testStat.fail((0, utils_js_1.getErrorsFromEvent)(test));
129
- this.counts.failures++;
130
- this.counts.tests++;
131
- this.onTestFail(testStat);
132
- });
133
- this.on('test:retry', (test) => {
134
- const testStat = this.tests[test.uid];
135
- testStat.fail((0, utils_js_1.getErrorsFromEvent)(test));
136
- this.onTestRetry(testStat);
137
- this.retries++;
138
- });
139
- this.on('test:pending', (test) => {
140
- test.retries = this.retries;
141
- const currentSuite = this.currentSuites[this.currentSuites.length - 1];
142
- currentTest = new test_js_1.default(test);
143
- /**
144
- * In Mocha: tests that are skipped don't have a start event but a test end.
145
- * In Jasmine: tests have a start event, therefore we need to replace the
146
- * test instance with the pending test here
147
- */
148
- if (test.uid in this.tests && this.tests[test.uid].state !== 'pending') {
149
- currentTest.uid = test.uid in this.tests ? 'skipped-' + this.counts.skipping : currentTest.uid;
150
- }
151
- const suiteTests = currentSuite.tests;
152
- if (!suiteTests.length || currentTest.uid !== suiteTests[suiteTests.length - 1].uid) {
153
- currentSuite.tests.push(currentTest);
154
- currentSuite.hooksAndTests.push(currentTest);
155
- }
156
- else {
157
- suiteTests[suiteTests.length - 1] = currentTest;
158
- currentSuite.hooksAndTests[currentSuite.hooksAndTests.length - 1] = currentTest;
159
- }
160
- this.tests[currentTest.uid] = currentTest;
161
- currentTest.skip(test.pendingReason);
162
- this.counts.skipping++;
163
- this.counts.tests++;
164
- this.onTestSkip(currentTest);
165
- });
166
- this.on('test:end', /* istanbul ignore next */ (test) => {
167
- const testStat = this.tests[test.uid];
168
- this.retries = 0;
169
- this.onTestEnd(testStat);
170
- });
171
- this.on('suite:end', /* istanbul ignore next */ (suite) => {
172
- const suiteStat = this.suites[suite.uid];
173
- suiteStat.complete();
174
- this.currentSuites.pop();
175
- this.onSuiteEnd(suiteStat);
176
- });
177
- this.on('runner:end', /* istanbul ignore next */ (runner) => {
178
- rootSuite.complete();
179
- if (this.runnerStat) {
180
- this.runnerStat.failures = runner.failures;
181
- this.runnerStat.retries = runner.retries;
182
- this.runnerStat.complete();
183
- this.onRunnerEnd(this.runnerStat);
184
- }
185
- const logFile = this.options.logFile;
186
- if (!this.isContentPresent && logFile && node_fs_1.default.existsSync(logFile)) {
187
- node_fs_1.default.unlinkSync(logFile);
188
- }
189
- });
190
- /**
191
- * browser client event handlers
192
- */
193
- this.on('client:beforeCommand', /* istanbul ignore next */ (payload) => {
194
- if (!currentTest) {
195
- return;
196
- }
197
- currentTest.output.push(Object.assign(payload, { type: 'command' }));
198
- });
199
- this.on('client:afterCommand', /* istanbul ignore next */ (payload) => {
200
- if (!currentTest) {
201
- return;
202
- }
203
- currentTest.output.push(Object.assign(payload, { type: 'result' }));
204
- });
205
- }
206
- /**
207
- * allows reporter to stale process shutdown process until required sync work
208
- * is done (e.g. when having to send data to some server or any other async work)
209
- */
210
- get isSynchronised() {
211
- return true;
212
- }
213
- /**
214
- * function to write to reporters output stream
215
- */
216
- write(content) {
217
- if (content) {
218
- this.isContentPresent = true;
219
- }
220
- this.outputStream.write(content);
221
- }
222
- /* istanbul ignore next */
223
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
224
- onRunnerStart(runnerStats) { }
225
- /* istanbul ignore next */
226
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
227
- onBeforeCommand(commandArgs) { }
228
- /* istanbul ignore next */
229
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
230
- onAfterCommand(commandArgs) { }
231
- /* istanbul ignore next */
232
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
233
- onBeforeAssertion(assertionArgs) { }
234
- /* istanbul ignore next */
235
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
236
- onAfterAssertion(assertionArgs) { }
237
- /* istanbul ignore next */
238
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
239
- onSuiteStart(suiteStats) { }
240
- /* istanbul ignore next */
241
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
242
- onHookStart(hookStat) { }
243
- /* istanbul ignore next */
244
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
245
- onHookEnd(hookStats) { }
246
- /* istanbul ignore next */
247
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
248
- onTestStart(testStats) { }
249
- /* istanbul ignore next */
250
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
251
- onTestPass(testStats) { }
252
- /* istanbul ignore next */
253
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
254
- onTestFail(testStats) { }
255
- /* istanbul ignore next */
256
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
257
- onTestRetry(testStats) { }
258
- /* istanbul ignore next */
259
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
260
- onTestSkip(testStats) { }
261
- /* istanbul ignore next */
262
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
263
- onTestEnd(testStats) { }
264
- /* istanbul ignore next */
265
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
266
- onSuiteEnd(suiteStats) { }
267
- /* istanbul ignore next */
268
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
269
- onRunnerEnd(runnerStats) { }
270
- }
271
- exports.default = WDIOReporter;
package/cjs/package.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@wdio/reporter-cjs",
3
- "type": "commonjs",
4
- "private": true
5
- }
package/cjs/stats/hook.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const runnable_js_1 = __importDefault(require("./runnable.js"));
7
- class HookStats extends runnable_js_1.default {
8
- uid;
9
- cid;
10
- title;
11
- parent;
12
- // Mocha only
13
- body;
14
- errors;
15
- error;
16
- state;
17
- currentTest;
18
- constructor(runner) {
19
- super('hook');
20
- this.uid = runnable_js_1.default.getIdentifier(runner);
21
- this.cid = runner.cid;
22
- this.title = runner.title;
23
- this.parent = runner.parent;
24
- this.currentTest = runner.currentTest;
25
- this.body = runner.body;
26
- }
27
- complete(errors) {
28
- this.errors = errors;
29
- if (errors && errors.length) {
30
- this.error = errors[0];
31
- this.state = 'failed';
32
- }
33
- super.complete();
34
- }
35
- }
36
- exports.default = HookStats;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Main class for a runnable class (e.g. test, suite or a hook)
5
- * mainly used to capture its running duration
6
- */
7
- class RunnableStats {
8
- type;
9
- start = new Date();
10
- end;
11
- _duration = 0;
12
- constructor(type) {
13
- this.type = type;
14
- }
15
- complete() {
16
- this.end = new Date();
17
- this._duration = this.end.getTime() - this.start.getTime();
18
- }
19
- get duration() {
20
- if (this.end) {
21
- return this._duration;
22
- }
23
- return new Date().getTime() - this.start.getTime();
24
- }
25
- /**
26
- * ToDo: we should always rely on uid
27
- */
28
- static getIdentifier(runner) {
29
- return runner.uid || runner.title;
30
- }
31
- }
32
- exports.default = RunnableStats;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const runnable_js_1 = __importDefault(require("./runnable.js"));
7
- const utils_js_1 = require("../utils.js");
8
- /**
9
- * Class to capture statistics about a test run. A test run is a single instance that
10
- * runs one or more spec files
11
- */
12
- class RunnerStats extends runnable_js_1.default {
13
- cid;
14
- capabilities;
15
- sanitizedCapabilities;
16
- config;
17
- specs;
18
- sessionId;
19
- isMultiremote;
20
- instanceOptions;
21
- retry;
22
- failures;
23
- retries;
24
- constructor(runner) {
25
- super('runner');
26
- this.cid = runner.cid;
27
- this.capabilities = runner.capabilities;
28
- this.sanitizedCapabilities = (0, utils_js_1.sanitizeCaps)(runner.capabilities);
29
- this.config = runner.config;
30
- this.specs = runner.specs;
31
- this.sessionId = runner.sessionId;
32
- this.isMultiremote = runner.isMultiremote;
33
- this.instanceOptions = runner.instanceOptions;
34
- this.retry = runner.retry;
35
- }
36
- }
37
- exports.default = RunnerStats;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const runnable_js_1 = __importDefault(require("./runnable.js"));
7
- /**
8
- * Class describing statistics about a single suite.
9
- */
10
- class SuiteStats extends runnable_js_1.default {
11
- uid;
12
- cid;
13
- file;
14
- title;
15
- fullTitle;
16
- tags;
17
- tests = [];
18
- hooks = [];
19
- suites = [];
20
- parent;
21
- /**
22
- * an array of hooks and tests stored in order as they happen
23
- */
24
- hooksAndTests = [];
25
- description;
26
- rule;
27
- constructor(suite) {
28
- super(suite.type || 'suite');
29
- this.uid = runnable_js_1.default.getIdentifier(suite);
30
- this.cid = suite.cid;
31
- this.file = suite.file;
32
- this.title = suite.title;
33
- this.fullTitle = suite.fullTitle;
34
- this.tags = suite.tags;
35
- this.parent = suite.parent;
36
- /**
37
- * only Cucumber
38
- */
39
- this.description = suite.description;
40
- this.rule = suite.rule;
41
- }
42
- }
43
- exports.default = SuiteStats;
package/cjs/stats/test.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_util_1 = require("node:util");
7
- const diff_1 = require("diff");
8
- const object_inspect_1 = __importDefault(require("object-inspect"));
9
- const runnable_js_1 = __importDefault(require("./runnable.js"));
10
- const utils_js_1 = require("../utils.js");
11
- const maxStringLength = 2048;
12
- /**
13
- * TestStats class
14
- * captures data on a test.
15
- */
16
- class TestStats extends runnable_js_1.default {
17
- uid;
18
- cid;
19
- title;
20
- currentTest;
21
- fullTitle;
22
- output;
23
- argument;
24
- retries;
25
- parent;
26
- /**
27
- * initial test state is pending
28
- * the state can change to the following: passed, skipped, failed
29
- */
30
- state;
31
- pendingReason;
32
- errors;
33
- error;
34
- body;
35
- constructor(test) {
36
- super('test');
37
- this.uid = runnable_js_1.default.getIdentifier(test);
38
- this.cid = test.cid;
39
- this.title = test.title;
40
- this.fullTitle = test.fullTitle;
41
- this.output = [];
42
- this.argument = test.argument;
43
- this.retries = test.retries;
44
- this.parent = test.parent;
45
- // Mocha only
46
- this.body = test.body;
47
- /**
48
- * initial test state is pending
49
- * the state can change to the following: passed, skipped, failed
50
- */
51
- this.state = 'pending';
52
- }
53
- pass() {
54
- this.complete();
55
- this.state = 'passed';
56
- }
57
- skip(reason) {
58
- this.pendingReason = reason;
59
- this.state = 'skipped';
60
- }
61
- fail(errors) {
62
- this.complete();
63
- this.state = 'failed';
64
- /**
65
- * Iterates through all errors to check if they're a type of 'AssertionError',
66
- * and formats it if so. Otherwise, just leaves error as is
67
- */
68
- const formattedErrors = errors?.map((err) => (
69
- /**
70
- * only format if error object has either an "expected" or "actual" property set
71
- */
72
- ((err.expected || err.actual) && !node_util_1.types.isProxy(err.actual)) &&
73
- /**
74
- * and if they aren't already formated, e.g. in Jasmine
75
- */
76
- (err.message && !err.message.includes('Expected: ') && !err.message.includes('Received: '))
77
- ? this._stringifyDiffObjs(err)
78
- : err));
79
- this.errors = formattedErrors;
80
- if (formattedErrors && formattedErrors.length) {
81
- this.error = formattedErrors[0];
82
- }
83
- }
84
- _stringifyDiffObjs(err) {
85
- const inspectOpts = { maxStringLength };
86
- const expected = (0, object_inspect_1.default)(err.expected, inspectOpts);
87
- const actual = (0, object_inspect_1.default)(err.actual, inspectOpts);
88
- let msg = (0, diff_1.diffWordsWithSpace)(actual, expected)
89
- .map((str) => (str.added
90
- ? (0, utils_js_1.colorLines)('diff added inline', str.value)
91
- : str.removed
92
- ? (0, utils_js_1.colorLines)('diff removed inline', str.value)
93
- : str.value))
94
- .join('');
95
- // linenos
96
- const lines = msg.split('\n');
97
- if (lines.length > 4) {
98
- const width = String(lines.length).length;
99
- msg = lines
100
- .map(function (str, i) {
101
- return (0, utils_js_1.pad)(String(++i), width) + ' |' + ' ' + str;
102
- })
103
- .join('\n');
104
- }
105
- // legend
106
- msg = `\n${(0, utils_js_1.color)('diff removed inline', 'actual')} ${(0, utils_js_1.color)('diff added inline', 'expected')}\n\n${msg}\n`;
107
- // indent
108
- msg = msg.replace(/^/gm, ' ');
109
- const newError = new Error(err.message + msg);
110
- newError.stack = err.stack;
111
- return newError;
112
- }
113
- }
114
- exports.default = TestStats;
@@ -1,153 +0,0 @@
1
- "use strict";
2
- /**
3
- * original source: https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js
4
- *
5
- * This file was imported due to lacking support of CJS environments in the original package.
6
- */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.createSupportsColor = void 0;
12
- const node_process_1 = __importDefault(require("node:process"));
13
- const node_os_1 = __importDefault(require("node:os"));
14
- const node_tty_1 = __importDefault(require("node:tty"));
15
- // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
16
- /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
17
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process_1.default.argv) {
18
- const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
19
- const position = argv.indexOf(prefix + flag);
20
- const terminatorPosition = argv.indexOf('--');
21
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
22
- }
23
- const { env } = node_process_1.default;
24
- let flagForceColor;
25
- if (hasFlag('no-color')
26
- || hasFlag('no-colors')
27
- || hasFlag('color=false')
28
- || hasFlag('color=never')) {
29
- flagForceColor = 0;
30
- }
31
- else if (hasFlag('color')
32
- || hasFlag('colors')
33
- || hasFlag('color=true')
34
- || hasFlag('color=always')) {
35
- flagForceColor = 1;
36
- }
37
- function envForceColor() {
38
- if ('FORCE_COLOR' in env) {
39
- if (env.FORCE_COLOR === 'true') {
40
- return 1;
41
- }
42
- if (env.FORCE_COLOR === 'false') {
43
- return 0;
44
- }
45
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
46
- }
47
- }
48
- function translateLevel(level) {
49
- if (level === 0) {
50
- return false;
51
- }
52
- return {
53
- level,
54
- hasBasic: true,
55
- has256: level >= 2,
56
- has16m: level >= 3,
57
- };
58
- }
59
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
60
- const noFlagForceColor = envForceColor();
61
- if (noFlagForceColor !== undefined) {
62
- flagForceColor = noFlagForceColor;
63
- }
64
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
65
- if (forceColor === 0) {
66
- return 0;
67
- }
68
- if (sniffFlags) {
69
- if (hasFlag('color=16m')
70
- || hasFlag('color=full')
71
- || hasFlag('color=truecolor')) {
72
- return 3;
73
- }
74
- if (hasFlag('color=256')) {
75
- return 2;
76
- }
77
- }
78
- // Check for Azure DevOps pipelines.
79
- // Has to be above the `!streamIsTTY` check.
80
- if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
81
- return 1;
82
- }
83
- if (haveStream && !streamIsTTY && forceColor === undefined) {
84
- return 0;
85
- }
86
- const min = forceColor || 0;
87
- if (env.TERM === 'dumb') {
88
- return min;
89
- }
90
- if (node_process_1.default.platform === 'win32') {
91
- // Windows 10 build 10586 is the first Windows release that supports 256 colors.
92
- // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
93
- const osRelease = node_os_1.default.release().split('.');
94
- if (Number(osRelease[0]) >= 10
95
- && Number(osRelease[2]) >= 10_586) {
96
- return Number(osRelease[2]) >= 14_931 ? 3 : 2;
97
- }
98
- return 1;
99
- }
100
- if ('CI' in env) {
101
- if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
102
- return 3;
103
- }
104
- if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
105
- return 1;
106
- }
107
- return min;
108
- }
109
- if ('TEAMCITY_VERSION' in env) {
110
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
111
- }
112
- if (env.COLORTERM === 'truecolor') {
113
- return 3;
114
- }
115
- if (env.TERM === 'xterm-kitty') {
116
- return 3;
117
- }
118
- if ('TERM_PROGRAM' in env) {
119
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
120
- switch (env.TERM_PROGRAM) {
121
- case 'iTerm.app': {
122
- return version >= 3 ? 3 : 2;
123
- }
124
- case 'Apple_Terminal': {
125
- return 2;
126
- }
127
- // No default
128
- }
129
- }
130
- if (env.TERM && /-256(color)?$/i.test(env.TERM)) {
131
- return 2;
132
- }
133
- if (env.TERM && /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
134
- return 1;
135
- }
136
- if ('COLORTERM' in env) {
137
- return 1;
138
- }
139
- return min;
140
- }
141
- function createSupportsColor(stream, options = {}) {
142
- const level = _supportsColor(stream, {
143
- streamIsTTY: stream && stream.isTTY,
144
- ...options,
145
- });
146
- return translateLevel(level);
147
- }
148
- exports.createSupportsColor = createSupportsColor;
149
- const supportsColor = {
150
- stdout: createSupportsColor({ isTTY: node_tty_1.default.isatty(1) }),
151
- stderr: createSupportsColor({ isTTY: node_tty_1.default.isatty(2) }),
152
- };
153
- exports.default = supportsColor;