Skip to content

Commit 03b7461

Browse files
authored
test(e2e): Show test progress & ensure we clean before running tests (#8649)
Noticed that when running `yarn test:run` it sometimes hang forever. Solved this with two steps: 1. Make sure we actually output the shell stuff, as otherwise it is super hard to debug what's going on. 2. The problem was that sometimes `pnpm` prompts to re-create node_modules (??), and the prompt was obviously forever hanging. I couldn't find any option to disable this from pnpm side, sadly 😬 So I ended up adding a step to clean out all node_modules etc. before running the tests.
1 parent a72efa2 commit 03b7461

File tree

11 files changed

+41
-4
lines changed

11 files changed

+41
-4
lines changed

packages/e2e-tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test:validate-test-app-setups": "ts-node validate-test-app-setups.ts",
2121
"test:prepare": "ts-node prepare.ts",
2222
"test:validate": "run-s test:validate-configuration test:validate-test-app-setups",
23-
"clean": "rimraf tmp test-applications/**/{node_modules,dist,build,.next,.sveltekit,pnpm-lock.yaml}"
23+
"clean": "rimraf tmp node_modules && yarn clean:test-applications",
24+
"clean:test-applications": "rimraf test-applications/**/{node_modules,dist,build,.next,.sveltekit,pnpm-lock.yaml}"
2425
},
2526
"devDependencies": {
2627
"@types/glob": "8.0.0",

packages/e2e-tests/run.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
/* eslint-disable max-lines */
22
/* eslint-disable no-console */
3-
import { exec } from 'child_process';
3+
import { spawn } from 'child_process';
44
import * as dotenv from 'dotenv';
55
import { sync as globSync } from 'glob';
66
import { resolve } from 'path';
7-
import { promisify } from 'util';
87

98
import { validate } from './lib/validate';
109
import { registrySetup } from './registrySetup';
1110

12-
const asyncExec = promisify(exec);
11+
function asyncExec(command: string, options: { env: Record<string, string | undefined>; cwd: string }): Promise<void> {
12+
return new Promise((resolve, reject) => {
13+
const process = spawn(command, { ...options, shell: true });
14+
15+
process.stdout.on('data', data => {
16+
console.log(`${data}`);
17+
});
18+
19+
process.stderr.on('data', data => {
20+
console.error(`${data}`);
21+
});
22+
23+
process.on('error', error => {
24+
reject(error);
25+
});
26+
27+
process.on('close', code => {
28+
if (code !== 0) {
29+
return reject();
30+
}
31+
resolve();
32+
});
33+
});
34+
}
1335

1436
async function run(): Promise<void> {
1537
// Load environment variables from .env file locally
@@ -31,8 +53,13 @@ async function run(): Promise<void> {
3153
const env = { ...process.env, ...envVarsToInject };
3254

3355
try {
56+
console.log('Cleaning test-applications...');
57+
console.log('');
58+
3459
registrySetup();
3560

61+
await asyncExec('pnpm clean:test-applications', { env, cwd: __dirname });
62+
3663
const testAppPaths = appName ? [appName.trim()] : globSync('*', { cwd: `${__dirname}/test-applications/` });
3764

3865
console.log(`Runnings tests for: ${testAppPaths.join(', ')}`);

packages/e2e-tests/test-applications/create-next-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
78
"test:prod": "TEST_ENV=prod playwright test",
89
"test:dev": "TEST_ENV=dev playwright test",
910
"test:build": "pnpm install && npx playwright install && pnpm build",

packages/e2e-tests/test-applications/create-react-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"build": "react-scripts build",
2424
"test": "react-scripts test",
2525
"eject": "react-scripts eject",
26+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
2627
"test:build": "pnpm install && pnpm build",
2728
"test:build-ts3.8": "pnpm install && pnpm add [email protected] && pnpm build",
2829
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && pnpm build",

packages/e2e-tests/test-applications/create-remix-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "remix dev",
77
"start": "remix-serve build",
88
"typecheck": "tsc",
9+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
910
"test:build": "pnpm install && npx playwright install && pnpm build",
1011
"test:assert": "pnpm playwright test"
1112
},

packages/e2e-tests/test-applications/nextjs-app-dir/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build > .tmp_build_output",
7+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
78
"test:prod": "TEST_ENV=production playwright test",
89
"test:dev": "TEST_ENV=development playwright test",
910
"test:build": "pnpm install && npx playwright install && pnpm build",

packages/e2e-tests/test-applications/node-express-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"build": "tsc",
77
"start": "node dist/app.js",
88
"test": "playwright test",
9+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
910
"test:build": "pnpm install && pnpm build",
1011
"test:assert": "pnpm test"
1112
},

packages/e2e-tests/test-applications/react-create-hash-router/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"build": "react-scripts build",
2323
"start": "serve -s build",
2424
"test": "playwright test",
25+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
2526
"test:build": "pnpm install && npx playwright install && pnpm build",
2627
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",
2728
"test:assert": "pnpm test"

packages/e2e-tests/test-applications/standard-frontend-react-tracing-import/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"build": "react-scripts build",
2424
"start": "serve -s build",
2525
"test": "playwright test",
26+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
2627
"test:build": "pnpm install && npx playwright install && pnpm build",
2728
"test:assert": "pnpm test"
2829
},

packages/e2e-tests/test-applications/standard-frontend-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"build": "react-scripts build",
2323
"start": "serve -s build",
2424
"test": "playwright test",
25+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
2526
"test:build": "pnpm install && npx playwright install && pnpm build",
2627
"test:build-ts3.8": "pnpm install && pnpm add [email protected] && npx playwright install && pnpm build",
2728
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",

packages/e2e-tests/test-applications/sveltekit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "vite dev",
77
"build": "vite build",
88
"preview": "vite preview",
9+
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
910
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1011
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1112
"test:prod": "TEST_ENV=production playwright test",

0 commit comments

Comments
 (0)