Skip to content

Commit 74e0527

Browse files
authored
test: add tests for ui (#241)
1 parent a580bb5 commit 74e0527

File tree

41 files changed

+846
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+846
-16
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ jobs:
3535
- name: Test
3636
run: pnpm test
3737

38+
test-e2e:
39+
name: Test E2E
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
45+
- uses: ./.github/actions/setup-and-build
46+
47+
- name: Install Playwright Dependencies
48+
run: pnpm --filter=tutorialkit-e2e exec playwright install chromium --with-deps
49+
50+
- name: Test
51+
run: pnpm test:e2e
52+
3853
docs:
3954
name: Docs
4055
runs-on: ubuntu-latest

.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+
/e2e/**/test-results
27+
/e2e/**/.astro

.npmrc

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

e2e/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+
```

e2e/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+
});

e2e/package.json

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

e2e/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+
});

e2e/public/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

e2e/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 };

e2e/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+
---

0 commit comments

Comments
 (0)