Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add component testing setup #58

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/playwright-ct.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Playwright component tests
on:
pull_request:
types:
- opened
- edited
- synchronize
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright component tests
run: pnpm test:components
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
20 changes: 20 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unit Tests
on:
pull_request:
types:
- opened
- edited
- synchronize
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Run Unit tests
run: pnpm test:unit
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"preview": "vite preview",
"test:e2e:serve": "serve -s dist -l 8080",
"test:e2e": "npx playwright install && playwright test",
"test:unit": "vitest run",
"test:components": "npx playwright install && playwright test -c playwright-ct.config.ts",
"test:unit": "vitest run --reporter=verbose",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage"
},
Expand Down Expand Up @@ -47,7 +48,8 @@
"@graphql-codegen/typescript": "^4.0.6",
"@graphql-codegen/typescript-operations": "^4.2.0",
"@graphql-codegen/typescript-vue-apollo": "^4.1.1",
"@playwright/test": "^1.41.2",
"@playwright/experimental-ct-vue": "1.44.0-alpha-2024-04-05",
"@playwright/test": "1.44.0-alpha-2024-04-05",
"@rollup/plugin-graphql": "^2.0.4",
"@types/dompurify": "^3.0.5",
"@types/node": "^20.11.16",
Expand All @@ -56,6 +58,7 @@
"@vitejs/plugin-vue": "^5.0.3",
"@vitest/coverage-v8": "^1.2.2",
"@vitest/ui": "^1.2.2",
"@vue/compiler-dom": "^3.4.21",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^12.0.0",
"@vue/tsconfig": "^0.5.1",
Expand All @@ -74,7 +77,7 @@
"serve": "^14.2.1",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite": "^5.2.8",
"vitest": "^1.2.2",
"vue-tsc": "^1.8.27"
}
Expand Down
105 changes: 105 additions & 0 deletions playwright-ct.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { defineConfig, devices } from "@playwright/experimental-ct-vue";
import { fileURLToPath, URL } from "node:url";
import vue from "@vitejs/plugin-vue";
import graphql from "@rollup/plugin-graphql";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { PluginOption } from 'vite';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests/components",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",

ctPort: 3100,
ctViteConfig: {

plugins: [
nodePolyfills({
// Whether to polyfill specific globals.
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
}),
vue(),
graphql() as PluginOption,
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
"~": fileURLToPath(new URL("./src", import.meta.url)),
},
},
},
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
20 changes: 10 additions & 10 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
Expand All @@ -10,7 +10,7 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
testDir: "./tests/e2e",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand All @@ -20,31 +20,31 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
name: "webkit",
use: { ...devices["Desktop Safari"] },
},

/* Test against mobile viewports. */
Expand Down
12 changes: 12 additions & 0 deletions playwright/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>Testing Page</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./index.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions playwright/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// playwright/index.ts
import { beforeMount } from '@playwright/experimental-ct-vue/hooks';
import IconVue from "../src/components/ui/Icon.vue";
import { DefaultApolloClient } from "@vue/apollo-composable";
import "../src/style.css";
import { createI18n } from "vue-i18n";
import { messages } from "../src/localization";
import apolloClient from "../src/apolloClient";

beforeMount(async ({ app }) => {
app.provide(DefaultApolloClient, apolloClient);
const i18n = createI18n({
legacy: false,
locale: "en",
fallbackLocale: "en",
messages,
});
app.use(i18n);
app.component("Icon", IconVue);
});
Loading
Loading