Skip to content

Commit 30fd705

Browse files
committed
01/03: add exercise texts
1 parent 3eb0958 commit 30fd705

File tree

28 files changed

+271
-22
lines changed

28 files changed

+271
-22
lines changed

exercises/01.setup/01.problem.vscode-extension/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"type": "module",
33
"name": "exercises_01.setup_01.problem.vscode-extension",
44
"scripts": {
5-
"dev": "vite",
6-
"test": "vitest",
7-
"build": "vite build"
5+
"test": "vitest"
86
},
97
"devDependencies": {
108
"vite": "^6.2.6",

exercises/01.setup/01.solution.vscode-extension/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"type": "module",
33
"name": "exercises_01.setup_01.solution.vscode-extension",
44
"scripts": {
5-
"dev": "vite",
6-
"test": "vitest",
7-
"build": "vite build"
5+
"test": "vitest"
86
},
97
"devDependencies": {
108
"vite": "^6.2.6",

exercises/01.setup/02.problem.multiple-workspaces/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"type": "module",
33
"name": "exercises_01.setup_02.problem.multiple-workspaces",
44
"scripts": {
5-
"test": "vitest",
6-
"build": "vite build"
5+
"test": "vitest"
76
},
87
"devDependencies": {
98
"vitest": "^3.1.1"

exercises/01.setup/02.solution.multiple-workspaces/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
"type": "module",
33
"name": "exercises_01.setup_02.solution.multiple-workspaces",
44
"scripts": {
5-
"dev": "vite",
65
"test": "vitest",
76
"test:unit": "vitest --project unit",
8-
"test:edge": "vitest --project edge",
9-
"build": "vite build"
7+
"test:edge": "vitest --project edge"
108
},
119
"devDependencies": {
1210
"@edge-runtime/types": "^4.0.0",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Code coverage
2+
3+
Code coverage can be a useful metric if done right. I find code coverage more of a guide to tell you about the state of your test suite than a barred threshold one must pass and never, ever lower. It can point to the areas you haven't covered with tests but you are still the one to decide the appropriate strategy to address that.
4+
5+
<callout-info>You can learn more about code coverage, its dangers, and where you would use it in my article called :scroll: [Making Sense of Code Coverage](https://www.epicweb.dev/making-use-of-code-coverage).</callout-info>
6+
7+
Vitest, like many other testing frameworks, allows you to enable and configure code coverage for any type of tests. It supports two coverage providers:
8+
9+
- [`v8`](https://v8.dev/blog/javascript-code-coverage) (_default_)
10+
- [`istanbul`](https://istanbul.js.org/)
11+
12+
## Your task
13+
14+
👨‍💼 In this one, you will enable code coverage in <InlineFile file="vitest.config.ts" />, inspect its report, and see if it hints you at any missing test cases you might add.
15+
16+
🐨 Start from installing `@vitest/coverage-v8` to use as a coverage provider.
17+
18+
```
19+
npm i @vitest/coverage-v8 --save-dev
20+
```
21+
22+
🐨 Next, head to <InlineFile file="vitest.config.ts" /> and adjust the configuration to enable code coverage and use the newly installed provider.
23+
24+
🐨 Run tests via `npm test` and see the generated code coverage report. Explore it to spot any weak or missing spots in the current test suites. Optionally, add the missing tests.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "module",
3+
"name": "exercises_01.setup_03.problem.code-coverage",
4+
"scripts": {
5+
"test": "vitest"
6+
},
7+
"devDependencies": {
8+
"@vitest/ui": "^3.1.1",
9+
"vite": "^6.2.6",
10+
"vitest": "^3.1.1"
11+
}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { fn } from './fn'
2+
3+
test('returns "great" if given a number greater than 10', () => {
4+
expect(fn(42)).toBe('great')
5+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function fn(input: number) {
2+
if (input > 10) {
3+
return 'great'
4+
}
5+
6+
return 'okay'
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["src/**/*"],
4+
"exclude": ["src/**/*.test.ts*"],
5+
"compilerOptions": {
6+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7+
"jsx": "react-jsx"
8+
}
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"useDefineForClassFields": true,
6+
"skipLibCheck": true,
7+
8+
/* Bundler mode */
9+
"moduleResolution": "bundler",
10+
"allowImportingTsExtensions": true,
11+
"isolatedModules": true,
12+
"moduleDetection": "force",
13+
"noEmit": true,
14+
"verbatimModuleSyntax": true,
15+
16+
/* Linting */
17+
"strict": true,
18+
"noUnusedLocals": false,
19+
"noUnusedParameters": false,
20+
"noFallthroughCasesInSwitch": true,
21+
"noUncheckedSideEffectImports": true
22+
}
23+
}

0 commit comments

Comments
 (0)