Skip to content

Commit cfa4e86

Browse files
author
aehnh
committed
build playground on playwright global setup instead of building before every test group
1 parent 04238cb commit cfa4e86

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

packages/tests-e2e/src/complete/utils/playground.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,27 @@ function getPlaygroundDir(): string {
2121
}
2222
}
2323

24-
function getPlaygroundArgs(port: number): string[] {
24+
function getPlaygroundBuildArgs(): string[] | null {
2525
switch (PLAYGROUND_TYPE) {
2626
case 'react':
27-
return ['run', 'build-and-preview', '--', '--port', port.toString()];
27+
return ['run', 'build'];
2828
case 'web-js':
29-
return ['run', 'build-and-preview', '--', '-l', port.toString()];
29+
return ['run', 'build'];
3030
case 'web-js-script':
31-
return ['run', 'build-and-preview', '--', '-l', port.toString()];
31+
return null;
32+
default:
33+
throw new Error(`Unknown PLAYGROUND_TYPE: ${PLAYGROUND_TYPE}`);
34+
}
35+
}
36+
37+
function getPlaygroundStartArgs(port: number): string[] {
38+
switch (PLAYGROUND_TYPE) {
39+
case 'react':
40+
return ['run', 'preview', '--', '--port', port.toString()];
41+
case 'web-js':
42+
return ['run', 'serve', '--', '-l', port.toString()];
43+
case 'web-js-script':
44+
return ['run', 'serve', '--', '-l', port.toString()];
3245
default:
3346
throw new Error(`Unknown PLAYGROUND_TYPE: ${PLAYGROUND_TYPE}`);
3447
}
@@ -41,7 +54,7 @@ export async function spawnPlaygroundNew(projectId: string): Promise<{
4154
const port = await getPort();
4255

4356
const playgroundDir = getPlaygroundDir();
44-
const server = spawn('npm', getPlaygroundArgs(port), {
57+
const server = spawn('npm', getPlaygroundStartArgs(port), {
4558
cwd: playgroundDir,
4659
env: {
4760
...process.env,
@@ -76,7 +89,29 @@ export default async function installPlaygroundDeps() {
7689
installProcess.on('close', (code: number) => {
7790
if (code === 0) {
7891
console.log(`[Global Setup] Dependencies installed successfully in ${playgroundDir}.`);
79-
resolve();
92+
const buildCommand = getPlaygroundBuildArgs();
93+
if (!buildCommand) {
94+
console.log(`[Global Setup] No build step required for ${PLAYGROUND_TYPE}.`);
95+
return resolve();
96+
}
97+
const buildProcess = spawn('npm', buildCommand, {
98+
cwd: playgroundDir,
99+
stdio: 'inherit',
100+
shell: true,
101+
});
102+
buildProcess.on('close', (buildCode: number) => {
103+
if (buildCode === 0) {
104+
console.log(`[Global Setup] Playground built successfully in ${playgroundDir}.`);
105+
resolve();
106+
} else {
107+
reject(
108+
new Error(`[Global Setup] npm run build failed in ${playgroundDir} with code ${buildCode}`),
109+
);
110+
}
111+
});
112+
buildProcess.on('error', (err: Error) => {
113+
reject(new Error(`[Global Setup] Failed to start build process: ${err.message}`));
114+
});
80115
} else {
81116
reject(new Error(`[Global Setup] npm install failed in ${playgroundDir} with code ${code}`));
82117
}

packages/tests-e2e/src/connect/utils/Playground.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default async function installPlaygroundDeps() {
8484
resolve();
8585
} else {
8686
reject(
87-
new Error(`[Global Setup] npm run build-and-preview failed in ${playgroundDir} with code ${buildCode}`),
87+
new Error(`[Global Setup] npm run build failed in ${playgroundDir} with code ${buildCode}`),
8888
);
8989
}
9090
});

playground/react/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"build": "tsc && vite build",
99
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1010
"preview": "vite preview",
11-
"build-and-preview": "tsc && vite build && vite preview",
1211
"test": "vitest",
1312
"test:coverage": "vitest run --coverage"
1413
},

playground/web-js-script/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build-and-preview": "npx serve --single"
7+
"serve": "npx serve --single"
88
},
99
"keywords": [],
1010
"author": "",

playground/web-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start": "cross-env NODE_ENV=local webpack-dev-server --open --mode development",
88
"build": "cross-env NODE_ENV=vercel webpack --mode production",
9-
"build-and-preview": "cross-env NODE_ENV=vercel webpack --mode production && npx serve dist --single"
9+
"serve": "npx serve dist --single"
1010
},
1111
"keywords": [],
1212
"author": "",

0 commit comments

Comments
 (0)