Skip to content

Commit 7b7478c

Browse files
authored
feat: atoms e2e tests (#22926)
* feat: atoms example app e2e * chore: build atoms when e2e examples app * docs: readme * fix: add env variable * fix: env var * chore: playwright at monorepo version * fix: workflow * chore: increase timeout to have time to build atoms * increase timeout for e2e * bump e2e instance * go back to 4cpu
1 parent ebeb008 commit 7b7478c

File tree

7 files changed

+153
-3
lines changed

7 files changed

+153
-3
lines changed

.github/workflows/atoms-e2e.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Atoms E2E Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'packages/platform/atoms/**'
9+
- 'packages/platform/examples/base/**'
10+
- 'apps/api/v2/**'
11+
- '.github/workflows/atoms-e2e.yml'
12+
13+
permissions:
14+
actions: write
15+
contents: read
16+
17+
env:
18+
NODE_OPTIONS: --max-old-space-size=8096
19+
ATOMS_E2E_OAUTH_CLIENT_ID: ${{ secrets.ATOMS_E2E_OAUTH_CLIENT_ID }}
20+
ATOMS_E2E_OAUTH_CLIENT_SECRET: ${{ secrets.ATOMS_E2E_OAUTH_CLIENT_SECRET }}
21+
ATOMS_E2E_API_URL: ${{ secrets.ATOMS_E2E_API_URL }}
22+
ATOMS_E2E_ORG_ID: ${{ secrets.ATOMS_E2E_ORG_ID }}
23+
ATOMS_E2E_OAUTH_CLIENT_ID_BOOKER_EMBED: ${{ secrets.ATOMS_E2E_OAUTH_CLIENT_ID_BOOKER_EMBED }}
24+
DATABASE_DIRECT_URL: ${{ secrets.CI_DATABASE_URL }}
25+
DATABASE_URL: ${{ secrets.CI_DATABASE_URL }}
26+
27+
jobs:
28+
atoms-e2e:
29+
timeout-minutes: 15
30+
name: Atoms E2E Tests
31+
runs-on: buildjet-4vcpu-ubuntu-2204
32+
steps:
33+
- uses: docker/login-action@v3
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_TOKEN }}
37+
- uses: actions/checkout@v4
38+
- uses: ./.github/actions/dangerous-git-checkout
39+
- uses: ./.github/actions/yarn-install
40+
- uses: ./.github/actions/yarn-playwright-install
41+
- name: Run Atoms E2E Tests
42+
working-directory: packages/platform/examples/base
43+
run: yarn test:e2e
44+
- name: Upload Test Results
45+
uses: actions/upload-artifact@v4
46+
if: always()
47+
with:
48+
name: atoms-e2e-test-results
49+
path: test-results
50+
retention-days: 7
51+
- name: Upload Playwright Report
52+
uses: actions/upload-artifact@v4
53+
if: always()
54+
with:
55+
name: atoms-e2e-playwright-report
56+
path: playwright-report
57+
retention-days: 7

packages/platform/atoms/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@ changesets will publish atoms to npm only if the `"version"` in the atoms `packa
3636

3737
The following 2 articles teach how to write good change summaries for each PR when it deserves to end up in CHANGELOG.md
3838
- https://keepachangelog.com/en/1.0.0/
39-
- https://docs.gitlab.com/development/changelog/
39+
- https://docs.gitlab.com/development/changelog/
40+
41+
### Testing
42+
Atoms are tested in CI using e2e tests within the example platform app. To run them locally:
43+
1. Go to "packages/platform/atoms" and run `yarn dev-on` and then `yarn build` - this will create local build of atoms.
44+
2. Setup environment variables in "packages/platform/examples/base/.env" file. You will need your own platform oAuth client to populate NEXT_PUBLIC_X_CAL_ID (oAuth id), X_CAL_SECRET_KEY (oAuth secret), VITE_BOOKER_EMBED_OAUTH_CLIENT_ID (oAuth id) and ORGANIZATION_ID (organization id to which oAuth client belongs) - all of these are available in the platform settings dashboard after creating the oAuth client.
45+
```
46+
NEXT_PUBLIC_X_CAL_ID=""
47+
X_CAL_SECRET_KEY=""
48+
NEXT_PUBLIC_CALCOM_API_URL="https://api.cal.com/v2"
49+
VITE_BOOKER_EMBED_OAUTH_CLIENT_ID=""
50+
VITE_BOOKER_EMBED_API_URL="https://api.cal.com/v2"
51+
ORGANIZATION_ID=""
52+
```
53+
3. Go to "packages/platform/examples/base" and run `yarn dev:e2e` - this will start the example platform app and run e2e tests by using locally built atoms. Because it is not running within CI it will open a browser and run tests.
54+
55+

packages/platform/examples/base/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ yarn-error.log*
3535
*.tsbuildinfo
3636
next-env.d.ts
3737
.yarn
38-
dev.db
38+
dev.db
39+
40+
# playwright
41+
test-results
42+
playwright-report

packages/platform/examples/base/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6+
"dev:e2e": "PORT=4322 next dev",
67
"dev": "PORT=4321 next dev",
78
"build": "next build",
89
"start": "next start",
9-
"lint": "next lint"
10+
"lint": "next lint",
11+
"test:e2e": "playwright test",
12+
"test:e2e:ui": "playwright test --ui"
1013
},
1114
"dependencies": {
1215
"@calcom/atoms": "*",
@@ -18,6 +21,7 @@
1821
"react-select": "^5.8.0"
1922
},
2023
"devDependencies": {
24+
"@playwright/test": "^1.45.3",
2125
"@types/node": "^20.3.1",
2226
"@types/react": "^18",
2327
"@types/react-dom": "^18",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const DEFAULT_EXPECT_TIMEOUT = process.env.CI ? 30000 : 120000;
4+
const DEFAULT_TEST_TIMEOUT = process.env.CI ? 60000 : 240000;
5+
6+
const headless = !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS;
7+
8+
export default defineConfig({
9+
forbidOnly: !!process.env.CI,
10+
retries: process.env.CI ? 2 : 0,
11+
workers: process.env.CI ? 1 : undefined,
12+
timeout: DEFAULT_TEST_TIMEOUT,
13+
fullyParallel: true,
14+
reporter: [
15+
['list'],
16+
['html', { outputFolder: './test-results/reports/playwright-html-report', open: 'never' }],
17+
],
18+
outputDir: './test-results/results',
19+
use: {
20+
baseURL: 'http://localhost:4322',
21+
locale: 'en-US',
22+
trace: 'retain-on-failure',
23+
headless,
24+
},
25+
projects: [
26+
{
27+
name: '@calcom/base',
28+
testDir: './tests',
29+
testMatch: /.*\.e2e\.tsx?/,
30+
expect: {
31+
timeout: DEFAULT_EXPECT_TIMEOUT,
32+
},
33+
use: {
34+
...devices['Desktop Chrome'],
35+
locale: 'en-US',
36+
},
37+
},
38+
],
39+
webServer: {
40+
command: process.env.CI
41+
? `yarn workspace @calcom/atoms dev-on && yarn workspace @calcom/atoms build && rm -f prisma/dev.db && yarn prisma db push && NEXT_PUBLIC_IS_E2E=1 NODE_ENV=test NEXT_PUBLIC_X_CAL_ID="${process.env.ATOMS_E2E_OAUTH_CLIENT_ID}" X_CAL_SECRET_KEY="${process.env.ATOMS_E2E_OAUTH_CLIENT_SECRET}" NEXT_PUBLIC_CALCOM_API_URL="${process.env.ATOMS_E2E_API_URL}" VITE_BOOKER_EMBED_OAUTH_CLIENT_ID="${process.env.ATOMS_E2E_OAUTH_CLIENT_ID_BOOKER_EMBED}" VITE_BOOKER_EMBED_API_URL="${process.env.ATOMS_E2E_API_URL}" ORGANIZATION_ID=${process.env.ATOMS_E2E_ORG_ID} yarn dev:e2e`
42+
: `rm -f prisma/dev.db && yarn prisma db push && yarn dev:e2e`,
43+
url: 'http://localhost:4322',
44+
timeout: 600_000,
45+
reuseExistingServer: !process.env.CI,
46+
},
47+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('create event type using CreateEventTypeAtom', async ({ page }) => {
4+
await page.goto('/');
5+
6+
await page.goto('/event-types');
7+
8+
await expect(page).toHaveURL('/event-types');
9+
10+
await expect(page.locator('body')).toBeVisible();
11+
12+
await page.fill('[data-testid="event-type-quick-chat"]', 'e2e event');
13+
14+
await page.fill('textarea[placeholder="A quick video meeting."]', 'This is an e2e test event description');
15+
16+
await page.waitForSelector('button[type="submit"]:has-text("Continue")', { state: 'visible' });
17+
await page.click('button[type="submit"]:has-text("Continue")');
18+
19+
await expect(page.locator('h1:has-text("E2e Event")')).toBeVisible();
20+
await expect(page.locator('p:has-text("/e2e-event")')).toBeVisible();
21+
});

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,7 @@ __metadata:
27302730
resolution: "@calcom/base@workspace:packages/platform/examples/base"
27312731
dependencies:
27322732
"@calcom/atoms": "*"
2733+
"@playwright/test": ^1.45.3
27332734
"@prisma/client": 5.4.2
27342735
"@types/node": ^20.3.1
27352736
"@types/react": ^18

0 commit comments

Comments
 (0)