Skip to content

Commit 14afd0b

Browse files
authored
Replace strip-ansi with node:util.stripVTControlCharacters
1 parent 665b922 commit 14afd0b

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

lib/concordance-options.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {inspect} from 'node:util';
1+
import {inspect, stripVTControlCharacters} from 'node:util';
22

33
import ansiStyles from 'ansi-styles';
44
import {Chalk} from 'chalk'; // eslint-disable-line unicorn/import-style
5-
import stripAnsi from 'strip-ansi';
65

76
import {chalk} from './chalk.js';
87

@@ -85,7 +84,7 @@ const colorTheme = {
8584
undefined: ansiStyles.yellow,
8685
};
8786

88-
const plainTheme = JSON.parse(JSON.stringify(colorTheme), (_name, value) => typeof value === 'string' ? stripAnsi(value) : value);
87+
const plainTheme = JSON.parse(JSON.stringify(colorTheme), (_name, value) => typeof value === 'string' ? stripVTControlCharacters(value) : value);
8988

9089
const theme = chalk.level > 0 ? colorTheme : plainTheme;
9190

lib/reporters/tap.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os from 'node:os';
22
import path from 'node:path';
3+
import {stripVTControlCharacters} from 'node:util';
34

45
import indentString from 'indent-string';
56
import plur from 'plur';
6-
import stripAnsi from 'strip-ansi';
77
import * as supertap from 'supertap';
88

99
import prefixTitle from './prefix-title.js';
@@ -20,7 +20,7 @@ function dumpError({
2020
if (type === 'unknown') {
2121
return {
2222
message: 'Non-native error',
23-
formatted: stripAnsi(formattedError),
23+
formatted: stripVTControlCharacters(formattedError),
2424
};
2525
}
2626

@@ -33,8 +33,8 @@ function dumpError({
3333

3434
if (formattedDetails.length > 0) {
3535
originalError.details = Object.fromEntries(formattedDetails.map(({label, formatted}) => [
36-
stripAnsi(label),
37-
stripAnsi(formatted),
36+
stripVTControlCharacters(label),
37+
stripVTControlCharacters(formatted),
3838
]));
3939
}
4040
}
@@ -119,7 +119,7 @@ export default class TapReporter {
119119
}
120120

121121
writeComment(evt, {title = this.prefixTitle(evt.testFile, evt.title)}) {
122-
this.reportStream.write(`# ${stripAnsi(title)}${os.EOL}`);
122+
this.reportStream.write(`# ${stripVTControlCharacters(title)}${os.EOL}`);
123123
if (evt.logs) {
124124
for (const log of evt.logs) {
125125
const logLines = indentString(log, 4).replaceAll(/^ {4}/gm, '# ');

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
"pretty-ms": "^9.2.0",
122122
"resolve-cwd": "^3.0.0",
123123
"stack-utils": "^2.0.6",
124-
"strip-ansi": "^7.1.0",
125124
"supertap": "^3.0.1",
126125
"temp-dir": "^3.0.0",
127126
"write-file-atomic": "^6.0.0",

test-tap/assert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path';
22
import {fileURLToPath} from 'node:url';
3+
import {stripVTControlCharacters} from 'node:util';
34

4-
import stripAnsi from 'strip-ansi';
55
import {test} from 'tap';
66

77
import * as assert from '../lib/assert.js';
@@ -70,8 +70,8 @@ function assertFailure(t, subset) {
7070
if (subset.formattedDetails) {
7171
t.equal(lastFailure.formattedDetails.length, subset.formattedDetails.length);
7272
for (const [i, s] of lastFailure.formattedDetails.entries()) {
73-
t.equal(stripAnsi(s.label), subset.formattedDetails[i].label);
74-
t.match(stripAnsi(s.formatted), subset.formattedDetails[i].formatted);
73+
t.equal(stripVTControlCharacters(s.label), subset.formattedDetails[i].label);
74+
t.match(stripVTControlCharacters(s.formatted), subset.formattedDetails[i].formatted);
7575
}
7676
} else {
7777
t.same(lastFailure.formattedDetails, []);

test-tap/integration/assorted.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import childProcess from 'node:child_process';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import {fileURLToPath} from 'node:url';
5+
import {stripVTControlCharacters} from 'node:util';
56

67
import ciInfo from 'ci-info';
7-
import stripAnsi from 'strip-ansi';
88
import {test} from 'tap';
99

1010
import {execCli} from '../helper/cli.js';
@@ -82,15 +82,15 @@ test('tests without assertions do not fail if failWithoutAssertions option is se
8282
test('--no-color disables formatting colors', t => {
8383
execCli(['--no-color', 'formatting-color.cjs'], (error, stdout) => {
8484
t.ok(error);
85-
t.equal(stripAnsi(stdout), stdout);
85+
t.equal(stripVTControlCharacters(stdout), stdout);
8686
t.end();
8787
});
8888
});
8989

9090
test('--color enables formatting colors', t => {
9191
execCli(['--color', 'formatting-color.cjs'], (error, stdout) => {
9292
t.ok(error);
93-
t.not(stripAnsi(stdout), stdout);
93+
t.not(stripVTControlCharacters(stdout), stdout);
9494
t.end();
9595
});
9696
});

0 commit comments

Comments
 (0)