Skip to content

Commit

Permalink
chore(deps): replace strip-ansi with stripVTControlCharacters fro…
Browse files Browse the repository at this point in the history
…m `node:util`
  • Loading branch information
AriPerkkio committed Oct 1, 2024
1 parent 214ec26 commit a78d9f5
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 122 deletions.
20 changes: 1 addition & 19 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Repository: https://github.com/debitoor/chai-subset.git

> The MIT License (MIT)
>
> Copyright (c) 2014
> Copyright (c) 2014
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -1207,7 +1207,6 @@ Repository: chalk/slice-ansi
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## string-width
Expand All @@ -1227,23 +1226,6 @@ Repository: sindresorhus/string-width
---------------------------------------

## strip-ansi
License: MIT
By: Sindre Sorhus
Repository: chalk/strip-ansi

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## strip-literal
License: MIT
By: Anthony Fu
Expand Down
1 change: 0 additions & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
"micromatch": "^4.0.7",
"pretty-format": "^29.7.0",
"prompts": "^2.4.2",
"strip-ansi": "^7.1.0",
"strip-literal": "^2.1.0",
"tinyglobby": "^0.2.6",
"ws": "^8.18.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable prefer-template */
import { existsSync, readFileSync } from 'node:fs'
import { Writable } from 'node:stream'
import { stripVTControlCharacters } from 'node:util'
import { normalize, relative } from 'pathe'
import c from 'tinyrainbow'
import cliTruncate from 'cli-truncate'
import type { ErrorWithDiff, ParsedStack } from '@vitest/utils'
import { inspect } from '@vitest/utils'
import stripAnsi from 'strip-ansi'
import {
lineSplitRE,
positionToOffset,
Expand Down Expand Up @@ -398,7 +398,7 @@ export function generateCodeFrame(
const lineLength = lines[j].length

// too long, maybe it's a minified file, skip for codeframe
if (stripAnsi(lines[j]).length > 200) {
if (stripVTControlCharacters(lines[j]).length > 200) {
return ''
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stripVTControlCharacters } from 'node:util'
import c from 'tinyrainbow'
import cliTruncate from 'cli-truncate'
import stripAnsi from 'strip-ansi'
import type { Task } from '@vitest/runner'
import { getTests, notNullish } from '../../../../utils'
import { F_RIGHT } from '../../../../utils/figures'
Expand Down Expand Up @@ -75,7 +75,7 @@ function renderBenchmarkItems(result: BenchmarkResult) {
function computeColumnWidths(results: BenchmarkResult[]): number[] {
const rows = [tableHead, ...results.map(v => renderBenchmarkItems(v))]
return Array.from(tableHead, (_, i) =>
Math.max(...rows.map(row => stripAnsi(row[i]).length)))
Math.max(...rows.map(row => stripVTControlCharacters(row[i]).length)))
}

function padRow(row: string[], widths: number[]) {
Expand Down Expand Up @@ -215,7 +215,7 @@ export function renderTree(
if (task.result?.state !== 'pass' && outputMap.get(task) != null) {
let data: string | undefined = outputMap.get(task)
if (typeof data === 'string') {
data = stripAnsi(data.trim().split('\n').filter(Boolean).pop()!)
data = stripVTControlCharacters(data.trim().split('\n').filter(Boolean).pop()!)
if (data === '') {
data = undefined
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/github-actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stripVTControlCharacters } from 'node:util'
import { getTasks } from '@vitest/runner/utils'
import stripAnsi from 'strip-ansi'
import type { File } from '@vitest/runner'
import { getFullName } from '../../utils'
import { capturePrintError } from '../error'
Expand Down Expand Up @@ -64,7 +64,7 @@ export class GithubActionsReporter implements Reporter {
line: String(stack.line),
column: String(stack.column),
},
message: stripAnsi(result.output),
message: stripVTControlCharacters(result.output),
})
this.ctx.logger.log(`\n${formatted}`)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/junit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { existsSync, promises as fs } from 'node:fs'
import { hostname } from 'node:os'
import { stripVTControlCharacters } from 'node:util'
import { dirname, relative, resolve } from 'pathe'

import type { Task } from '@vitest/runner'
import { getSuites } from '@vitest/runner/utils'
import stripAnsi from 'strip-ansi'
import type { Vitest } from '../core'
import type { Reporter } from '../types/reporter'
import { getOutputFile } from '../../utils/config-helpers'
Expand Down Expand Up @@ -233,7 +233,7 @@ export class JUnitReporter implements Reporter {
{ project: this.ctx.getProjectByTaskId(task.id), task },
)
await this.baseLog(
escapeXML(stripAnsi(result.output.trim())),
escapeXML(stripVTControlCharacters(result.output.trim())),
)
},
)
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/renderers/listRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stripVTControlCharacters } from 'node:util'
import c from 'tinyrainbow'
import cliTruncate from 'cli-truncate'
import stripAnsi from 'strip-ansi'
import type { SuiteHooks, Task } from '@vitest/runner'
import { getTests, notNullish } from '../../../utils'
import { F_RIGHT } from '../../../utils/figures'
Expand Down Expand Up @@ -183,7 +183,7 @@ function renderTree(
if (task.result?.state !== 'pass' && outputMap.get(task) != null) {
let data: string | undefined = outputMap.get(task)
if (typeof data === 'string') {
data = stripAnsi(data.trim().split('\n').filter(Boolean).pop()!)
data = stripVTControlCharacters(data.trim().split('\n').filter(Boolean).pop()!)
if (data === '') {
data = undefined
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/renderers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stripVTControlCharacters } from 'node:util'
import { basename, dirname, isAbsolute, relative } from 'pathe'
import c from 'tinyrainbow'
import stripAnsi from 'strip-ansi'
import type { SuiteHooks, Task } from '@vitest/runner'
import type { SnapshotSummary } from '@vitest/snapshot'
import { slash } from '../../../utils/base'
Expand Down Expand Up @@ -37,7 +37,7 @@ export function divider(text?: string, left?: number, right?: number) {
const cols = getCols()

if (text) {
const textLength = stripAnsi(text).length
const textLength = stripVTControlCharacters(text).length
if (left == null && right != null) {
left = cols - textLength - right
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/watch-filter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import readline from 'node:readline'
import type { Writable } from 'node:stream'
import { stripVTControlCharacters } from 'node:util'
import c from 'tinyrainbow'
import stripAnsi from 'strip-ansi'
import { createDefer } from '@vitest/utils'
import { stdout as getStdout } from '../utils'

Expand Down Expand Up @@ -198,7 +198,7 @@ export class WatchFilter {
const columns = 'columns' in this.stdout ? this.stdout.columns : 80

// We have to take care of screen width in case of long lines
rows += 1 + Math.floor(Math.max(stripAnsi(line).length - 1, 0) / columns)
rows += 1 + Math.floor(Math.max(stripVTControlCharacters(line).length - 1, 0) / columns)
}

this.write(`${ESC}1G`) // move to the beginning of the line
Expand Down
26 changes: 0 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"playwright": "^1.41.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"strip-ansi": "^7.1.0",
"url": "^0.11.3",
"vitest": "workspace:*",
"vitest-browser-react": "^0.0.1",
Expand Down
10 changes: 5 additions & 5 deletions test/browser/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stripVTControlCharacters } from 'node:util'
import { inspect } from 'vitest/utils'
import { afterEach, expect, it, test } from 'vitest'
import stripAnsi from 'strip-ansi'

import { prettyDOM } from '@vitest/browser/utils'

Expand All @@ -13,27 +13,27 @@ it('utils package correctly uses loupe', async () => {
})

test('prints default document', () => {
expect(stripAnsi(prettyDOM())).toMatchSnapshot()
expect(stripVTControlCharacters(prettyDOM())).toMatchSnapshot()

const div = document.createElement('div')
div.innerHTML = '<span>hello</span>'
document.body.append(div)

expect(stripAnsi(prettyDOM())).toMatchSnapshot()
expect(stripVTControlCharacters(prettyDOM())).toMatchSnapshot()
})

test('prints the element', () => {
const div = document.createElement('div')
div.innerHTML = '<span>hello</span>'
document.body.append(div)

expect(stripAnsi(prettyDOM())).toMatchSnapshot()
expect(stripVTControlCharacters(prettyDOM())).toMatchSnapshot()
})

test('prints the element with attributes', () => {
const div = document.createElement('div')
div.innerHTML = '<span class="some-name" data-test-id="33" id="5">hello</span>'
document.body.append(div)

expect(stripAnsi(prettyDOM())).toMatchSnapshot()
expect(stripVTControlCharacters(prettyDOM())).toMatchSnapshot()
})
1 change: 0 additions & 1 deletion test/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"debug": "^4.3.4",
"immutable": "5.0.0-beta.5",
"memfs": "^4.8.2",
"strip-ansi": "^7.1.0",
"sweetalert2": "^11.6.16",
"tinyrainbow": "^1.2.0",
"tinyspy": "^1.0.2",
Expand Down
Loading

0 comments on commit a78d9f5

Please sign in to comment.