Skip to content

Commit 7ad871d

Browse files
committed
initial setup of tests
1 parent 0d573f0 commit 7ad871d

File tree

9 files changed

+173
-14
lines changed

9 files changed

+173
-14
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ concurrency:
1717
jobs:
1818
build:
1919
runs-on: ubuntu-latest
20-
2120
steps:
2221
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
2322
- uses: pnpm/action-setup@v4
@@ -28,3 +27,24 @@ jobs:
2827
- run: pnpm i
2928
- run: pnpm run lint
3029
- run: pnpm run build
30+
test:
31+
timeout-minutes: 60
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
35+
- uses: pnpm/action-setup@v4
36+
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
37+
with:
38+
node-version-file: '.node-version'
39+
cache: 'pnpm'
40+
- run: pnpm i
41+
- name: Install Playwright Browsers
42+
run: pnpm exec playwright install chromium --with-deps
43+
- name: Run Playwright tests
44+
run: pnpm run test
45+
- uses: actions/upload-artifact@v4
46+
if: ${{ !cancelled() }}
47+
with:
48+
name: playwright-report
49+
path: playwright-report/
50+
retention-days: 10

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ node_modules
33
dist
44
dist-ssr
55
*.local
6-
!.vscode
6+
!.vscode
7+
8+
# Playwright
9+
/test-results/
10+
/playwright-report/
11+
/blob-report/
12+
/playwright/.cache/

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"description": "A configurable pomodoro-like timer",
66
"type": "module",
77
"scripts": {
8-
"dev": "vite",
8+
"dev": "vite --port 8888",
99
"build": "vue-tsc --noEmit && vite build",
1010
"lint": "eslint 'src/**/*.*'",
11-
"serve": "vite preview"
11+
"serve": "vite preview",
12+
"dev:test": "vite dev --port 8888 --mode=test",
13+
"test": ""
1214
},
1315
"packageManager": "[email protected]",
1416
"engines": {
@@ -24,6 +26,7 @@
2426
},
2527
"devDependencies": {
2628
"@eslint/js": "9.20.0",
29+
"@playwright/test": "^1.51.0",
2730
"@tailwindcss/vite": "4.0.9",
2831
"@types/node": "22.13.7",
2932
"@vitejs/plugin-vue": "5.2.1",

playwright.config.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env.CI,
20+
/* Retry on CI only */
21+
retries: process.env.CI ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env.CI ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: 'html',
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
baseURL: 'http://localhost:8888',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: 'on-first-retry',
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: 'chromium',
39+
use: { ...devices['Desktop Chrome'] },
40+
},
41+
42+
{
43+
name: 'Mobile Chrome',
44+
use: { ...devices['Pixel 5'] },
45+
},
46+
],
47+
48+
webServer: {
49+
command: 'pnpm run dev:test',
50+
url: 'http://localhost:8888',
51+
reuseExistingServer: !process.env.CI,
52+
},
53+
});

pnpm-lock.yaml

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

src/components/BaseTimer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const label = computed(() => {
2525
if (mins === 0) {
2626
return `${toSpacedString(type)}: less than 1 minute left`;
2727
}
28-
return `${toSpacedString(type)}: ${mins + 1} minutes left`;
28+
return `${toSpacedString(type)}: ${mins + (secs === 0 ? 0 : 1)} minutes left`;
2929
});
3030
3131
const classes = computed(() => getIntervalTypeColor(type as IntervalType));

src/components/TheCycle.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<script setup lang="ts">
22
import IntervalSquare from '@/components/IntervalSquare.vue';
33
import { useCycle } from '@/stores/cycle';
4+
import { useId } from 'vue';
45
56
const cycle = useCycle();
7+
const id = useId();
68
</script>
79
<template>
810
<div>
9-
<h2 class="sr-only">Intervals</h2>
10-
<ul class="flex flex-wrap items-center justify-center gap-1">
11+
<h2 :id="id + '-cycle'" aria-hidden="true">Intervals</h2>
12+
<ul
13+
class="flex flex-wrap items-center justify-center gap-1"
14+
:aria-labelledby="id + '-cycle'"
15+
>
1116
<IntervalSquare
1217
v-for="(interval, i) in cycle.intervals"
1318
:key="interval.id"

src/stores/cycle.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import { Interval, IntervalType } from '@/types';
44
import { useStorage } from '@vueuse/core';
55
import { uniqId } from '@/utils';
66

7+
const initialIntervals = () => [
8+
{
9+
type: IntervalType.Work,
10+
duration: 45 * 60 * 1000,
11+
id: uniqId([]),
12+
},
13+
];
14+
715
export const useCycle = defineStore('cycle', () => {
8-
const intervals = useStorage<Interval[]>('intervals', [
9-
{
10-
type: IntervalType.Work,
11-
duration: 45 * 60 * 1000,
12-
id: uniqId([]),
13-
},
14-
]);
16+
const intervals =
17+
import.meta.env.MODE !== 'test'
18+
? useStorage<Interval[]>('intervals', initialIntervals())
19+
: ref<Interval[]>(initialIntervals());
1520

1621
const countdowns = ref<number[]>([]);
1722
const current = ref(0);

tests/timer.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('initial state', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/');
6+
});
7+
test('default timer', async ({ page }) => {
8+
await expect(page.getByRole('timer')).toContainText('45:00');
9+
});
10+
test('default timer - accessible name', async ({ page }) => {
11+
await expect(page.getByRole('timer')).toContainText('45 minutes left');
12+
});
13+
test('cycle list', async ({ page }) => {
14+
const list = page.getByRole('list', { name: 'Intervals' });
15+
await expect(list.getByRole('listitem')).toHaveCount(1);
16+
await expect(list.getByRole('listitem')).toContainText('W');
17+
await expect(list.getByRole('listitem')).toContainText('45:00');
18+
});
19+
20+
test('controls', async ({ page }) => {
21+
const controls = page.getByRole('group', { name: 'Timer controls' });
22+
await expect(controls.getByRole('button', { name: 'Play' })).toBeVisible();
23+
await expect(controls.getByRole('button', { name: 'Skip' })).toBeVisible();
24+
await expect(controls.getByRole('button', { name: 'Reset' })).toBeVisible();
25+
await expect(
26+
controls.getByRole('button', { name: 'Settings' }),
27+
).toBeVisible();
28+
});
29+
});

0 commit comments

Comments
 (0)