Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 23, 2023
2 parents 8161000 + a29fece commit 6ccbf72
Show file tree
Hide file tree
Showing 115 changed files with 5,536 additions and 1,076 deletions.
5 changes: 0 additions & 5 deletions docs/advanced/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Vitest instance requires the current test mode. It can be either:
- `test` when running runtime tests
- `benchmark` when running benchmarks
- `typecheck` when running type tests
### mode
Expand All @@ -64,10 +63,6 @@ Test mode will only call functions inside `test` or `it`, and throws an error wh
Benchmark mode calls `bench` functions and throws an error, when it encounters `test` or `it`. This mode uses `benchmark.include` and `benchmark.exclude` options in the config to find benchmark files.
#### typecheck
Typecheck mode doesn't _run_ tests. It only analyses types and gives a summary. This mode uses `typecheck.include` and `typecheck.exclude` options in the config to find files to analyze.
### start
You can start running tests or benchmarks with `start` method. You can pass an array of strings to filter test files.
4 changes: 2 additions & 2 deletions docs/api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type Awaitable<T> = T | PromiseLike<T>
})
```

Everything in JavaScript is truthy, except `false`, `0`, `''`, `null`, `undefined`, and `NaN`.
Everything in JavaScript is truthy, except `false`, `null`, `undefined`, `NaN`, `0`, `-0`, `0n`, `""` and `document.all`.

## toBeFalsy

Expand Down Expand Up @@ -224,7 +224,7 @@ type Awaitable<T> = T | PromiseLike<T>
})
```

Everything in JavaScript is truthy, except `false`, `0`, `''`, `null`, `undefined`, and `NaN`.
Everything in JavaScript is truthy, except `false`, `null`, `undefined`, `NaN`, `0`, `-0`, `0n`, `""` and `document.all`.

## toBeNull

Expand Down
50 changes: 48 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export default defineConfig({

### poolMatchGlobs

- **Type:** `[string, 'threads' | 'forks' | 'vmThreads'][]`
- **Type:** `[string, 'threads' | 'forks' | 'vmThreads' | 'typescript'][]`
- **Default:** `[]`
- **Version:** Since Vitest 0.29.4

Expand Down Expand Up @@ -1319,7 +1319,7 @@ Run all tests in a specific browser. Possible options in different providers:

- **Type:** `boolean`
- **Default:** `process.env.CI`
- **CLI:** `--browser.headless`, `--brower.headless=false`
- **CLI:** `--browser.headless`, `--browser.headless=false`

Run the browser in a `headless` mode. If you are running Vitest in CI, it will be enabled by default.

Expand Down Expand Up @@ -1637,6 +1637,24 @@ Changes the order in which setup files are executed.

Options for configuring [typechecking](/guide/testing-types) test environment.

#### typecheck.enabled

- **Type**: `boolean`
- **Default**: `false`
- **CLI**: `--typecheck`, `--typecheck.enabled`
- **Version**: Since Vitest 1.0.0-beta.3

Enable typechecking alongside your regular tests.

#### typecheck.only

- **Type**: `boolean`
- **Default**: `false`
- **CLI**: `--typecheck.only`
- **Version**: Since Vitest 1.0.0-beta.3

Run only typecheck tests, when typechecking is enabled. When using CLI, this option will automatically enable typechecking.

#### typecheck.checker

- **Type**: `'tsc' | 'vue-tsc' | string`
Expand Down Expand Up @@ -1767,6 +1785,34 @@ export default defineConfig({
})
```

### onStackTrace

- **Type**: `(error: Error, frame: ParsedStack) => boolean | void`
- **Version**: Since Vitest 1.0.0-beta.3

Apply a filtering function to each frame of each stacktrace when handling errors. The first argument, `error`, is an object with the same properties as a standard `Error`, but it is not an actual instance.

Can be useful for filtering out stacktrace frames from third-party libraries.

```ts
import type { ParsedStack } from 'vitest'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
onStackTrace(error: Error, { file }: ParsedStack): boolean | void {
// If we've encountered a ReferenceError, show the whole stack.
if (error.name === 'ReferenceError')
return

// Reject all frames from third party libraries.
if (file.includes('node_modules'))
return false
},
},
})
```

### diff

- **Type:** `string`
Expand Down
12 changes: 7 additions & 5 deletions docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim
| `--ui` | Enable UI |
| `--open` | Open the UI automatically if enabled (default: `true`) |
| `--api [api]` | Serve API, available options: `--api.port <port>`, `--api.host [host]` and `--api.strictPort` |
| `--threads` | Enable Threads (default: `true`) |
| `--single-thread` | Run tests inside a single thread, requires --threads (default: `false`) |
| `--experimental-vm-threads` | Run tests in a worker pool using VM isolation (default: `false`) |
| `--experimental-vm-worker-memory-limit` | Set the maximum allowed memory for a worker. When reached, a new worker will be created instead |
| `--pool <pool>` | Specify pool, if not running in the browser (default: `threads`) |
| `--poolOptions <options>` | Specify pool options |
| `--poolOptions.threads.isolate` | Isolate tests in threads pool (default: `true`) |
| `--poolOptions.forks.isolate` | Isolate tests in forks pool (default: `true`) |
| `--silent` | Silent console output from tests |
| `--isolate` | Isolate environment for each test file (default: `true`) |
| `--reporter <name>` | Select reporter: `default`, `verbose`, `dot`, `junit`, `json`, or a path to a custom reporter |
| `--outputFile <filename/-s>` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified <br /> Via [cac's dot notation] you can specify individual outputs for multiple reporters |
| `--coverage` | Enable coverage report |
Expand All @@ -97,6 +96,9 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim
| `--inspect-brk` | Enables Node.js inspector with break |
| `--bail <number>` | Stop test execution when given number of tests have failed |
| `--retry <times>` | Retry the test specific number of times if it fails |
| `--typecheck [options]` | Custom options for typecheck pool. If passed without options, enables typechecking |
| `--typecheck.enabled` | Enable typechecking alongside tests (default: `false`) |
| `--typecheck.only` | Run only typecheck tests. This automatically enables typecheck (default: `false`) |
| `-h, --help` | Display available CLI options |

::: tip
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ You can try Vitest online on [StackBlitz](https://vitest.new). It runs Vitest di
```bash [pnpm]
pnpm add -D vitest
```
```bash [bun]
bun add -D vitest
```
:::

:::tip
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/test-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ it('math is hard', ({ skip }) => {

## Extend Test Context

Vitest provides two diffident ways to help you extend the test context.
Vitest provides two different ways to help you extend the test context.

### `test.extend`

Expand Down
10 changes: 5 additions & 5 deletions docs/guide/testing-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ assertType<string>(answr) //

## Run typechecking

Add this command to your `scripts` section in `package.json`:
To enabled typechecking, just add `--typecheck` flag to your Vitest command in `package.json`:

```json
{
"scripts": {
"typecheck": "vitest typecheck"
"test": "vitest --typecheck"
}
}
```
Expand All @@ -80,13 +80,13 @@ Now you can run typecheck:

```sh
# npm
npm run typecheck
npm run test

# yarn
yarn typecheck
yarn test

# pnpm
pnpm run typecheck
pnpm run test
```

Vitest uses `tsc --noEmit` or `vue-tsc --noEmit`, depending on your configuration, so you can remove these scripts from your pipeline.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"https-localhost": "^4.7.1",
"unocss": "^0.53.4",
"unplugin-vue-components": "^0.25.1",
"vite": "^4.0.0",
"vite": "^4.5.0",
"vite-plugin-pwa": "^0.16.4",
"vitepress": "1.0.0-beta.5",
"workbox-window": "^7.0.0"
Expand Down
8 changes: 5 additions & 3 deletions examples/playwright/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { chromium } from 'playwright'
import type { Browser, Page } from 'playwright'
import { expect } from '@playwright/test'

const PORT = 3001

// unstable in Windows, TODO: investigate
describe.runIf(process.platform !== 'win32')('basic', async () => {
let server: PreviewServer
let browser: Browser
let page: Page

beforeAll(async () => {
server = await preview({ preview: { port: 3000 } })
browser = await chromium.launch()
server = await preview({ preview: { port: PORT } })
browser = await chromium.launch({ headless: true })
page = await browser.newPage()
})

Expand All @@ -25,7 +27,7 @@ describe.runIf(process.platform !== 'win32')('basic', async () => {
})

test('should change count when button clicked', async () => {
await page.goto('http://localhost:3000')
await page.goto(`http://localhost:${PORT}`)
const button = page.getByRole('button', { name: /Clicked/ })
await expect(button).toBeVisible()

Expand Down
32 changes: 14 additions & 18 deletions examples/puppeteer/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { preview } from 'vite'
import type { PreviewServer } from 'vite'
import puppeteer from 'puppeteer'
import { launch } from 'puppeteer'
import type { Browser, Page } from 'puppeteer'

const PORT = 3000

describe('basic', async () => {
let server: PreviewServer
let browser: Browser
let page: Page

beforeAll(async () => {
server = await preview({ preview: { port: 3000 } })
browser = await puppeteer.launch()
server = await preview({ preview: { port: PORT } })
browser = await launch({ headless: true })
page = await browser.newPage()
})

Expand All @@ -22,22 +24,16 @@ describe('basic', async () => {
})
})

// TODO make more stable
test.skip('should have the correct title', async () => {
try {
await page.goto('http://localhost:3000')
const button = (await page.$('#btn'))!
expect(button).toBeDefined()
test('should have the correct title', async () => {
await page.goto(`http://localhost:${PORT}`)
const button = (await page.$<HTMLButtonElement>('#btn'))!
expect(button).toBeDefined()

let text = await page.evaluate(btn => btn.textContent, button)
expect(text).toBe('Clicked 0 time(s)')
let text = await page.evaluate(btn => btn.textContent, button)
expect(text).toBe('Clicked 0 time(s)')

await button.click()
text = await page.evaluate(btn => btn.textContent, button)
}
catch (e) {
console.error(e)
expect(e).toBeUndefined()
}
await button.click()
text = await page.evaluate(btn => btn.textContent, button)
expect(text).toBe('Clicked 1 time(s)')
}, 60_000)
})
3 changes: 3 additions & 0 deletions examples/react-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"@storybook/addon-actions": "^6.5.5",
"@storybook/addon-essentials": "^6.5.5",
"@storybook/addon-links": "^6.5.5",
"@storybook/addons": "^6.5.5",
"@storybook/builder-vite": "^0.1.35",
"@storybook/client-api": "^6.5.5",
"@storybook/preview-web": "^6.5.5",
"@storybook/react": "^6.5.5",
"@storybook/testing-library": "^0.0.11",
"@storybook/testing-react": "^1.3.0",
Expand Down
7 changes: 4 additions & 3 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[build.environment]
NPM_FLAGS = "--version"
NODE_VERSION = "16"
NODE_VERSION = "18"
# don't need playwright for docs build
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1"

[build]
publish = "docs/.vitepress/dist"
command = "npx pnpm@7.8.0 i --store=node_modules/.pnpm-store --no-frozen-lockfile && npm run docs:build"
command = "pnpm docs:build"
ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- docs/ package.json pnpm-lock.yaml"

[[redirects]]
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@vitest/monorepo",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"private": true,
"packageManager": "pnpm@8.7.4",
"packageManager": "pnpm@8.9.2",
"description": "Next generation testing framework powered by Vite",
"scripts": {
"ci": "ni && nr typecheck && nr lint && nr build && nr test:all",
Expand Down Expand Up @@ -56,12 +56,11 @@
"fast-glob": "^3.3.0",
"if-node-version": "^1.1.1",
"lint-staged": "^13.2.3",
"magic-string": "^0.30.1",
"magic-string": "^0.30.5",
"node-fetch-native": "^1.4.0",
"npm-run-all": "^4.1.5",
"ofetch": "^1.3.3",
"pathe": "^1.1.1",
"pnpm": "8.6.6",
"rimraf": "^5.0.1",
"rollup": "^3.29.4",
"rollup-plugin-dts": "^6.0.2",
Expand All @@ -71,12 +70,12 @@
"ts-node": "^10.9.1",
"tsup": "^6.7.0",
"typescript": "^5.1.6",
"vite": "^4.2.1",
"vite": "^4.5.0",
"vitest": "workspace:*"
},
"pnpm": {
"overrides": {
"vite": "^4.4.10",
"vite": "$vite",
"vitest": "workspace:*"
},
"peerDependencyRules": {
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser",
"type": "module",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Browser running for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down Expand Up @@ -39,11 +39,11 @@
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"vitest": ">=0.34.0"
"vitest": "^1.0.0-0"
},
"dependencies": {
"estree-walker": "^3.0.3",
"magic-string": "^0.30.1",
"magic-string": "^0.30.5",
"sirv": "^2.0.3"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions packages/browser/src/client/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ export function createBrowserRunner(original: any, coverageModule: CoverageHandl
async onAfterRunFiles() {
await super.onAfterRun?.()
const coverage = await coverageModule?.takeCoverage?.()
if (coverage)
await rpc().onAfterSuiteRun({ coverage })

if (coverage) {
await rpc().onAfterSuiteRun({
coverage,
transformMode: 'web',
projectName: this.config.name,
})
}
}

onCollected(files: File[]): unknown {
Expand Down

0 comments on commit 6ccbf72

Please sign in to comment.