Skip to content

Commit 54aac29

Browse files
Add normal e2e tests
1 parent c05cd47 commit 54aac29

28 files changed

+227
-62
lines changed

.ci/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
NODE_IMAGE="node:20"
2-
PLAYWRIGHT_IMAGE="mcr.microsoft.com/playwright:v1.43.1-jammy"
2+
PLAYWRIGHT_IMAGE="mcr.microsoft.com/playwright:v1.43.0-jammy"
33
CLOUDFLARE_ACCOUNT_ID="example"
44
CLOUDFLARE_API_TOKEN="example"

.ci/Taskfile.yaml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,60 @@ tasks:
5353
-v $(pwd)/..:/app \
5454
$NODE_IMAGE /bin/bash -c "yarn lint"
5555
56-
test:
57-
desc: runs unit tests of lib
56+
build:
57+
desc: creates production build of docs
58+
cmds:
59+
- task lint
60+
- |
61+
docker run \
62+
--rm \
63+
-w /app/docs \
64+
-v $(pwd)/../docs:/app/docs \
65+
-v $(pwd)/../lib:/app/lib \
66+
$NODE_IMAGE /bin/bash -c "yarn build"
67+
68+
up:
5869
cmds:
5970
- |
60-
docker run --user {{.MY_UID}}:{{.MY_GID}} \
71+
docker run \
72+
--network="host" \
73+
-v $(pwd)/../docs:/app/docs \
74+
-v $(pwd)/../lib:/app/lib \
75+
-w /app/docs \
76+
-d $NODE_IMAGE \
77+
yarn preview
78+
79+
test:unit:
80+
desc: runs unit tests in 'lib' directory
81+
cmds:
82+
- |
83+
docker run \
6184
-v $(pwd)/../lib:/app \
6285
-w /app \
6386
$NODE_IMAGE \
6487
yarn test:unit
6588
66-
build:prepare:
67-
desc: creates production build of docs
89+
test:e2e:
90+
desc: runs Playwright
6891
cmds:
6992
- |
7093
docker run \
71-
--rm \
72-
-w /app/docs \
73-
-v $(pwd)/../docs:/app/docs \
74-
-v $(pwd)/../lib:/app/lib \
75-
$NODE_IMAGE /bin/bash -c "yarn build"
94+
--network="host" \
95+
-v $(pwd)/../docs:/app \
96+
-w /app \
97+
$PLAYWRIGHT_IMAGE \
98+
yarn test:e2e
7699
77-
build:
100+
test:
78101
cmds:
79-
- task lint
80-
- task test
81-
- task build:prepare
102+
- task test:unit
103+
- task test:e2e
82104

83105
deploy:pages:
84106
desc: deploy to CloudFlare pages
85107
cmds:
86108
- |
87-
docker run --user $(id -u):$(id -g) \
109+
docker run \
88110
--rm \
89111
-w /app \
90112
-v $(pwd)/../docs:/app \
@@ -96,4 +118,6 @@ tasks:
96118
desc: Lints, tests, builds and deploys to CloudFlare pages
97119
cmds:
98120
- task build
121+
- task up
122+
- task test
99123
- task deploy:pages

.dev/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
NODE_IMAGE="node:20"
2-
PLAYWRIGHT_IMAGE="mcr.microsoft.com/playwright:v1.43.1-jammy"
2+
PLAYWRIGHT_IMAGE="mcr.microsoft.com/playwright:v1.43.0-jammy"

.github/workflows/test-and-build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ jobs:
4747
lib/node_modules
4848
key: node-modules-${{ hashFiles('yarn.lock', 'docs/yarn.lock', 'lib/yarn.lock') }}
4949

50-
- name: Lint workspace
51-
run: task -d .ci lint
50+
- name: Build
51+
run: task -d .ci build
5252

53-
- name: Unit tests lib
54-
run: task -d .ci test
53+
- name: Runs server
54+
run: task -d .ci up
5555

56-
- name: Build docs
57-
run: task -d .ci build:prepare
56+
- name: Tests
57+
run: task -d .ci test
5858

5959
- name: 'Uploads ''frontend/dist'' artifact'
6060
uses: actions/upload-artifact@v4

docs/e2e.html

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,108 @@
66
<title>Document</title>
77

88
<style>
9-
.start,
10-
.end {
9+
html,
10+
body {
11+
margin: 0;
12+
padding: 0;
13+
height: 100%;
14+
}
15+
.top-100,
16+
.top-150,
17+
.top-200,
18+
.top-250,
19+
.top-300,
20+
.top-350,
21+
.top-400 {
1122
position: absolute;
12-
width: 10px;
23+
width: 100px;
1324
height: 5px;
14-
background: red;
25+
background: orange;
26+
z-index: 100;
1527
}
1628

17-
.foo {
29+
.top-100 {
30+
top: 100vh;
31+
}
32+
.top-150 {
33+
top: 150vh;
34+
}
35+
.top-200 {
36+
top: 200vh;
37+
}
38+
.top-250 {
39+
top: 250vh;
40+
}
41+
.top-300 {
42+
top: 300vh;
43+
}
44+
.top-350 {
45+
top: 350vh;
46+
}
47+
.top-400 {
48+
top: 400vh;
49+
}
50+
51+
.element {
1852
position: fixed;
19-
z-index: 100;
20-
left: 0;
21-
top: 0;
22-
width: 50px;
23-
height: 50px;
53+
width: 80px;
54+
height: 80px;
2455
background: yellow;
25-
26-
animation-name: foo;
2756
animation-duration: 10s;
2857
animation-play-state: paused;
2958
animation-fill-mode: forwards;
59+
animation-timing-function: linear;
3060
}
3161

32-
@keyframes foo {
33-
0% {
34-
translate: -30px 0 0;
35-
}
62+
.basic,
63+
.cancel-render-driver,
64+
.cancel-render-animation,
65+
.changes-bg-on-render {
66+
animation-name: basic;
67+
}
68+
69+
@keyframes basic {
3670
100% {
37-
translate: calc(100vw - 50px) 0 0;
71+
translate: calc(50vw - 50%) 0 0;
3872
}
3973
}
4074
</style>
4175
</head>
4276
<body>
43-
<div class="start" style="top: 100vh"></div>
44-
<div class="end" style="top: 300vh"></div>
45-
<div class="foo"></div>
77+
<div class="top-100"></div>
78+
<div class="top-150"></div>
79+
<div class="top-200"></div>
80+
<div class="top-250"></div>
81+
<div class="top-250"></div>
82+
<div class="top-300"></div>
83+
<div class="top-350"></div>
84+
<div class="top-400"></div>
85+
86+
<div class="element basic" style="left: 0; top: 0"></div>
87+
88+
<div
89+
class="element basic"
90+
style="left: 0; top: 100px; animation-timing-function: ease"
91+
></div>
92+
93+
<div
94+
class="element basic"
95+
style="left: 0; top: 200px; animation-delay: 1s"
96+
></div>
97+
98+
<div class="element cancel-render-driver" style="left: 0; top: 0"></div>
99+
100+
<div
101+
class="element cancel-render-animation"
102+
style="left: 0; top: 100px"
103+
></div>
104+
105+
<div class="element changes-bg-on-render" style="left: 0; top: 300px"></div>
46106

107+
<div
108+
style="position: fixed; right: 0; bottom: 0; z-index: 200"
109+
id="scroll-log"
110+
></div>
47111
<script type="module" src="/src/e2e.ts"></script>
48112
</body>
49113
</html>

docs/e2e/ScreenShot.test.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
import { expect, test } from '@playwright/test'
22

3-
test('Initial state', async ({ page }) => {
3+
test('0', async ({ page }) => {
44
await page.goto('/e2e.html')
5-
await expect(page).toHaveScreenshot()
5+
await expect(page).toHaveScreenshot({
6+
animations: 'allow',
7+
})
68
})
9+
10+
test('500', async ({ page }) => {
11+
await page.goto('/e2e.html')
12+
await page.evaluate(() => window.scrollTo(0, 500))
13+
await sleep()
14+
await expect(page).toHaveScreenshot({
15+
animations: 'allow',
16+
})
17+
})
18+
19+
test('1000', async ({ page }) => {
20+
await page.goto('/e2e.html')
21+
await page.evaluate(() => window.scrollTo(0, 1000))
22+
await sleep()
23+
await expect(page).toHaveScreenshot({
24+
animations: 'allow',
25+
})
26+
})
27+
28+
function sleep(time = 100) {
29+
return new Promise((res) => {
30+
setTimeout(res, time)
31+
})
32+
}
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)