File tree Expand file tree Collapse file tree 7 files changed +830
-15
lines changed
exercises/01.setup/03.solution.code-coverage Expand file tree Collapse file tree 7 files changed +830
-15
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ data.db
1313__screenshots__
1414* .sqlite
1515test-profiles
16+ coverage
1617
1718# in a real app you'd want to not commit the .env
1819# file as well, but since this is for a workshop
Original file line number Diff line number Diff line change 11# Code coverage
2+
3+ 1 . Install ` @vitest/coverage-v8 ` .
4+ 1 . Set ` test.coverage.enabled ` to ` true ` .
5+ 1 . List explicit values in ` test.coverage.include ` to make Vitest faster.
6+
7+ Then, to preview the coverage:
8+
9+ 1 . Install ` @vitest/ui ` .
10+ 1 . Run Vitest in the UI mode: ` npx vitest --ui ` (or set ` test.ui ` to ` true ` ).
11+ 1 . Make sure to include ` html ` in the ` test.coverage.reporters ` list (you can still use other reporters).
12+ 1 . In the UI, go to the "Coverage" tab. See the coverage.
13+
14+ ## Related materials
15+
16+ - [ ** Making sense of code coverage** ] ( https://www.epicweb.dev/making-use-of-code-coverage )
17+ - [ Coverage in Vitest] ( https://main.vitest.dev/guide/coverage.html )
18+ - [ Vitest UI] ( https://main.vitest.dev/guide/ui.html )
Original file line number Diff line number Diff line change 77 "build" : " vite build"
88 },
99 "devDependencies" : {
10+ "@vitest/coverage-v8" : " ^3.1.1" ,
11+ "@vitest/ui" : " ^3.1.1" ,
1012 "vite" : " ^6.0.7" ,
1113 "vitest" : " ^3.0.5"
1214 }
Original file line number Diff line number Diff line change 1+ import { fn } from './fn'
2+
3+ test ( 'returns "great" if given a number greater than 10' , ( ) => {
4+ expect ( fn ( 42 ) ) . toBe ( 'great' )
5+ } )
Original file line number Diff line number Diff line change 1+ export function fn ( input : number ) {
2+ if ( input > 10 ) {
3+ return 'great'
4+ }
5+
6+ return 'okay'
7+ }
Original file line number Diff line number Diff line change 11import { defineConfig } from 'vitest/config'
22
33export default defineConfig ( {
4- server : {
5- port : process . env . PORT ? Number ( process . env . PORT ) : undefined ,
6- } ,
74 test : {
85 globals : true ,
6+ coverage : {
7+ enabled : true ,
8+ include : [ 'src/**/*.ts' ] ,
9+ reporter : [ 'html' ] ,
10+ } ,
911 } ,
1012} )
You can’t perform that action at this time.
0 commit comments