Skip to content

Commit 5f23d24

Browse files
committed
01/01: add exercise texts
1 parent 5af8680 commit 5f23d24

27 files changed

+263
-47
lines changed

exercises/01.setup/01.problem.vscode-extension/README.mdx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,12 @@ All of those things (and more) are provided by the official Vitest extension! Le
1515

1616
> At the time of writing this, Vitest provides an official extension only for Visual Studio Code. Keep an eye on the [IDE integrations](https://vitest.dev/guide/#ide-integrations) for any future support for other IDEs.
1717
18-
## Installing extension
18+
## Your task
1919

20-
🐨 Install the [Vitest extension](https://marketplace.visualstudio.com/items?itemName=vitest.explorer) from Visual Studio Code Marketplace.
20+
👨‍💼 In this exercise, let's go through the steps needed to get the Vitest extension up and running together.
2121

22-
And ... that's it! 🎉 Next, we will explore how to use the extension to iterate on tests faster and help you debug failed tests more efficiently.
22+
🐨 First, install the [Vitest extension](https://marketplace.visualstudio.com/items?itemName=vitest.explorer) from Visual Studio Code Marketplace (or search for "vitest" in the "Extensions" tab of the editor).
2323

24-
## Running tests inline
24+
![](/assets/01-01-vitest-vscode-extension.png)
2525

26-
Now, you can go to any test case in your project and click on the green "run" icon next to the test's name to run it inline. Vitest will report the test results right next to the test.
27-
28-
> 🦉 You can run all tests or a subset of tests from the "Testing" tab in your explorer as well.
29-
30-
## Continuous run
31-
32-
Start a continuous run of your tests by going to the "Testing" tab and clicking on the "Start Continuous Run" button (with the eye icon) in the controls panel of the extension. You will be prompted to choose test files to run in continuous (i.e. watch) mode.
33-
34-
Once the continuous run is active, you will see the test results _immediately_ as you work on your code or write your tests. This makes for a lightning-fast feedback loop when testing.
35-
36-
## Debugging failed tests
37-
38-
You can start a pre-configured debugging session for any test by clicking on the "Debug Test" button next to the failing test (or, alternatively, debug all tests via the "Debug Tests" button on the top panel). Use debuggers, breakpoints, and Debug Console to hunt down those nasty bugs and fix them.
26+
And ... that's it! 🎉 Next, let's explore how to use the extension to iterate on tests faster and help you debug failed tests more efficiently.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["vitest.explorer"]
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Visual Studio Code extension
2+
3+
There is a couple of things that the Vitest extension enables you to do.
4+
5+
## Running tests inline
6+
7+
Now, you can go to any test case in your project and click on the green "run" icon next to the test's name to run it inline. Vitest will report the test results right next to the test.
8+
9+
![A screenshot of Visual Studio Code with a test file open. On the left, next to the test name, a green play button displays a hint "Click to run tests, right click for more options".](/assets/01-01-run-tests-inline.png)
10+
11+
Alternatively, head to the "Testing" tab of your editor and use the extension controls to run, watch, and debug any test suites or test cases you need:
12+
13+
![A screenshot of Visual Studio Code with the "Testing" tab open to the right. A list of tests is displayed, and the cursor is hovering over the play button next to a test case that says "Run Test".](/assets/01-01-run-tests-extension.png)
14+
15+
## Continuous run
16+
17+
Start a continuous run of your tests by going to the "Testing" tab and clicking on the "Start Continuous Run" button (with the eye icon) in the controls panel of the extension. You will be prompted to choose test files to run in continuous (i.e. watch) mode.
18+
19+
![A screenshot of Visual Studio Code with the failed assertion displayed inline next to the assertion itself. Below, an open terminal displays an extended diff between the expected and the actual results.](/assets/01-01-watch-mode.png)
20+
21+
Once the continuous run is active, you will see the test results _immediately_ as you work on your code or write your tests, both in the terminal and next to the failing assertions. This makes for a lightning-fast feedback loop when testing.
22+
23+
## Debugging failed tests
24+
25+
You can start a pre-configured debugging session for any test by clicking on the "Debug Test" button next to the failing test (or, alternatively, debug all tests via the "Debug Tests" button on the top panel). Use debuggers, breakpoints, and Debug Console to hunt down those nasty bugs and fix them.
26+
27+
![A screenshot of Visual Studio Code with a breakpoint set next to a line in the test. The "Testing" panel is open on the right, and the cursor is over the button that says "Debug Test".](/assets/01-01-debug-test.png)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "module",
3+
"name": "exercises_01.setup_01.solution.vscode-extension",
4+
"scripts": {
5+
"dev": "vite",
6+
"test": "vitest",
7+
"build": "vite build"
8+
},
9+
"devDependencies": {
10+
"vite": "^6.2.6",
11+
"vitest": "^3.1.1"
12+
}
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { sortBy } from './sort-by'
2+
3+
test('sorts a list of fruits by their name', () => {
4+
expect(
5+
sortBy(
6+
[{ name: 'Banana' }, { name: 'Apple' }, { name: 'Cucumber' }],
7+
'name',
8+
),
9+
).toEqual([{ name: 'Apple' }, { name: 'Banana' }, { name: 'Cucumber' }])
10+
})
11+
12+
test('sorts a list of players by their score', () => {
13+
expect(
14+
sortBy(
15+
[
16+
{ name: 'John', score: 10 },
17+
{ name: 'Allen', score: 5 },
18+
{ name: 'Sarah', score: 21 },
19+
],
20+
'score',
21+
),
22+
).toEqual([
23+
{ name: 'Sarah', score: 21 },
24+
{ name: 'John', score: 10 },
25+
{ name: 'Allen', score: 5 },
26+
])
27+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function sortBy<T extends Record<string, unknown>>(
2+
list: Array<T>,
3+
sortKey: keyof T,
4+
): Array<T> {
5+
const clone = structuredClone(list)
6+
7+
clone.sort((left, right) => {
8+
return left[sortKey] < right[sortKey] ? -1 : 1
9+
})
10+
11+
return clone
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["src/**/*"],
4+
"exclude": ["src/**/*.test.ts*"]
5+
}
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{ "path": "./tsconfig.app.json" },
5+
{ "path": "./tsconfig.node.json" },
6+
{ "path": "./tsconfig.test.json" }
7+
]
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"lib": ["ES2023"]
5+
},
6+
"include": ["vitest.config.ts"]
7+
}

0 commit comments

Comments
 (0)