Skip to content

Commit

Permalink
test: add test/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 20, 2024
1 parent bcb666f commit 9e72229
Show file tree
Hide file tree
Showing 39 changed files with 497 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Lint
run: pnpm lint

- name: Install Playwright Dependencies
run: pnpm exec playwright install chromium --with-deps

- name: Test
run: pnpm test

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ tsconfig.tsbuildinfo
tsconfig.build.tsbuildinfo
.tmp
.tmp-*
/test/**/test-results
/test/**/.astro
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shell-emulator=true
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"scripts": {
"build": "pnpm run --stream --filter=@tutorialkit/* --filter=create-tutorial build",
"build": "pnpm run --stream --filter='@tutorialkit/*' --filter=create-tutorial build",
"dev": "TUTORIALKIT_DEV=true pnpm -r --parallel --stream --filter='./packages/**' run dev",
"changelog": "./scripts/changelog.mjs",
"clean": "./scripts/clean.sh",
Expand All @@ -16,7 +16,7 @@
"demo": "pnpm run --filter=demo.tutorialkit.dev dev",
"demo:build": "pnpm run build && pnpm run --filter=demo.tutorialkit.dev build",
"lint": "eslint \"{packages,docs,extensions,integration}/**/*\"",
"test": "pnpm run --stream --filter=@tutorialkit/* test --run"
"test": "CI=true pnpm run --stream --filter='@tutorialkit/*' test"
},
"license": "MIT",
"packageManager": "[email protected]",
Expand All @@ -30,6 +30,7 @@
"eslint-plugin-astro": "^1.2.3",
"husky": "^9.0.11",
"is-ci": "^3.0.1",
"playwright": "^1.46.0",
"prettier": "^3.3.2",
"prettier-plugin-astro": "^0.14.1",
"tempfile": "^5.0.0"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions test/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# UI Tests

> Tests for verifying TutorialKit works as expected in the browser. Tests are run against locally linked `@tutorialkit` packages.
## Running

- `pnpm exec playwright install chromium --with-deps` - When running the tests first time
- `pnpm test`

## Development

- `pnpm start` - Starts example/fixture project's development server
- `pnpm test:ui` - Start Playwright in UI mode

## Structure

Test cases are located in `test` directory.
Each test file has its own `chapter`, that contains `lesson`s for test cases:

For example Navigation tests:

```
├── src/content/tutorial
│ └── tests
│ └──── navigation
│ ├── page-one
│ ├── page-three
│ └── page-two
└── test
└── navigation.test.ts
```

Or File Tree tests:

```
├── src/content/tutorial
│ └── tests
│ └── file-tree
│ └── lesson-and-solution
└── test
└── file-tree.test.ts
```
23 changes: 23 additions & 0 deletions test/ui/astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createRequire } from 'node:module';
import { resolve } from 'node:path';
import tutorialkit from '@tutorialkit/astro';
import { defineConfig } from 'astro/config';

const require = createRequire(import.meta.url);
const astroDist = resolve(require.resolve('astro/package.json'), '..');
const swapFunctionEntry = resolve(astroDist, 'dist/transitions/swap-functions.js');

export default defineConfig({
devToolbar: { enabled: false },
server: { port: 4329 },
integrations: [tutorialkit()],

vite: {
resolve: {
alias: {
// work-around for https://github.com/stackblitz/tutorialkit/pull/238
'node_modules/astro/dist/transitions/swap-functions': swapFunctionEntry,
},
},
},
});
32 changes: 32 additions & 0 deletions test/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@tutorialkit/test-ui",
"private": true,
"type": "module",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"preview": "astro build && astro preview",
"test": "playwright test",
"test:ui": "pnpm run test --ui"
},
"devDependencies": {
"@astrojs/react": "^3.6.0",
"@iconify-json/ph": "^1.1.13",
"@iconify-json/svg-spinners": "^1.1.2",
"@playwright/test": "^1.46.0",
"@tutorialkit/astro": "workspace:*",
"@tutorialkit/components-react": "workspace:*",
"@tutorialkit/runtime": "workspace:*",
"@tutorialkit/theme": "workspace:*",
"@tutorialkit/types": "workspace:*",
"@types/node": "^22.2.0",
"@unocss/reset": "^0.59.4",
"@unocss/transformer-directives": "^0.62.0",
"astro": "^4.12.0",
"fast-glob": "^3.3.2",
"playwright": "^1.46.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"unocss": "^0.59.4"
}
}
17 changes: 17 additions & 0 deletions test/ui/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
expect: {
timeout: process.env.CI ? 30_000 : 10_000,
},
use: {
baseURL: 'http://localhost:4329',
},
webServer: {
command: 'pnpm preview',
url: 'http://localhost:4329',
reuseExistingServer: !process.env.CI,
stdout: 'ignore',
stderr: 'pipe',
},
});
1 change: 1 addition & 0 deletions test/ui/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/ui/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { contentSchema } from '@tutorialkit/types';
import { defineCollection } from 'astro:content';

const tutorial = defineCollection({
type: 'content',
schema: contentSchema,
});

export const collections = { tutorial };
5 changes: 5 additions & 0 deletions test/ui/src/content/tutorial/meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
type: tutorial
mainCommand: ''
prepareCommands: []
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Lesson file example.html title</title>
</head>
<body>
Lesson file example.html content
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'Lesson file example.js content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Solution file example.html title</title>
</head>
<body>
Solution file example.html content
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'Solution file example.js content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: lesson
title: Lesson and solution
---

# File Tree test - Lesson and solution
4 changes: 4 additions & 0 deletions test/ui/src/content/tutorial/tests/file-tree/meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: chapter
title: File Tree
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Lesson file example.html title</title>
</head>
<body>
Lesson file example.html content
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'Lesson file example.js content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: lesson
title: No solution
---

# File Tree test - No solution
4 changes: 4 additions & 0 deletions test/ui/src/content/tutorial/tests/meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: part
title: Tests
---
10 changes: 10 additions & 0 deletions test/ui/src/content/tutorial/tests/navigation/meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
type: chapter
title: Navigation
lessons:
- page-one
- page-two
- page-three
mainCommand: ''
prepareCommands: []
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: lesson
title: Page one
---

# Navigation test - Page one
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: lesson
title: Page three
---

# Navigation test - Page three
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: lesson
title: Page two
---

# Navigation test - Page two
5 changes: 5 additions & 0 deletions test/ui/src/content/tutorial/tests/preview/meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
type: chapter
title: Preview
mainCommand: 'pnpm start'
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
type: lesson
title: Multiple
previews:
- [8000, "First Server"]
- [8000, "Second Server", "/about.html"]
---

# Preview test - Multiple
8 changes: 8 additions & 0 deletions test/ui/src/content/tutorial/tests/preview/single/content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
type: lesson
title: Single
previews:
- [8000, "Node Server"]
---

# Preview test - Single
3 changes: 3 additions & 0 deletions test/ui/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="@tutorialkit/astro/types" />
/// <reference types="astro/client" />
14 changes: 14 additions & 0 deletions test/ui/src/templates/default/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Default template</title>
</head>
<body>
<main>
<h1>Default template</h1>
<h2>About</h2>
</main>
</body>
</html>
14 changes: 14 additions & 0 deletions test/ui/src/templates/default/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Default template</title>
</head>
<body>
<main>
<h1>Default template</h1>
<h2>Index</h2>
</main>
</body>
</html>
23 changes: 23 additions & 0 deletions test/ui/src/templates/default/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import http from 'node:http';
import { readFileSync } from 'node:fs';

const server = http.createServer((req, res) => {
if (req.url === '/' || req.url === '/index.html') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(readFileSync('./index.html', 'utf8'));

return;
}

if (req.url === '/about.html') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(readFileSync('./about.html'));

return;
}

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Not found');
});

server.listen(8000);
9 changes: 9 additions & 0 deletions test/ui/src/templates/default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "default-template",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "node ./index.mjs"
}
}
Loading

0 comments on commit 9e72229

Please sign in to comment.