From aec0b5306efa1c7b798ecadf36989e54767f1138 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 14 Jan 2025 06:42:38 +0100 Subject: [PATCH] fix: cleanup `vitest/reporters` entrypoint (#7241) --- docs/advanced/reporters.md | 6 ++-- docs/guide/migration.md | 4 +++ packages/vitest/src/node/cli/cli-api.ts | 2 +- .../src/node/reporters/benchmark/index.ts | 5 +++ packages/vitest/src/node/reporters/index.ts | 32 ++++--------------- packages/vitest/src/node/specifications.ts | 2 +- packages/vitest/src/node/types/tests.ts | 2 +- packages/vitest/src/node/watcher.ts | 2 +- packages/vitest/src/public/node.ts | 11 +++++++ packages/vitest/src/public/reporters.ts | 27 +++++++++++++++- test/reporters/tests/task-parser.test.ts | 3 +- 11 files changed, 59 insertions(+), 37 deletions(-) diff --git a/docs/advanced/reporters.md b/docs/advanced/reporters.md index 494c1fba1a11..2a486d622894 100644 --- a/docs/advanced/reporters.md +++ b/docs/advanced/reporters.md @@ -36,7 +36,7 @@ export default class CustomReporter extends BaseReporter { Or implement the `Reporter` interface: ```ts [custom-reporter.js] -import { Reporter } from 'vitest/reporters' +import type { Reporter } from 'vitest/node' export default class CustomReporter implements Reporter { onCollected() { @@ -65,9 +65,7 @@ Instead of using the tasks that reporters receive, it is recommended to use the You can get access to this API by calling `vitest.state.getReportedEntity(runnerTask)`: ```ts twoslash -import type { Vitest } from 'vitest/node' -import type { RunnerTestFile } from 'vitest' -import type { Reporter, TestModule } from 'vitest/reporters' +import type { Reporter, RunnerTestFile, TestModule, Vitest } from 'vitest/node' class MyReporter implements Reporter { private vitest!: Vitest diff --git a/docs/guide/migration.md b/docs/guide/migration.md index d57569fd7c98..0e18d944d49c 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -81,6 +81,10 @@ The [`resolveConfig`](/advanced/api/#resolveconfig) is now more useful. Instead This function is not used internally and exposed exclusively as a public API. +### Cleaned up `vitest/reporters` types API {#cleaned-up-vitest-reporters-types} + +The `vitest/reporters` entrypoint now only exports reporters implementations and options types. If you need access to `TestCase`/`TestSuite` and other task related types, import them additionally from `vitest/node`. + ## Migrating to Vitest 2.0 {#vitest-2} ### Default Pool is `forks` diff --git a/packages/vitest/src/node/cli/cli-api.ts b/packages/vitest/src/node/cli/cli-api.ts index 5edaac0e073a..8f3fce88f947 100644 --- a/packages/vitest/src/node/cli/cli-api.ts +++ b/packages/vitest/src/node/cli/cli-api.ts @@ -1,7 +1,7 @@ import type { UserConfig as ViteUserConfig } from 'vite' import type { environments } from '../../integrations/env' import type { Vitest, VitestOptions } from '../core' -import type { TestModule, TestSuite } from '../reporters' +import type { TestModule, TestSuite } from '../reporters/reported-tasks' import type { TestSpecification } from '../spec' import type { UserConfig, VitestEnvironment, VitestRunMode } from '../types/config' import { mkdirSync, writeFileSync } from 'node:fs' diff --git a/packages/vitest/src/node/reporters/benchmark/index.ts b/packages/vitest/src/node/reporters/benchmark/index.ts index e82fb37cdb5d..df1222658e1e 100644 --- a/packages/vitest/src/node/reporters/benchmark/index.ts +++ b/packages/vitest/src/node/reporters/benchmark/index.ts @@ -1,6 +1,11 @@ import { BenchmarkReporter } from './reporter' import { VerboseBenchmarkReporter } from './verbose' +export { + BenchmarkReporter, + VerboseBenchmarkReporter, +} + export const BenchmarkReportsMap = { default: BenchmarkReporter, verbose: VerboseBenchmarkReporter, diff --git a/packages/vitest/src/node/reporters/index.ts b/packages/vitest/src/node/reporters/index.ts index dcb7e99a9297..3045ace00d94 100644 --- a/packages/vitest/src/node/reporters/index.ts +++ b/packages/vitest/src/node/reporters/index.ts @@ -3,7 +3,6 @@ import type { BaseOptions, BaseReporter } from './base' import type { BlobOptions } from './blob' import type { DefaultReporterOptions } from './default' import type { HTMLOptions } from './html' -import type { ModuleDiagnostic as _FileDiagnostic } from './reported-tasks' import { BasicReporter } from './basic' import { BlobReporter } from './blob' import { DefaultReporter } from './default' @@ -12,7 +11,6 @@ import { GithubActionsReporter } from './github-actions' import { HangingProcessReporter } from './hanging-process' import { type JsonOptions, JsonReporter } from './json' import { type JUnitOptions, JUnitReporter } from './junit' -import { TestModule as _TestFile } from './reported-tasks' import { TapReporter } from './tap' import { TapFlatReporter } from './tap-flat' import { VerboseReporter } from './verbose' @@ -31,23 +29,17 @@ export { } export type { BaseReporter, Reporter } -export type { TestProject } from '../project' -/** - * @deprecated Use `TestModule` instead - */ -export const TestFile = _TestFile -export * from './benchmark' +export { + BenchmarkBuiltinReporters, + BenchmarkReporter, + BenchmarkReportsMap, + VerboseBenchmarkReporter, +} from './benchmark' export type { JsonAssertionResult, JsonTestResult, JsonTestResults, } from './json' -/** - * @deprecated Use `ModuleDiagnostic` instead - */ -export type FileDiagnostic = _FileDiagnostic - -export { TestCase, TestModule, TestSuite } from './reported-tasks' export const ReportersMap = { 'default': DefaultReporter, @@ -78,15 +70,3 @@ export interface BuiltinReporterOptions { 'hanging-process': never 'html': HTMLOptions } - -export type { - TaskOptions, - - TestCollection, - TestDiagnostic, - - TestResult, - TestResultFailed, - TestResultPassed, - TestResultSkipped, -} from './reported-tasks' diff --git a/packages/vitest/src/node/specifications.ts b/packages/vitest/src/node/specifications.ts index e57d79ce9ba1..78422d4dfcb8 100644 --- a/packages/vitest/src/node/specifications.ts +++ b/packages/vitest/src/node/specifications.ts @@ -1,5 +1,5 @@ import type { Vitest } from './core' -import type { TestProject } from './reporters' +import type { TestProject } from './project' import type { TestSpecification } from './spec' import { existsSync } from 'node:fs' import mm from 'micromatch' diff --git a/packages/vitest/src/node/types/tests.ts b/packages/vitest/src/node/types/tests.ts index 9b05e1f97ee0..ba793c572a19 100644 --- a/packages/vitest/src/node/types/tests.ts +++ b/packages/vitest/src/node/types/tests.ts @@ -1,4 +1,4 @@ -import type { TestModule } from '../reporters' +import type { TestModule } from '../reporters/reported-tasks' export interface TestRunResult { testModules: TestModule[] diff --git a/packages/vitest/src/node/watcher.ts b/packages/vitest/src/node/watcher.ts index 0db9f78649e1..fbbfa0eefa19 100644 --- a/packages/vitest/src/node/watcher.ts +++ b/packages/vitest/src/node/watcher.ts @@ -1,5 +1,5 @@ import type { Vitest } from './core' -import type { TestProject } from './reporters' +import type { TestProject } from './project' import { readFileSync } from 'node:fs' import { noop, slash } from '@vitest/utils' import mm from 'micromatch' diff --git a/packages/vitest/src/public/node.ts b/packages/vitest/src/public/node.ts index bc7fbcb502a4..f79585611ea0 100644 --- a/packages/vitest/src/public/node.ts +++ b/packages/vitest/src/public/node.ts @@ -143,6 +143,17 @@ export type { export { createDebugger } from '../utils/debugger' +export type { + RunnerTask, + RunnerTaskResult, + RunnerTaskResultPack, + RunnerTestCase, + RunnerTestFile, + RunnerTestSuite, +} from './index' +export type { + Reporter, +} from './reporters' export { generateFileHash } from '@vitest/runner/utils' export { diff --git a/packages/vitest/src/public/reporters.ts b/packages/vitest/src/public/reporters.ts index eca01ade4d0b..befae0041d83 100644 --- a/packages/vitest/src/public/reporters.ts +++ b/packages/vitest/src/public/reporters.ts @@ -1 +1,26 @@ -export * from '../node/reporters' +export { + BasicReporter, + BenchmarkReporter, + BenchmarkReportsMap, + DefaultReporter, + DotReporter, + GithubActionsReporter, + HangingProcessReporter, + JsonReporter, + JUnitReporter, + ReportersMap, + TapFlatReporter, + TapReporter, + VerboseBenchmarkReporter, + VerboseReporter, +} from '../node/reporters' +export type { + BaseReporter, + BenchmarkBuiltinReporters, + BuiltinReporterOptions, + BuiltinReporters, + JsonAssertionResult, + JsonTestResult, + JsonTestResults, + Reporter, +} from '../node/reporters' diff --git a/test/reporters/tests/task-parser.test.ts b/test/reporters/tests/task-parser.test.ts index 22779ecb377b..598f602dcf50 100644 --- a/test/reporters/tests/task-parser.test.ts +++ b/test/reporters/tests/task-parser.test.ts @@ -1,6 +1,5 @@ import type { File, Test } from '@vitest/runner' -import type { TestSpecification } from 'vitest/node' -import type { Reporter } from 'vitest/reporters' +import type { Reporter, TestSpecification } from 'vitest/node' import type { HookOptions } from '../../../packages/vitest/src/node/reporters/task-parser' import { expect, test } from 'vitest' import { TaskParser } from '../../../packages/vitest/src/node/reporters/task-parser'