[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(utils): fix color util maximum call stack error (#5733)

authored by

Hiroshi Ogawa and committed by
GitHub
(May 17, 2024, 2:11 PM +0200) a4ec5831 c469c74d

+19 -5
+8 -4
packages/utils/src/colors.ts
··· 74 74 || 'CI' in process.env) 75 75 76 76 const replaceClose = (string: string, close: string, replace: string, index: number): string => { 77 - const start = string.substring(0, index) + replace 78 - const end = string.substring(index + close.length) 79 - const nextIndex = end.indexOf(close) 80 - return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end 77 + let result = '' 78 + let cursor = 0 79 + do { 80 + result += string.substring(cursor, index) + replace 81 + cursor = index + close.length 82 + index = string.indexOf(close, cursor) 83 + } while (~index) 84 + return result + string.substring(cursor) 81 85 } 82 86 83 87 const formatter = (open: string, close: string, replace = open) => {
+11 -1
test/core/test/utils.spec.ts
··· 1 1 import { beforeAll, describe, expect, test } from 'vitest' 2 - import { assertTypes, deepClone, objDisplay, objectAttr, toArray } from '@vitest/utils' 2 + import { assertTypes, createColors, deepClone, objDisplay, objectAttr, toArray } from '@vitest/utils' 3 3 import { deepMerge, resetModules } from '../../../packages/vitest/src/utils' 4 4 import { deepMergeSnapshot } from '../../../packages/snapshot/src/port/utils' 5 5 import type { EncodedSourceMap } from '../../../packages/vite-node/src/types' ··· 283 283 // note: our code should not split surrogate pairs, but may split graphemes 284 284 expect(() => encodeURI(objDisplay(value))).not.toThrow() 285 285 expect(objDisplay(value)).toEqual(expected) 286 + }) 287 + }) 288 + 289 + describe(createColors, () => { 290 + test('no maximum call stack error', () => { 291 + process.env.FORCE_COLOR = '1' 292 + delete process.env.GITHUB_ACTIONS 293 + const c = createColors() 294 + expect(c.isColorSupported).toBe(true) 295 + expect(c.blue(c.blue('x').repeat(10000))).toBeTruthy() 286 296 }) 287 297 })