From 5df522f7603bf8eadc9c60cd0d976c43140f9a70 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sat, 21 Jan 2023 21:18:22 +0800 Subject: [PATCH] feat: add basic reporter which allow user to use reporter in ci (#2612) * add basic reporter * extend basic reporter * Update index.md * Update index.md * extend from base reporter * fix lint * override onReRun * only ovverride onWatcherRerun * chore: cleanup * add override back * revert Co-authored-by: Vladimir --- docs/config/index.md | 1 + packages/vitest/src/node/reporters/basic.ts | 12 ++++++++++++ packages/vitest/src/node/reporters/index.ts | 2 ++ packages/vitest/src/utils/env.ts | 4 ++-- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 packages/vitest/src/node/reporters/basic.ts diff --git a/docs/config/index.md b/docs/config/index.md index 095c436c2d78..68a56780756d 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -359,6 +359,7 @@ Project root Custom reporters for output. Reporters can be [a Reporter instance](https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/types/reporter.ts) or a string to select built in reporters: - `'default'` - collapse suites when they pass + - `'basic'` - give a reporter like default reporter give in ci - `'verbose'` - keep the full task tree visible - `'dot'` - show each task as a single dot - `'junit'` - JUnit XML reporter (you can configure `testsuites` tag name with `VITEST_JUNIT_SUITE_NAME` environmental variable) diff --git a/packages/vitest/src/node/reporters/basic.ts b/packages/vitest/src/node/reporters/basic.ts new file mode 100644 index 000000000000..ea24eb20209d --- /dev/null +++ b/packages/vitest/src/node/reporters/basic.ts @@ -0,0 +1,12 @@ +import { BaseReporter } from './base' +import type { File } from '#types' + +export class BasicReporter extends BaseReporter { + isTTY = false + + reportSummary(files: File[]) { + // non-tty mode doesn't add a new line + this.ctx.logger.log() + return super.reportSummary(files) + } +} diff --git a/packages/vitest/src/node/reporters/index.ts b/packages/vitest/src/node/reporters/index.ts index 91e4020aba84..60e8f2babc9a 100644 --- a/packages/vitest/src/node/reporters/index.ts +++ b/packages/vitest/src/node/reporters/index.ts @@ -1,3 +1,4 @@ +import { BasicReporter } from './basic' import { DefaultReporter } from './default' import { DotReporter } from './dot' import { JsonReporter } from './json' @@ -11,6 +12,7 @@ export { DefaultReporter } export const ReportersMap = { 'default': DefaultReporter, + 'basic': BasicReporter, 'verbose': VerboseReporter, 'dot': DotReporter, 'json': JsonReporter, diff --git a/packages/vitest/src/utils/env.ts b/packages/vitest/src/utils/env.ts index 87c1c22667d2..648a7337ceea 100644 --- a/packages/vitest/src/utils/env.ts +++ b/packages/vitest/src/utils/env.ts @@ -1,2 +1,2 @@ -export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window -export const isBrowser = typeof window !== 'undefined' +export const isNode: boolean = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window +export const isBrowser: boolean = typeof window !== 'undefined'