Skip to content

Commit

Permalink
Merge branch 'main' into fix-browser-magic-string
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 23, 2024
2 parents ae3be83 + bca7705 commit 2728080
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 32 deletions.
18 changes: 9 additions & 9 deletions docs/.vitepress/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ const plainTeamMembers: CoreTeam[] = [
title: 'A passionate enthusiast of open source contributions',
desc: 'Team member of Vitest & UnoCSS',
},
{
avatar: contributorsAvatars.zxch3n,
name: 'Zixuan Chen',
github: 'zxch3n',
mastodon: 'https://elk.zone/hachyderm.io/@zx',
twitter: 'zxch3n',
title: 'A fullstack developer',
desc: 'Working on CRDTs & local-first software',
},
{
avatar: contributorsAvatars['hi-ogawa'],
name: 'Hiroshi Ogawa',
Expand Down Expand Up @@ -155,6 +146,15 @@ const plainTeamEmeritiMembers: CoreTeam[] = [
title: 'It\'s no problem in my locall',
desc: 'Core team member of Vite & Team member of Vitest',
},
{
avatar: contributorsAvatars.zxch3n,
name: 'Zixuan Chen',
github: 'zxch3n',
mastodon: 'https://elk.zone/hachyderm.io/@zx',
twitter: 'zxch3n',
title: 'A fullstack developer',
desc: 'Working on CRDTs & local-first software',
},
]

const teamMembers = plainTeamMembers.map(tm => createLinks(tm))
Expand Down
2 changes: 0 additions & 2 deletions docs/guide/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ WebdriverIO comes with the same advantages as Cypress allowing you to test your

[@web/test-runner](https://modern-web.dev/docs/test-runner/overview/) runs tests inside a headless browser, providing the same execution environment as your web application without the need for mocking out browser APIs or the DOM. This also makes it possible to debug inside a real browser using the devtools, although there is no UI shown for stepping through the test, as there is in Cypress tests.

There is a watch mode, but it is not as intelligent as that of Vitest, and may not always re-run the tests you want.

To use @web/test-runner with a Vite project, use [@remcovaes/web-test-runner-vite-plugin](https://github.com/remcovaes/web-test-runner-vite-plugin). @web/test-runner does not include assertion or mocking libraries, so it is up to you to add them.

## uvu
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Learn more about the [Command Line Interface](/guide/cli)

We also provided a official extension for Visual Studio Code to enhance your testing experience with Vitest.

[Install from VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer)
[Install from VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=vitest.explorer)

Learn more about [IDE Integrations](/guide/ide)

Expand Down
22 changes: 22 additions & 0 deletions examples/nestjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@vitest/example-nestjs",
"type": "module",
"private": true,
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run"
},
"devDependencies": {
"@nestjs/common": "^10.3.3",
"@nestjs/testing": "^10.3.3",
"@vitest/coverage-v8": "^1.3.1",
"unplugin-swc": "^1.4.4",
"vitest": "1.3.1"
},
"stackblitz": {
"startCommand": "npm run test:ui"
}
}
17 changes: 17 additions & 0 deletions examples/nestjs/src/cats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Body, Controller, Get, Post } from '@nestjs/common'
import type { Cat, CatsService } from './cats.service'

@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}

@Post()
async create(@Body() createCatDto: Cat) {
this.catsService.create(createCatDto)
}

@Get()
async findAll(): Promise<Cat[]> {
return this.catsService.findAll()
}
}
20 changes: 20 additions & 0 deletions examples/nestjs/src/cats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@nestjs/common'

export interface Cat {
name: string
age: number
breed: string
}

@Injectable()
export class CatsService {
private readonly cats: Cat[] = []

create(cat: Cat) {
this.cats.push(cat)
}

findAll(): Cat[] {
return this.cats
}
}
23 changes: 23 additions & 0 deletions examples/nestjs/test/nestjs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { CatsController } from '../src/cats.controller'
import type { Cat } from '../src/cats.service'
import { CatsService } from '../src/cats.service'

describe('CatsController', () => {
let catsController: CatsController
let catsService: CatsService

beforeEach(() => {
catsService = new CatsService()
catsController = new CatsController(catsService)
})

describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'] as unknown as Cat[]
vi.spyOn(catsService, 'findAll').mockImplementation(() => result)

expect(await catsController.findAll()).toBe(result)
})
})
})
6 changes: 6 additions & 0 deletions examples/nestjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"experimentalDecorators": true
}
}
32 changes: 32 additions & 0 deletions examples/nestjs/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import swc from 'unplugin-swc'
import { defineConfig } from 'vitest/config'

export default defineConfig({
plugins: [
swc.vite({
jsc: {
target: 'esnext',
parser: {
syntax: 'typescript',
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
},
}),
],
test: {
coverage: {
enabled: true,
provider: 'v8',
thresholds: {
branches: 100,
functions: 57.14,
lines: 81.08,
statements: 81.08,
},
},
},
})
2 changes: 1 addition & 1 deletion packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const WRAPPER_LENGTH = 185

// Note that this needs to match the line ending as well
const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g
const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes"(\s|.)+?]\),/g
const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes", \[[^\]]*?\]\),*/g
const DEFAULT_PROJECT = Symbol.for('default-project')

const debug = createDebug('vitest:coverage')
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
project: {
description: 'The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: --project=1 --project=2',
argument: '<name>',
array: true,
},
slowTestThreshold: {
description: 'Threshold in milliseconds for a test to be considered slow (default: 300)',
Expand Down
Loading

0 comments on commit 2728080

Please sign in to comment.