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

refactor: merge TestProject with WorkspaceProject #6906

Merged
merged 17 commits into from
Nov 18, 2024

Conversation

sheremet-va
Copy link
Member

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

Description

In preparation for the public API. Previously TestProject was a prototype for the public API, but it was hard to work with internally because it was too restrictive. In this PR I decided to merge them together and introduce a sort of convention:

  • All public methods starting with _ and marked with @internal are internal and not part of the public API. They are striped from the public interface during bundling
  • All those methods were renamed, and the previous names stayed with a @deprecated tag - they will be removed in V3 (we can remove them right away, they shouldn't have been used at all)
  • The WorkspaceProject was renamed to TestProject - all properties from the test project are now present there. The file was also renamed from workspace to project
  • Added a getter to throw an error if .vite or .config was accessed before the project was initialised. This should catch unexpected errors with a nice stack trace

The public test project API now looks like this (excluding deprecated and private APIs):

export interface TestProject {
  readonly name: string
  readonly serializedConfig: SerializedConfig
  readonly globalConfig: ResolvedConfig
  readonly vitest: Vitest
  readonly config: ResolvedConfig // project config
  readonly vite: ViteDevServer
  browser?: BrowserServer
  
  provide(key: string | symbol, value: unknown): void
  getProvidedContext(): ProvidedContext
  createSpecification(moduleId: string, pool?: string): TestSpecification
  isRootProject(): boolean
  globTestFiles(filters?: string[]): Promise<{ testFiles, typecheckTestFiles }>
  matchesTestGlob(filepath: string, code?: string): boolean
  close(): Promise<void>
}

image

TODO:

  • Better docs

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 14, 2024

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit ce19da0
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/673b07da0e59d20008a89d4d
😎 Deploy Preview https://deploy-preview-6906--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 changed the title refactor: merge TestProject with WorkspaceProject refactor: merge TestProject with WorkspaceProject Nov 14, 2024
docs/advanced/api.md Outdated Show resolved Hide resolved
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall direction is great! Thanks for working on this 🙌

docs/advanced/api.md Outdated Show resolved Hide resolved
packages/vitest/src/node/core.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/logger.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/project.ts Show resolved Hide resolved
packages/vitest/src/node/project.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/project.ts Outdated Show resolved Hide resolved
sheremet-va and others added 2 commits November 18, 2024 10:24
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of the much of API, but I like the idea of merging and simplifying WorkspaceProject and TestProject 👍

@sheremet-va sheremet-va merged commit 171041a into vitest-dev:main Nov 18, 2024
17 checks passed
@sheremet-va sheremet-va deleted the refactor/project branch November 18, 2024 09:54
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.

3 participants