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: proposal for the public Vitest API #6405

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Aug 26, 2024

sneaky draft proposal, look away

related #6147

// The main Vitest class
export interface Vitest {
  // the main config from the root of the project
  readonly config: ResolvedConfig
  // instances of projects defined in the workspace config
  // always has at least one project
  readonly projects: Map<string, TestProject>
  // global Vite server instance
  readonly vite: ViteDevServer
  // class that runs tests and stores results
  readonly runner: VitestRunner
  // global inject/provide context
  readonly context: VitestContext
  // snapshot state
  readonly snapshot: VitestSnapshot
  readonly logger: Logger

  onClose(cb: () => void): void

  close(): Promise<void>
  exit(): Promise<void>
}

interface TestProject {
  readonly config: ResolvedProjectConfig
  readonly globalConfig: ResolvedConfig // same as vitest.config
  readonly name: string
  // local project context
  readonly context: VitestContext
  readonly vite: ViteDevServer
  // config that can be sent as a json
  readonly serializedConfig: SerializedConfig
  // browser server instance if tests are running in the browser
  readonly browser: BrowserServer | null
  // an easy way to create a spec
  createSpecification(moduleId: string): TestSpecification
}

export interface VitestRunner {
  // Vitest starts a standalone runner, will react on watch changes, it doesn't run tests
  start: () => void
  stop: () => void

  // Map<filepath, spec[]>
  // unique by project+pool, creating a new spec overrides the old one
  readonly specifications: Map<string, Array<TestSpecification>>

  run: () => Promise<TestRunResult>
  collect: () => Promise<TestRunResult>
  // run module in every project
  runModules: (moduleNames: string[]) => Promise<TestRunResult>
  // run specific tests
  runTests: (specifications: Array<TestSpecification>) => Promise<TestRunResult>
  mergeReports: () => Promise<TestRunResult>
}

interface TestRunResult {
  testModules: TestModule[]
  errors: TestError[]
}

Copy link

netlify bot commented Aug 26, 2024

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 273affe
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/66ccba73513a09000875268f
😎 Deploy Preview https://deploy-preview-6405--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.

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.

1 participant