Skip to content

Commit 360aab1

Browse files
committed
test: add test/ui
1 parent 5c4510d commit 360aab1

39 files changed

+497
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
- name: Lint
3333
run: pnpm lint
3434

35+
- name: Install Playwright Dependencies
36+
run: pnpm exec playwright install chromium --with-deps
37+
3538
- name: Test
3639
run: pnpm test
3740

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ tsconfig.tsbuildinfo
2323
tsconfig.build.tsbuildinfo
2424
.tmp
2525
.tmp-*
26+
/test/**/test-results
27+
/test/**/.astro

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shell-emulator=true

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4-
"build": "pnpm run --stream --filter=@tutorialkit/* --filter=create-tutorial build",
4+
"build": "pnpm run --stream --filter='@tutorialkit/*' --filter=create-tutorial build",
55
"dev": "TUTORIALKIT_DEV=true pnpm -r --parallel --stream --filter='./packages/**' run dev",
66
"changelog": "./scripts/changelog.mjs",
77
"clean": "./scripts/clean.sh",
@@ -16,7 +16,7 @@
1616
"demo": "pnpm run --filter=demo.tutorialkit.dev dev",
1717
"demo:build": "pnpm run build && pnpm run --filter=demo.tutorialkit.dev build",
1818
"lint": "eslint \"{packages,docs,extensions,integration}/**/*\"",
19-
"test": "pnpm run --stream --filter=@tutorialkit/* test --run"
19+
"test": "CI=true pnpm run --stream --filter='@tutorialkit/*' test"
2020
},
2121
"license": "MIT",
2222
"packageManager": "pnpm@8.15.6",
@@ -30,6 +30,7 @@
3030
"eslint-plugin-astro": "^1.2.3",
3131
"husky": "^9.0.11",
3232
"is-ci": "^3.0.1",
33+
"playwright": "^1.46.0",
3334
"prettier": "^3.3.2",
3435
"prettier-plugin-astro": "^0.14.1",
3536
"tempfile": "^5.0.0"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/ui/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# UI Tests
2+
3+
> Tests for verifying TutorialKit works as expected in the browser. Tests are run against locally linked `@tutorialkit` packages.
4+
5+
## Running
6+
7+
- `pnpm exec playwright install chromium --with-deps` - When running the tests first time
8+
- `pnpm test`
9+
10+
## Development
11+
12+
- `pnpm start` - Starts example/fixture project's development server
13+
- `pnpm test:ui` - Start Playwright in UI mode
14+
15+
## Structure
16+
17+
Test cases are located in `test` directory.
18+
Each test file has its own `chapter`, that contains `lesson`s for test cases:
19+
20+
For example Navigation tests:
21+
22+
```
23+
├── src/content/tutorial
24+
│ └── tests
25+
│ └──── navigation
26+
│ ├── page-one
27+
│ ├── page-three
28+
│ └── page-two
29+
└── test
30+
└── navigation.test.ts
31+
```
32+
33+
Or File Tree tests:
34+
35+
```
36+
├── src/content/tutorial
37+
│ └── tests
38+
│ └── file-tree
39+
│ └── lesson-and-solution
40+
└── test
41+
└── file-tree.test.ts
42+
```

test/ui/astro.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createRequire } from 'node:module';
2+
import { resolve } from 'node:path';
3+
import tutorialkit from '@tutorialkit/astro';
4+
import { defineConfig } from 'astro/config';
5+
6+
const require = createRequire(import.meta.url);
7+
const astroDist = resolve(require.resolve('astro/package.json'), '..');
8+
const swapFunctionEntry = resolve(astroDist, 'dist/transitions/swap-functions.js');
9+
10+
export default defineConfig({
11+
devToolbar: { enabled: false },
12+
server: { port: 4329 },
13+
integrations: [tutorialkit()],
14+
15+
vite: {
16+
resolve: {
17+
alias: {
18+
// work-around for https://github.com/stackblitz/tutorialkit/pull/238
19+
'node_modules/astro/dist/transitions/swap-functions': swapFunctionEntry,
20+
},
21+
},
22+
},
23+
});

test/ui/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@tutorialkit/test-ui",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "astro dev",
7+
"start": "astro dev",
8+
"preview": "astro build && astro preview",
9+
"test": "playwright test",
10+
"test:ui": "pnpm run test --ui"
11+
},
12+
"devDependencies": {
13+
"@astrojs/react": "^3.6.0",
14+
"@iconify-json/ph": "^1.1.13",
15+
"@iconify-json/svg-spinners": "^1.1.2",
16+
"@playwright/test": "^1.46.0",
17+
"@tutorialkit/astro": "workspace:*",
18+
"@tutorialkit/components-react": "workspace:*",
19+
"@tutorialkit/runtime": "workspace:*",
20+
"@tutorialkit/theme": "workspace:*",
21+
"@tutorialkit/types": "workspace:*",
22+
"@types/node": "^22.2.0",
23+
"@unocss/reset": "^0.59.4",
24+
"@unocss/transformer-directives": "^0.62.0",
25+
"astro": "^4.12.0",
26+
"fast-glob": "^3.3.2",
27+
"playwright": "^1.46.0",
28+
"react": "^18.3.1",
29+
"react-dom": "^18.3.1",
30+
"unocss": "^0.59.4"
31+
}
32+
}

test/ui/playwright.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
expect: {
5+
timeout: process.env.CI ? 30_000 : 10_000,
6+
},
7+
use: {
8+
baseURL: 'http://localhost:4329',
9+
},
10+
webServer: {
11+
command: 'pnpm preview',
12+
url: 'http://localhost:4329',
13+
reuseExistingServer: !process.env.CI,
14+
stdout: 'ignore',
15+
stderr: 'pipe',
16+
},
17+
});

test/ui/public/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

test/ui/src/content/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { contentSchema } from '@tutorialkit/types';
2+
import { defineCollection } from 'astro:content';
3+
4+
const tutorial = defineCollection({
5+
type: 'content',
6+
schema: contentSchema,
7+
});
8+
9+
export const collections = { tutorial };

test/ui/src/content/tutorial/meta.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: tutorial
3+
mainCommand: ''
4+
prepareCommands: []
5+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Lesson file example.html title</title>
4+
</head>
5+
<body>
6+
Lesson file example.html content
7+
</body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'Lesson file example.js content';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Solution file example.html title</title>
4+
</head>
5+
<body>
6+
Solution file example.html content
7+
</body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'Solution file example.js content';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: lesson
3+
title: Lesson and solution
4+
---
5+
6+
# File Tree test - Lesson and solution
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: chapter
3+
title: File Tree
4+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Lesson file example.html title</title>
4+
</head>
5+
<body>
6+
Lesson file example.html content
7+
</body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'Lesson file example.js content';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: lesson
3+
title: No solution
4+
---
5+
6+
# File Tree test - No solution
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: part
3+
title: Tests
4+
---
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
type: chapter
3+
title: Navigation
4+
lessons:
5+
- page-one
6+
- page-two
7+
- page-three
8+
mainCommand: ''
9+
prepareCommands: []
10+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: lesson
3+
title: Page one
4+
---
5+
6+
# Navigation test - Page one
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: lesson
3+
title: Page three
4+
---
5+
6+
# Navigation test - Page three
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: lesson
3+
title: Page two
4+
---
5+
6+
# Navigation test - Page two
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: chapter
3+
title: Preview
4+
mainCommand: 'pnpm start'
5+
---
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
type: lesson
3+
title: Multiple
4+
previews:
5+
- [8000, "First Server"]
6+
- [8000, "Second Server", "/about.html"]
7+
---
8+
9+
# Preview test - Multiple
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: lesson
3+
title: Single
4+
previews:
5+
- [8000, "Node Server"]
6+
---
7+
8+
# Preview test - Single

test/ui/src/env.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path="../.astro/types.d.ts" />
2+
/// <reference types="@tutorialkit/astro/types" />
3+
/// <reference types="astro/client" />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Default template</title>
7+
</head>
8+
<body>
9+
<main>
10+
<h1>Default template</h1>
11+
<h2>About</h2>
12+
</main>
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Default template</title>
7+
</head>
8+
<body>
9+
<main>
10+
<h1>Default template</h1>
11+
<h2>Index</h2>
12+
</main>
13+
</body>
14+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import http from 'node:http';
2+
import { readFileSync } from 'node:fs';
3+
4+
const server = http.createServer((req, res) => {
5+
if (req.url === '/' || req.url === '/index.html') {
6+
res.writeHead(200, { 'Content-Type': 'text/html' });
7+
res.end(readFileSync('./index.html', 'utf8'));
8+
9+
return;
10+
}
11+
12+
if (req.url === '/about.html') {
13+
res.writeHead(200, { 'Content-Type': 'text/html' });
14+
res.end(readFileSync('./about.html'));
15+
16+
return;
17+
}
18+
19+
res.writeHead(200, { 'Content-Type': 'text/html' });
20+
res.end('Not found');
21+
});
22+
23+
server.listen(8000);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "default-template",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"start": "node ./index.mjs"
8+
}
9+
}

0 commit comments

Comments
 (0)