-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage): expensive regexp hangs v8 report generation (#5259)
- Loading branch information
1 parent
ec6f56a
commit d68a739
Showing
8 changed files
with
271 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"experimentalDecorators": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.