Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prepare the Vitest API to be stable #6962

Merged

Conversation

sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Nov 25, 2024

Description

Goals of this PR:

  • Reduce the size of core.ts
  • Deprecate APIs that we exposed, and mark internal APIs with @internal to remove them from types
  • Document all relevant Node.js APIs

The new API without deprecated methods:

declare class Vitest {
    readonly mode: VitestRunMode;
    readonly version: string;
    readonly logger: Logger;
    readonly packageInstaller: VitestPackageInstaller;
    readonly distPath: string;
    readonly watcher: VitestWatcher
    readonly state: StateManager; /** marked experimental */
    readonly snapshot: SnapshotManager;
    readonly cache: VitestCache;
    readonly config: ResolvedConfig;
    readonly vite: ViteDevServer;
    projects: TestProject[];
    
    provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
    getProvidedContext(): ProvidedContext
    getRootProject(): TestProject;
    getProjectByName(name: string): TestProject;
    
    mergeReports(): Promise<TestRunResult>;
    collect(filters?: string[]): Promise<TestRunResult>;
    start(filters?: string[]): Promise<TestRunResult>;
    init(): Promise<void>;

    listFiles(filters?: string[]): Promise<TestSpecification[]>;
    getModuleSpecifications(moduleId: string): TestSpecification[];
    globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
    
    runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
    // difference is that `rerun` triggers `onWatcher*` events
    rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
    collectTests(specifications: TestSpecification[]): Promise<TestRunResult>;
    
    cancelCurrentRun(reason: CancelReason): Promise<void>;
    invalidateFile(filepath: string): void;
    shouldKeepServer(): boolean;
    
    enableSnapshotUpdate(): void
    resetSnapshotUpdate(): void
    setGlobalTestNamePattern(pattern: string | RegExp): void
    resetGlobalTestNamePattern(): void
    
    import<T>(moduleId: string): Promise<T>
    
    onServerRestart(fn: OnServerRestartHandler): void;
    onCancel(fn: (reason: CancelReason) => Awaitable<void>): void;
    onClose(fn: () => Awaitable<void>): void;
    onTestsRerun(fn: OnTestsRerunHandler): void;
    onFilterWatchedSpecification(fn: (spec: TestSpecification) => boolean): void;
    
    close(): Promise<void>;
    exit(force?: boolean): Promise<void>;
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Nov 25, 2024

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 2ad4d6f
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/675814110cbabb0008af527b
😎 Deploy Preview https://deploy-preview-6962--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sheremet-va sheremet-va force-pushed the refactor/vitest-prepare-stable branch 2 times, most recently from d267bf6 to 2d421a5 Compare December 2, 2024 16:38
@sheremet-va sheremet-va modified the milestones: 2.2.0, 3.0.0 Dec 3, 2024
@sheremet-va sheremet-va force-pushed the refactor/vitest-prepare-stable branch 2 times, most recently from 483acc6 to 78d0af9 Compare December 6, 2024 08:58
@sheremet-va sheremet-va marked this pull request as ready for review December 6, 2024 17:15
docs/advanced/api/index.md Outdated Show resolved Hide resolved
packages/vitest/src/node/core.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/core.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/watcher.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/watcher.ts Outdated Show resolved Hide resolved
docs/advanced/api/index.md Show resolved Hide resolved
docs/advanced/api/vitest.md Outdated Show resolved Hide resolved
docs/advanced/api/vitest.md Outdated Show resolved Hide resolved
docs/advanced/api/vitest.md Outdated Show resolved Hide resolved
docs/advanced/api/test-project.md Outdated Show resolved Hide resolved
@sheremet-va sheremet-va force-pushed the refactor/vitest-prepare-stable branch from 9c5cc3d to c9e14c2 Compare December 10, 2024 09:48
AriPerkkio
AriPerkkio previously approved these changes Dec 10, 2024
@sheremet-va sheremet-va merged commit 9a1b501 into vitest-dev:main Dec 10, 2024
3 checks passed
@sheremet-va sheremet-va deleted the refactor/vitest-prepare-stable branch December 10, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants