Skip to content

Commit 0bc95bd

Browse files
sarahsgaactions-user
authored andcommitted
chore: Include Nextjs versions 15/16 in loader tests (#2310)
* chore: Include Nextjs versions 15/16 in loader tests * fix: add missing pnpm-lock.yaml files * docs: document pnpm usage * fix: update package.json to use react-18 * feedback * test: at least one test using react 17 * test: also test with React 19 + refactor * fix: React 17 should only be tested with loader v1 * chore: use latest react version for app router template Also remove testing of react-quill package for latest react version * fix: an accidental change * docs: update loader-tests/README.md to include e2e tests GitOrigin-RevId: 6a5f30608b1c6d079b9919a96ead9409d1650e1b
1 parent 0f0470f commit 0bc95bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+15923
-11318
lines changed

platform/loader-tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__diff_output__/
22
screenshots/
33
videos/
4+
pnpm-workspace.yaml

platform/loader-tests/README

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

platform/loader-tests/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# loader-tests
2+
3+
End-to-end Playwright tests for Plasmic SDK packages. Tests verify that Plasmic projects render correctly when integrated into real framework apps (Next.js, Gatsby, CRA).
4+
5+
> **Note:** The `cypress/` directory and Jest-based specs in `src/nextjs/*.spec.ts` are **obsolete** and no longer maintained or run by CI. All active tests use Playwright.
6+
7+
## How it works
8+
9+
There are two kinds of Playwright tests:
10+
11+
### Loader tests (`src/playwright-tests/nextjs/`, `src/playwright-tests/gatsby/`, etc.)
12+
13+
Each test uploads a JSON bundle from `data/` to the local Plasmic server, copies a framework template (e.g. `src/nextjs/template-pages/`) into a temp directory, installs deps with `pnpm install --frozen-lockfile`, builds the app, starts it on a random port, then runs Playwright assertions against it. Tests run against multiple loader/framework version combinations defined in `src/env.ts`.
14+
15+
### E2E codegen/loader tests (`src/playwright-tests/e2e/`)
16+
17+
These tests exercise `create-plasmic-app` end-to-end. Instead of copying a template, each test runs `npx create-plasmic-app` to scaffold a real project (Next.js, React, or TanStack Start), builds it, starts a server, and runs Playwright assertions. Tests cover both codegen and loader schemes. On CI, all changed packages are published to verdaccio first so the scaffolded projects pick up the latest local builds.
18+
19+
### Adding a new loader test
20+
21+
Export a Plasmic project bundle as JSON into `data/`. Then write a Playwright spec in `src/playwright-tests/` by copying boilerplate from a similar test.
22+
23+
### Adding a new e2e test
24+
25+
This should rarely be needed.
26+
Add a new spec file in `src/playwright-tests/e2e/` using `defineE2eTests()` from `e2e-test-utils.ts`. Specify the platform, test cases (scheme, typescript, appDir), and assertion callback. See `e2e-nextjs-codegen.spec.ts` for an example.
27+
28+
Note: These tests were split by platform into multiple files to enable parallel execution.
29+
30+
## pnpm in templates
31+
32+
The framework templates use pnpm with `--frozen-lockfile`. If you update a template's `package.json`, you need to regenerate the lockfile:
33+
34+
1. Create a `pnpm-workspace.yaml` in the template directory if it doesn't already exist:
35+
```bash
36+
echo 'packages:\n - "."' > src/nextjs/template-pages/pnpm-workspace.yaml
37+
```
38+
This ensures that the `pnpm install` in the next step alters the template's own lock file.
39+
The `pnpm-workspace.yaml` file is gitignored and won't be committed.
40+
2. Run `pnpm install` in the template directory to regenerate `pnpm-lock.yaml`.
41+
42+
## Running tests
43+
44+
```bash
45+
# All tests
46+
yarn test
47+
48+
# Playwright only
49+
yarn test-playwright
50+
51+
# Specific test file
52+
yarn test-playwright src/playwright-tests/nextjs/antd5/tabs.spec.ts
53+
54+
# Specific folder
55+
yarn test-playwright src/playwright-tests/nextjs/antd5/
56+
57+
# Interactive UI mode
58+
yarn playwright-ui
59+
60+
# To run E2e tests (requires verdaccio with local packages published)
61+
yarn local-publish
62+
yarn run local:playwright-ui
63+
```
64+
65+
On failure, traces and videos are saved to `test-results/`. The HTML report opens automatically, or run `npx playwright show-report`. Each test logs its temp directory path (`tmpdir /tmp/...`) which you can inspect to debug build issues (comment out teardown to keep it around).

platform/loader-tests/src/cra/cra-setup.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export async function setupCra(opts: {
2626
bundleFile: string;
2727
projectName: string;
2828
template?: string;
29+
reactVersion?: string;
30+
loaderReactVersion?: string;
2931
}): Promise<CraContext> {
3032
const { bundleFile, projectName } = opts;
3133
const { projectId, projectToken } = await uploadProject(
@@ -39,7 +41,12 @@ export async function setupCra(opts: {
3941
console.log("tmpdir", tmpdir);
4042
const { server, host } = await setupCraServer(
4143
{ projectId, projectToken },
42-
{ type: "cra", template: opts.template },
44+
{
45+
type: "cra",
46+
template: opts.template,
47+
reactVersion: opts.reactVersion,
48+
loaderReactVersion: opts.loaderReactVersion,
49+
},
4350
tmpdir
4451
);
4552

@@ -80,8 +87,21 @@ export async function setupCraServer(
8087
`pnpm install --frozen-lockfile ${pnpmCiFlags}`,
8188
pnpmOptions
8289
);
90+
91+
const updatePackages = [
92+
`@plasmicapp/loader-react@${env.loaderReactVersion ?? "latest"}`,
93+
];
94+
if (env.reactVersion) {
95+
updatePackages.push(
96+
`react@${env.reactVersion}`,
97+
`react-dom@${env.reactVersion}`,
98+
`@types/react@${env.reactVersion}`,
99+
`@types/react-dom@${env.reactVersion}`
100+
);
101+
}
102+
83103
await runCommand(
84-
`pnpm update @plasmicapp/loader-react --latest ${pnpmCiFlags}`,
104+
`pnpm update ${updatePackages.join(" ")} ${pnpmCiFlags}`,
85105
pnpmOptions
86106
);
87107

platform/loader-tests/src/env.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,31 @@ export function getEnvVar(variable: keyof typeof DEFAULT_ENV): string {
1919
}
2020

2121
export const LOADER_NEXTJS_TEMPLATES = [
22-
{ template: "template-pages", nextVersion: "^12" },
23-
{ template: "template-app", nextVersion: "15.5.3" },
22+
{ loaderVersion: "1", template: "template-pages", nextVersion: "12" },
23+
{
24+
loaderVersion: "1",
25+
template: "template-app",
26+
reactVersion: "latest",
27+
nextVersion: "15.5.3",
28+
},
2429
];
2530

2631
export const LOADER_NEXTJS_VERSIONS = [
27-
{ loaderVersion: "latest", nextVersion: "latest" },
32+
{ loaderVersion: "latest", reactVersion: "latest", nextVersion: "latest" },
2833
// Before PlasmicLinkProvider / usePlasmicLink is added
29-
{ loaderVersion: "1.0.287", nextVersion: "^12" },
34+
{ loaderVersion: "1.0.287", reactVersion: "18", nextVersion: "12" },
35+
];
36+
37+
export const LOADER_REACT_VERSIONS = [
38+
{ reactVersion: "17", loaderReactVersion: "latest" },
39+
{ reactVersion: "18", loaderReactVersion: "latest" },
3040
];
3141

3242
export const LOADER_NEXTJS_VERSIONS_EXHAUSTIVE = [
3343
...LOADER_NEXTJS_VERSIONS,
34-
{ loaderVersion: "^1", nextVersion: "^13" },
35-
{ loaderVersion: "^1", nextVersion: "^14" },
44+
{ loaderVersion: "latest", reactVersion: "18", nextVersion: "13" },
45+
{ loaderVersion: "latest", reactVersion: "18", nextVersion: "14" },
46+
{ loaderVersion: "latest", reactVersion: "18", nextVersion: "15" },
3647
];
3748

3849
function maybeSwapWithDockerLocalhost(value: string | undefined) {

platform/loader-tests/src/nextjs/custom-auth/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "template",
33
"version": "0.1.0",
44
"private": true,
5+
"packageManager": "pnpm@10.28.2",
56
"scripts": {
67
"dev": "next dev",
78
"build": "next build",

0 commit comments

Comments
 (0)