diff --git a/src/pure/runner.ts b/src/pure/runner.ts index 25d471ca..c2e1c87e 100644 --- a/src/pure/runner.ts +++ b/src/pure/runner.ts @@ -3,10 +3,9 @@ import { readFile } from "fs-extra"; import { tmpdir } from "os"; import { existsSync } from "fs"; import * as path from "path"; -import { Readable } from "stream"; import { chunksToLinesAsync } from "@rauschma/stringio"; -import { sanitizeFilePath } from "./utils"; +import { filterColorFormatOutput, sanitizeFilePath } from "./utils"; import { isWindows } from "./platform"; export function getDebuggerConfig() {} @@ -112,8 +111,8 @@ export class TestRunner { chunksToLinesAsync(child.stderr), ) ) { - log(line.trimEnd() + "\r\n"); - outputs.push(line); + log((line.trimEnd()) + "\r\n"); + outputs.push(filterColorFormatOutput(line)); } } catch (e) { error = e; diff --git a/src/pure/utils.ts b/src/pure/utils.ts index cef644a2..6e4ebd56 100644 --- a/src/pure/utils.ts +++ b/src/pure/utils.ts @@ -17,7 +17,9 @@ export function getVitestPath(projectRoot: string): string | undefined { const suffixes = [".js", "", ".cmd"]; for (const suffix of suffixes) { if (existsSync(path.resolve(node_modules, ".bin", "vitest" + suffix))) { - return sanitizeFilePath(path.resolve(node_modules, ".bin", "vitest" + suffix)); + return sanitizeFilePath( + path.resolve(node_modules, ".bin", "vitest" + suffix), + ); } } @@ -48,13 +50,18 @@ export async function getVitestVersion(vitestPath?: string): Promise { throw new Error(`Cannot get vitest version from "${vitestPath}"`); } -const capitalizeFirstLetter = (string:string)=> string.charAt(0).toUpperCase() + string.slice(1); +const capitalizeFirstLetter = (string: string) => + string.charAt(0).toUpperCase() + string.slice(1); -const replaceDoubleSlashes = (string:string)=> string.replace(/\\/g, "/"); +const replaceDoubleSlashes = (string: string) => string.replace(/\\/g, "/"); export function sanitizeFilePath(path: string) { - if(isWindows) { - return capitalizeFirstLetter(replaceDoubleSlashes(path)); + if (isWindows) { + return capitalizeFirstLetter(replaceDoubleSlashes(path)); } return path; } + +export function filterColorFormatOutput(s: string): string { + return s.replace(/\u001b\[\d+m/g, ""); +}