Skip to content

Commit

Permalink
test: add tests for ui
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 13, 2024
1 parent d46ec03 commit 7c0eeb0
Show file tree
Hide file tree
Showing 27 changed files with 760 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.

8 changes: 8 additions & 0 deletions test/ui/astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import tutorialkit from '@tutorialkit/astro';
import { defineConfig } from 'astro/config';

export default defineConfig({
devToolbar: { enabled: false },
server: { port: 4329 },
integrations: [tutorialkit()],
});
31 changes: 31 additions & 0 deletions test/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@tutorialkit/test-ui",
"private": true,
"type": "module",
"scripts": {
"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"
}
}
14 changes: 14 additions & 0 deletions test/ui/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
webServer: {
command: 'pnpm preview',
url: 'http://localhost:4329',
reuseExistingServer: !process.env.CI,
stdout: 'ignore',
stderr: 'pipe',
},
use: {
baseURL: 'http://localhost:4329',
},
});
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: []
---
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
10 changes: 10 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,10 @@
---
type: chapter
title: Preview
lessons:
- single
- multiple
template: vite
mainCommand: 'pnpm start'
prepareCommands: ['pnpm install']
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
type: lesson
title: Multiple
previews:
- [5173, "First Server"]
- [5173, "Second Server"]
---

# 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:
- [5173, "Vite Dev 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" />
13 changes: 13 additions & 0 deletions test/ui/src/templates/default/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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>
</main>
</body>
</html>
6 changes: 6 additions & 0 deletions test/ui/src/templates/default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "default-template",
"private": true,
"version": "0.0.0",
"type": "module"
}
12 changes: 12 additions & 0 deletions test/ui/src/templates/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite Template</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/ui/src/templates/vite/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
document.querySelector('#app').innerHTML = `
<div>
<h1>Hello Vite Template!</h1>
</div>
`;
12 changes: 12 additions & 0 deletions test/ui/src/templates/vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "vite-project",
"private": true,
"type": "module",
"packageManager": "[email protected]",
"scripts": {
"start": "vite"
},
"devDependencies": {
"vite": "^5.4.0"
}
}
Loading

0 comments on commit 7c0eeb0

Please sign in to comment.