Skip to content

Commit

Permalink
Merge branch 'main' into fix/json-output
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa authored Jul 30, 2024
2 parents 17e272d + e7acd0c commit 6b41da6
Show file tree
Hide file tree
Showing 253 changed files with 5,074 additions and 3,087 deletions.
119 changes: 47 additions & 72 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,131 +53,106 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@ea251d4d2f03a9c18841ae1b752f58b82dfb4d5e # v35.3.0
with:
files: |
docs/**
.github/**
!.github/workflows/ci.yml
**.md
- uses: ./.github/actions/setup-and-cache
if: steps.changed-files.outputs.only_changed != 'true'
with:
node-version: ${{ matrix.node_version }}

- uses: browser-actions/setup-chrome@v1
if: steps.changed-files.outputs.only_changed != 'true'

- name: Install
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm i

- name: Install Playwright Dependencies
run: pnpm exec playwright install --with-deps
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm exec playwright install chromium --with-deps

- name: Build
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run build

- name: Test
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run test:ci

- name: Test Examples
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run test:examples

test-ui:
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
fail-fast: false

runs-on: ${{ matrix.os }}

timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-and-cache
with:
node-version: 20

- name: Install
run: pnpm i

- name: Install Playwright Dependencies
run: pnpm exec playwright install chromium

- name: Build
run: pnpm run build

- name: Unit Test UI
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run -C packages/ui test:ui

- name: E2E Test UI
run: pnpm -C test/ui test-e2e

test-browser:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
browser: [[chrome, chromium], [firefox, firefox], [edge, webkit]]
os:
- macos-14
- windows-latest
browser:
- [chromium, chrome]
- [firefox, firefox]
- [webkit]
fail-fast: false

timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@ea251d4d2f03a9c18841ae1b752f58b82dfb4d5e # v35.3.0
with:
files: |
docs/**
.github/**
!.github/workflows/ci.yml
**.md
- uses: ./.github/actions/setup-and-cache
if: steps.changed-files.outputs.only_changed != 'true'
with:
node-version: 20

- uses: browser-actions/setup-chrome@v1
if: ${{ steps.changed-files.outputs.only_changed != 'true' && matrix.browser[0] == 'chromium' }}
- uses: browser-actions/setup-firefox@v1
if: ${{ steps.changed-files.outputs.only_changed != 'true' && matrix.browser[0] == 'firefox' }}

- name: Install
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm i

- name: Install Playwright Dependencies
run: pnpm exec playwright install --with-deps
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm exec playwright install ${{ matrix.browser[0] }} --with-deps

- name: Build
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run build

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (playwright)
if: steps.changed-files.outputs.only_changed != 'true'
run: pnpm run test:browser:playwright
env:
BROWSER: ${{ matrix.browser[1] }}

test-browser-windows:
runs-on: windows-latest
strategy:
matrix:
browser: [[chrome, chromium], [edge, webkit]]
fail-fast: false

timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-and-cache
with:
node-version: 20

- uses: browser-actions/setup-chrome@v1
- uses: browser-actions/setup-edge@v1

- name: Install
run: pnpm i

- name: Install Playwright Dependencies
run: pnpm exec playwright install --with-deps

- name: Build
run: pnpm run build
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (playwright)
run: pnpm run test:browser:playwright
if: ${{ steps.changed-files.outputs.only_changed != 'true' && matrix.browser[1] }}
env:
BROWSER: ${{ matrix.browser[1] }}
11 changes: 10 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ export default ({ mode }: { mode: string }) => {
light: 'github-light',
dark: 'github-dark',
},
codeTransformers: mode === 'development' ? [] : [transformerTwoslash()],
codeTransformers: mode === 'development'
? []
: [transformerTwoslash({
processHoverInfo: (info) => {
if (info.includes(process.cwd())) {
return info.replace(new RegExp(process.cwd(), 'g'), '')
}
return info
},
})],
},
themeConfig: {
logo: '/logo.svg',
Expand Down
45 changes: 37 additions & 8 deletions docs/.vitepress/scripts/cli-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,37 @@ import type { CLIOption, CLIOptions } from '../../../packages/vitest/src/node/cl
import { cliOptionsConfig } from '../../../packages/vitest/src/node/cli/cli-config'

const docsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
const cliTablePath = resolve(docsDir, './guide/cli-table.md')
const cliTablePath = resolve(docsDir, './guide/cli-generated.md')

const nonNullable = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined

const skipCli = new Set([
'mergeReports',
'changed',
'shard',
])

const skipConfig = new Set([
'config',
'api.port',
'api.host',
'api.strictPort',
'coverage.watermarks.statements',
'coverage.watermarks.lines',
'coverage.watermarks.branches',
'coverage.watermarks.functions',
'coverage.thresholds.statements',
'coverage.thresholds.branches',
'coverage.thresholds.functions',
'coverage.thresholds.lines',
'standalone',
'clearScreen',
'color',
'run',
'hideSkippedTests',
'dom',
])

function resolveOptions(options: CLIOptions<any>, parentName?: string) {
return Object.entries(options).flatMap(
([subcommandName, subcommandConfig]) => resolveCommand(
Expand All @@ -19,7 +46,7 @@ function resolveOptions(options: CLIOptions<any>, parentName?: string) {
}

function resolveCommand(name: string, config: CLIOption<any> | null): any {
if (!config) {
if (!config || skipCli.has(name)) {
return null
}

Expand All @@ -37,17 +64,19 @@ function resolveCommand(name: string, config: CLIOption<any> | null): any {
}

return {
title,
title: name,
cli: title,
description: config.description,
}
}

const options = resolveOptions(cliOptionsConfig)

const template = `
| Options | |
| ------------- | ------------- |
${options.map(({ title, description }) => `| ${title} | ${description} |`).join('\n')}
`.trimStart()
const template = options.map((option) => {
const title = option.title
const cli = option.cli
const config = skipConfig.has(title) ? '' : `[${title}](/config/#${title.toLowerCase().replace(/\./g, '-')})`
return `### ${title}\n\n- **CLI:** ${cli}\n${config ? `- **Config:** ${config}\n` : ''}\n${option.description}\n`
}).join('\n')

writeFileSync(cliTablePath, template, 'utf-8')
6 changes: 3 additions & 3 deletions docs/advanced/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Vitest exposes experimental private API. Breaking changes might not follow SemVe

You can start running Vitest tests using its Node API:

```js twoslash
```js
import { startVitest } from 'vitest/node'

const vitest = await startVitest('test')
Expand Down Expand Up @@ -38,7 +38,7 @@ Alternatively, you can pass in the complete Vite config as the fourth argument,
You can create Vitest instance yourself using `createVitest` function. It returns the same `Vitest` instance as `startVitest`, but it doesn't start tests and doesn't validate installed packages.
```js twoslash
```js
import { createVitest } from 'vitest/node'

const vitest = await createVitest('test', {
Expand All @@ -50,7 +50,7 @@ const vitest = await createVitest('test', {
You can use this method to parse CLI arguments. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
```ts twoslash
```ts
import { parseCLI } from 'vitest/node'

parseCLI('vitest ./files.ts --coverage --browser=chrome')
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Vitest runs tests in pools. By default, there are several pools:

You can provide your own pool by specifying a file path:

```ts twoslash
```ts
import { defineConfig } from 'vitest/config'
// ---cut---

export default defineConfig({
test: {
// will run every file with a custom pool by default
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can import reporters from `vitest/reporters` and extend them to create your

In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend.

```ts twoslash
```ts
import { DefaultReporter } from 'vitest/reporters'

export default class MyDefaultReporter extends DefaultReporter {
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Snapshot support and some other features depend on the runner. If you don't want

You can extend Vitest task system with your tasks. A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method:

```js twoslash
```js
// ./utils/custom.js
import { createTaskCollector, getCurrentSuite, setFn } from 'vitest/suite'

Expand All @@ -134,7 +134,7 @@ export const myCustomTask = createTaskCollector(
)
```

```js twoslash
```js
// ./garden/tasks.test.js
import { afterAll, beforeAll, describe, myCustomTask } from '../custom.js'
import { gardener } from './gardener.js'
Expand Down
Loading

0 comments on commit 6b41da6

Please sign in to comment.