Skip to content

Commit fc59604

Browse files
authored
feat(ci): run example tests against local workspace code (#2480)
* feat(ci): run example tests against local workspace code Examples and demos now resolve superdoc packages from the local workspace instead of npm, so breaking changes are caught before merge. - Add pnpm overrides for superdoc, @superdoc-dev/react, @superdoc-dev/superdoc-yjs-collaboration, and @superdoc-dev/sdk - Add demos to pnpm workspace - Rewrite ci-examples workflow: shared build job, pnpm workspace install, expanded path triggers (packages/superdoc, packages/react, etc.) - Increase smoke test timeouts for Nuxt SPA hydration and Laravel dual-process startup * fix(ci): include Playwright browser cache in workspace cache Playwright installs browsers to ~/.cache/ms-playwright/ which is outside the workspace directory. Include it in the cache so matrix jobs can find the chromium binary. * fix(ci): use build-then-serve for Laravel smoke test The concurrently approach (php artisan serve + vite dev) is unreliable in CI. Instead, build Vite assets first then serve with PHP only via a new `start` script. This is simpler and avoids the race condition between the two processes. * fix(ci): build collaboration package and trigger on layout-engine changes Address review feedback: - Build @superdoc-dev/superdoc-yjs-collaboration in the build job so the collaboration/superdoc-yjs smoke test can resolve its dist/ - Add packages/layout-engine/** to path triggers since superdoc bundles it and regressions there should run example tests
1 parent 8721614 commit fc59604

7 files changed

Lines changed: 6807 additions & 560 deletions

File tree

.github/workflows/ci-examples.yml

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,75 @@ on:
44
pull_request:
55
paths:
66
- 'examples/**'
7+
- 'packages/superdoc/**'
8+
- 'packages/react/**'
9+
- 'packages/super-editor/**'
10+
- 'packages/collaboration-yjs/**'
11+
- 'packages/sdk/**'
12+
- 'packages/layout-engine/**'
13+
- 'shared/**'
714
workflow_dispatch:
815

916
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- uses: pnpm/action-setup@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v6
26+
with:
27+
node-version: '20'
28+
cache: 'pnpm'
29+
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Build superdoc
34+
run: pnpm build:superdoc
35+
36+
- name: Build React wrapper
37+
run: pnpm --filter @superdoc-dev/react build
38+
39+
- name: Build collaboration package
40+
run: pnpm --filter @superdoc-dev/superdoc-yjs-collaboration build
41+
42+
- name: Install Playwright
43+
working-directory: examples/__tests__
44+
run: npx playwright install chromium
45+
46+
- name: Cache workspace
47+
uses: actions/cache/save@v4
48+
with:
49+
path: |
50+
.
51+
~/.cache/ms-playwright
52+
key: examples-workspace-${{ github.sha }}
53+
1054
getting-started:
55+
needs: build
1156
runs-on: ubuntu-latest
1257
strategy:
1358
fail-fast: false
1459
matrix:
1560
example: [react, vue, vanilla, cdn, angular, nuxt, laravel]
1661
steps:
17-
- uses: actions/checkout@v6
62+
- name: Restore workspace
63+
uses: actions/cache/restore@v4
64+
with:
65+
path: |
66+
.
67+
~/.cache/ms-playwright
68+
key: examples-workspace-${{ github.sha }}
1869

1970
- name: Setup PHP
2071
if: matrix.example == 'laravel'
2172
uses: shivammathur/setup-php@v2
2273
with:
2374
php-version: '8.2'
2475

25-
- name: Setup Node.js
26-
uses: actions/setup-node@v6
27-
with:
28-
node-version: '20'
29-
3076
- name: Install Composer dependencies
3177
if: matrix.example == 'laravel'
3278
working-directory: examples/getting-started/laravel
@@ -37,32 +83,25 @@ jobs:
3783
working-directory: examples/getting-started/laravel
3884
run: cp .env.example .env && php artisan key:generate
3985

40-
- name: Install example dependencies
41-
if: matrix.example != 'cdn'
42-
working-directory: examples/getting-started/${{ matrix.example }}
43-
run: npm install
44-
45-
- name: Install smoke test dependencies
46-
working-directory: examples/__tests__
47-
run: npm install && npx playwright install chromium
48-
4986
- name: Run smoke test
5087
working-directory: examples/__tests__
5188
run: EXAMPLE=${{ matrix.example }} npx playwright test
5289

5390
collaboration:
91+
needs: build
5492
runs-on: ubuntu-latest
5593
strategy:
5694
fail-fast: false
5795
matrix:
5896
example: [superdoc-yjs, hocuspocus, liveblocks]
5997
steps:
60-
- uses: actions/checkout@v6
61-
62-
- name: Setup Node.js
63-
uses: actions/setup-node@v6
98+
- name: Restore workspace
99+
uses: actions/cache/restore@v4
64100
with:
65-
node-version: '20'
101+
path: |
102+
.
103+
~/.cache/ms-playwright
104+
key: examples-workspace-${{ github.sha }}
66105

67106
- name: Create .env for cloud providers
68107
working-directory: examples/collaboration/${{ matrix.example }}
@@ -71,44 +110,46 @@ jobs:
71110
echo "VITE_LIVEBLOCKS_PUBLIC_KEY=${{ secrets.VITE_LIVEBLOCKS_PUBLIC_KEY }}" > .env
72111
fi
73112
74-
- name: Install example dependencies
75-
working-directory: examples/collaboration/${{ matrix.example }}
76-
run: npm install
77-
78-
- name: Install smoke test dependencies
79-
working-directory: examples/__tests__
80-
run: npm install && npx playwright install chromium
81-
82113
- name: Run smoke test
83114
working-directory: examples/__tests__
84115
run: EXAMPLE=collaboration/${{ matrix.example }} npx playwright test
85116

86117
features:
118+
needs: build
87119
runs-on: ubuntu-latest
88120
strategy:
89121
fail-fast: false
90122
matrix:
91123
example: [track-changes, ai-redlining, comments, custom-toolbar]
92124
steps:
93-
- uses: actions/checkout@v6
94-
95-
- name: Setup Node.js
96-
uses: actions/setup-node@v6
125+
- name: Restore workspace
126+
uses: actions/cache/restore@v4
97127
with:
98-
node-version: '20'
99-
100-
- name: Install example dependencies
101-
working-directory: examples/features/${{ matrix.example }}
102-
run: npm install
103-
104-
- name: Install smoke test dependencies
105-
working-directory: examples/__tests__
106-
run: npm install && npx playwright install chromium
128+
path: |
129+
.
130+
~/.cache/ms-playwright
131+
key: examples-workspace-${{ github.sha }}
107132

108133
- name: Run smoke test
109134
working-directory: examples/__tests__
110135
run: EXAMPLE=features/${{ matrix.example }} npx playwright test
111136

137+
headless:
138+
needs: build
139+
runs-on: ubuntu-latest
140+
steps:
141+
- name: Restore workspace
142+
uses: actions/cache/restore@v4
143+
with:
144+
path: |
145+
.
146+
~/.cache/ms-playwright
147+
key: examples-workspace-${{ github.sha }}
148+
149+
- name: Run headless tests
150+
working-directory: examples/headless/ai-redlining
151+
run: npx tsx src/index.test.ts
152+
112153
validate:
113154
if: always()
114155
needs: [getting-started, collaboration, features, headless]
@@ -119,21 +160,3 @@ jobs:
119160
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
120161
exit 1
121162
fi
122-
123-
headless:
124-
runs-on: ubuntu-latest
125-
steps:
126-
- uses: actions/checkout@v6
127-
128-
- name: Setup Node.js
129-
uses: actions/setup-node@v6
130-
with:
131-
node-version: '20'
132-
133-
- name: Install dependencies
134-
working-directory: examples/headless/ai-redlining
135-
run: npm install
136-
137-
- name: Run headless tests
138-
working-directory: examples/headless/ai-redlining
139-
run: npx tsx src/index.test.ts

examples/__tests__/playwright.config.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ const examplePath = isGettingStarted
1616
? `../getting-started/${example}`
1717
: `../${example}`;
1818

19-
// Collaboration examples that use concurrently (server + client).
19+
// Examples that use concurrently (server + client).
2020
// These run `npm run dev` which starts both processes — don't append --port.
2121
const useConcurrently = [
2222
'collaboration/hocuspocus',
2323
'collaboration/superdoc-yjs',
24-
'laravel',
2524
];
2625

2726
// Port mapping — must match vite.config or server defaults
@@ -39,13 +38,19 @@ const exampleAbsPath = resolve(__dirname, examplePath);
3938
const hasLocalNodeModules = existsSync(resolve(exampleAbsPath, 'node_modules', '.bin'));
4039
const run = hasLocalNodeModules ? `npm run --prefix ${examplePath}` : `pnpm --dir ${examplePath} run`;
4140

41+
// Laravel: build Vite assets first, then serve with PHP only (via `start` script).
42+
// The concurrently approach (php + vite dev) is unreliable in CI.
43+
const isLaravel = example === 'laravel';
44+
4245
// Start command
4346
const isCdn = example === 'cdn';
4447
const command = isCdn
4548
? `npx serve ${examplePath} -l ${port}`
46-
: useConcurrently.includes(example)
47-
? `${run} dev`
48-
: `${run} dev -- --port ${port}`;
49+
: isLaravel
50+
? `${run} start`
51+
: useConcurrently.includes(example)
52+
? `${run} dev`
53+
: `${run} dev -- --port ${port}`;
4954

5055
export default defineConfig({
5156
testDir: '.',
@@ -54,7 +59,7 @@ export default defineConfig({
5459
webServer: {
5560
command,
5661
url: `http://localhost:${port}`,
57-
timeout: 60_000,
62+
timeout: 120_000,
5863
reuseExistingServer: !process.env.CI,
5964
},
6065
use: {

examples/__tests__/smoke.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ test('example loads without errors', async ({ page }) => {
1717
await page.route('**/ingest.superdoc.dev/**', (route) => route.abort());
1818

1919
await page.goto('/');
20-
await expect(page.locator('body')).toBeVisible();
20+
// SPA frameworks (e.g. Nuxt with ssr:false) hide the body during hydration;
21+
// give them enough time to mount before checking visibility.
22+
await expect(page.locator('body')).toBeVisible({ timeout: 30_000 });
2123

2224
// Give the app a moment to initialize (SuperDoc is async)
2325
await page.waitForTimeout(2000);

examples/getting-started/laravel/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "module",
55
"scripts": {
66
"build": "vite build",
7-
"dev": "concurrently \"php artisan serve --host=0.0.0.0 --port=8000\" \"vite\""
7+
"dev": "concurrently \"php artisan serve --host=0.0.0.0 --port=8000\" \"vite\"",
8+
"start": "vite build && php artisan serve --host=127.0.0.1 --port=8000"
89
},
910
"dependencies": {
1011
"concurrently": "^9.0.0",

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@
134134
"@vue/runtime-dom": "3.5.25",
135135
"@vue/server-renderer": "3.5.25",
136136
"@vue/shared": "3.5.25",
137-
"vite": "npm:rolldown-vite@7.3.1"
137+
"vite": "npm:rolldown-vite@7.3.1",
138+
"superdoc": "workspace:*",
139+
"@superdoc-dev/react": "workspace:*",
140+
"@superdoc-dev/superdoc-yjs-collaboration": "workspace:*",
141+
"@superdoc-dev/sdk": "workspace:*"
138142
},
139143
"ignoredBuiltDependencies": [
140144
"@parcel/watcher",

0 commit comments

Comments
 (0)