Skip to content

Commit 561cf82

Browse files
committed
01/02: add solution code
1 parent 2824616 commit 561cf82

File tree

28 files changed

+269
-29
lines changed

28 files changed

+269
-29
lines changed

exercises/01.setup/01.problem.vscode-extension/vite.config.ts renamed to exercises/01.setup/01.problem.vscode-extension/vitest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference types="vitest" />
21
import { defineConfig } from 'vitest/config'
32

43
export default defineConfig({
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# Multiple workspaces
2+
3+
1. Use `test.workspace` to define a list of workspaces.
4+
1. Give each workspace a unique `test.name` and `include` pattern. Also, any other configuration, like `environment`.
5+
1. Run all workspaces via `vitest` or individual workspaces via `vitest --project <WORKSPACE_NAME>`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*?raw' {
2+
const src: string
3+
export default src
4+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
"scripts": {
55
"dev": "vite",
66
"test": "vitest",
7+
"test:unit": "vitest --project unit",
8+
"test:edge": "vitest --project edge",
79
"build": "vite build"
810
},
911
"devDependencies": {
12+
"@edge-runtime/types": "^4.0.0",
13+
"@edge-runtime/vm": "^5.0.0",
14+
"edge-runtime": "^4.0.1",
1015
"vite": "^6.0.7",
1116
"vitest": "^3.0.5"
1217
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { EdgeRuntime } from 'edge-runtime'
2+
import initialCode from './handler?raw'
3+
4+
const runtime = new EdgeRuntime({
5+
initialCode,
6+
})
7+
8+
test('returns the user by id', async () => {
9+
const response = await runtime.dispatchFetch(
10+
'https://example.com/users/abc-123',
11+
)
12+
13+
await expect(response.json()).resolves.toEqual({
14+
id: 'abc-123',
15+
name: 'John Maverick',
16+
})
17+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
addEventListener('fetch', (event) => {
2+
event.respondWith(
3+
Response.json({
4+
id: 'abc-123',
5+
name: 'John Maverick',
6+
}),
7+
)
8+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { slugify } from './slugify'
2+
3+
test('returns a slugified string', () => {
4+
expect(slugify('hello world')).toBe('hello-world')
5+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function slugify(input: string): string {
2+
return input.replace(/\s+/g, '-')
3+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"extends": "./tsconfig.base.json",
33
"include": ["src/**/*"],
4-
"exclude": ["src/**/*.test.ts*"],
4+
"exclude": ["src/**/*.test.ts"],
55
"compilerOptions": {
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7-
"jsx": "react-jsx"
6+
"lib": ["esnext"]
87
}
98
}
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/api"],
4+
"exclude": ["**/*.test.ts"],
5+
"compilerOptions": {
6+
"lib": [],
7+
"types": ["@types/node", "@edge-runtime/types"]
8+
}
9+
}

0 commit comments

Comments
 (0)