Skip to content

Commit 57b7439

Browse files
committed
Move tests to a package and simplify docker setup
1 parent 45aec06 commit 57b7439

16 files changed

Lines changed: 220 additions & 178 deletions

File tree

.dockerignore

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Setup Playwright
2+
description: Setup Playwright for the runner
3+
4+
runs:
5+
using: 'composite'
6+
7+
steps:
8+
- name: Cache Playwright binaries
9+
uses: actions/cache@v5
10+
id: cache-playwright
11+
with:
12+
path: |
13+
~/.cache/ms-playwright
14+
# This is the version of Playwright that we are using, if you are willing to upgrade, you should update this.
15+
key: playwright-${{ runner.arch }}-${{ runner.os }}-1.52.2
16+
17+
- name: Install Playwright
18+
shell: bash
19+
if: steps.cache-playwright.outputs.cache-hit != 'true'
20+
working-directory: .
21+
run: npx playwright install --with-deps

.github/workflows/cd.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,24 @@ jobs:
3131
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
3232
- run: yarn
3333
if: steps.yarn-cache.outputs.cache-hit != 'true'
34-
- run: yarn run ci
34+
- name: Build, lint and test
35+
id: build-lint-test
36+
run: yarn run ci
37+
38+
- name: Setup Playwright
39+
uses: ./.github/actions/setup-playwright
40+
41+
- name: Visual regression
42+
id: visual-regression
43+
if: steps.build-lint-test.outputs.success == 'true'
44+
run: yarn turbo run visual-regression --cache-dir=".turbo" --concurrency=1
45+
46+
- uses: actions/upload-artifact@v7
47+
if: failure()
48+
with:
49+
name: playwright-visual-results
50+
path: '**/test-results'
51+
3552
- run: yarn run docs
3653
- uses: actions/upload-artifact@v7
3754
with:

.github/workflows/ci-pr.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,29 @@ jobs:
4141
turbo-${{ runner.os }}-
4242
- run: yarn
4343
if: steps.yarn-cache.outputs.cache-hit != 'true'
44-
id: 'yarn-ci'
45-
- run: yarn run ci
44+
45+
- name: Setup Playwright
46+
uses: ./.github/actions/setup-playwright
47+
48+
- name: Build, lint and test
49+
id: build-lint-test
50+
run: yarn run ci
51+
52+
- name: Visual regression
53+
id: visual-regression
54+
if: steps.build-lint-test.outputs.success == 'true'
55+
run: yarn turbo run visual-regression --cache-dir=".turbo" --concurrency=1
56+
57+
- uses: actions/upload-artifact@v7
58+
if: failure()
59+
with:
60+
name: 'playwright-visual-results-${{ github.event.number }}'
61+
path: '**/test-results'
62+
4663
- uses: actions/upload-artifact@v7
4764
with:
4865
name: 'storybooks-${{ github.event.number }}'
4966
path: |
5067
packages/fuselage/storybook-static
5168
packages/onboarding-ui/storybook-static
5269
packages/layout/storybook-static
53-
54-
- uses: actions/upload-artifact@v7
55-
if: steps.yarn-ci.outcome != 'success'
56-
with:
57-
name: 'playwright-visual-results-${{ github.event.number }}'
58-
path: packages/fuselage/test-results

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ node_modules/
1717
**/bundle-report.html
1818
.env
1919
**/playwright-report
20+
**/test-results

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"changeset": "changeset",
1212
".ci-build-lint": "yarn turbo run build lint build-storybook --cache-dir=\".turbo\"",
1313
".ci-test": "yarn turbo run test",
14-
".ci-visual-regression": "yarn turbo run visual-regression-ci",
15-
"ci": "yarn turbo run build lint test build-storybook visual-regression --cache-dir=\".turbo\"",
14+
"ci": "yarn turbo run build lint test build-storybook --cache-dir=\".turbo\"",
1615
"clean": "yarn workspaces foreach -vA run clean",
1716
"docs": "yarn turbo run docs",
1817
"postinstall": "husky install",

packages/fuselage/Dockerfile.playwright

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/fuselage/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
"/index.js"
2424
],
2525
"scripts": {
26-
"visual-regression-ci": "npx concurrently -k -s first -n \"SB,TEST\" \"npx http-server storybook-static -s -p 6006\" \"npx wait-on tcp:127.0.0.1:6006 && yarn playwright test\"",
27-
"visual-regression-update": "npx concurrently -k -s first -n \"SB,TEST\" \"yarn storybook --ci\" \"npx wait-on tcp:127.0.0.1:6006 && ./scripts/run-playwright-docker.sh --update-snapshots\"",
28-
"visual-regression": "npx concurrently -k -s first -n \"SB,TEST\" \"yarn storybook --ci\" \"npx wait-on tcp:127.0.0.1:6006 && ./scripts/run-playwright-docker.sh\"",
26+
"visual-regression": "visual-regression",
27+
"visual-regression-update": "visual-regression --update-snapshots",
2928
"start": "webpack --watch --mode development",
3029
"storybook": "storybook dev -p 6006 --no-version-updates",
3130
"build": "run-s .:build:clean .:build:dev .:build:prod",
@@ -55,10 +54,10 @@
5554
"@babel/plugin-transform-runtime": "~7.28.5",
5655
"@babel/preset-env": "~7.28.6",
5756
"@babel/preset-react": "~7.28.5",
58-
"@playwright/test": "~1.58.1",
5957
"@rocket.chat/fuselage-hooks": "workspace:~",
6058
"@rocket.chat/icons": "workspace:~",
6159
"@rocket.chat/storybook-dark-mode": "workspace:~",
60+
"@rocket.chat/visual-regression": "workspace:~",
6261
"@storybook/addon-a11y": "~9.1.17",
6362
"@storybook/addon-docs": "~9.1.17",
6463
"@storybook/addon-links": "~9.1.17",

packages/fuselage/scripts/run-playwright-docker.sh

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
import { execSync } from 'child_process';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7+
const toolRoot = path.resolve(__dirname, '..');
8+
const packageDir = process.cwd();
9+
10+
const args = process.argv.slice(2);
11+
const updateSnapshots = args.includes('--update-snapshots')
12+
? '--update-snapshots'
13+
: '';
14+
const buildDockerImage = args.includes('--build') ? '--build' : '';
15+
16+
if (process.env.CI) {
17+
execSync(
18+
`npx -y concurrently -k -s first -n "SB,TEST" "npx -y http-server storybook-static -s -p 6006" "npx -y wait-on tcp:127.0.0.1:6006 && PACKAGE_DIR=${packageDir} yarn workspace @rocket.chat/visual-regression playwright test --config=${toolRoot}/playwright.config.ts ${updateSnapshots}"`,
19+
{ stdio: 'inherit', cwd: packageDir },
20+
{
21+
env: {
22+
...process.env,
23+
PACKAGE_DIR: `${packageDir}`,
24+
},
25+
},
26+
);
27+
} else {
28+
execSync(
29+
`npx -y concurrently -k -s first -n "SB,TEST" "yarn storybook -p 6006 --ci --host 0.0.0.0" "${toolRoot}/scripts/run-playwright-docker.sh ${updateSnapshots} ${buildDockerImage}"`,
30+
{
31+
stdio: 'inherit',
32+
cwd: packageDir,
33+
env: { ...process.env, PACKAGE_DIR: packageDir },
34+
},
35+
);
36+
}

0 commit comments

Comments
 (0)