Skip to content

Commit bbbea86

Browse files
authored
test(e2e): Use pnpm for e2e tests (#7930)
1 parent 5a3c29d commit bbbea86

File tree

15 files changed

+37
-50
lines changed

15 files changed

+37
-50
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ jobs:
768768
uses: actions/checkout@v3
769769
with:
770770
ref: ${{ env.HEAD_COMMIT }}
771+
- uses: pnpm/action-setup@v2
772+
with:
773+
version: 7
771774
- name: Set up Node
772775
uses: actions/setup-node@v3
773776
with:

.github/workflows/canary.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
uses: actions/checkout@v3
2727
with:
2828
ref: ${{ env.HEAD_COMMIT }}
29+
- uses: pnpm/action-setup@v2
30+
with:
31+
version: 7
2932
- name: Set up Node
3033
uses: actions/setup-node@v3
3134
with:

packages/e2e-tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ To get you started with the recipe, you can copy the following into `test-recipe
5454
{
5555
"$schema": "../../test-recipe-schema.json",
5656
"testApplicationName": "My New Test Application",
57-
"buildCommand": "yarn install",
57+
"buildCommand": "pnpm install",
5858
"tests": [
5959
{
6060
"testName": "My new test",
61-
"testCommand": "yarn test",
61+
"testCommand": "pnpm test",
6262
"timeoutSeconds": 60
6363
}
6464
]

packages/e2e-tests/lib/buildApp.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-console */
22

33
import * as fs from 'fs-extra';
4-
import * as os from 'os';
54
import * as path from 'path';
65

76
import { DEFAULT_BUILD_TIMEOUT_SECONDS } from './constants';
@@ -29,13 +28,9 @@ export async function buildApp(appDir: string, recipeInstance: RecipeInstance, e
2928
if (recipe.buildCommand) {
3029
console.log(`Running build command for test application "${label}"`);
3130

32-
fs.mkdirSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches'), { recursive: true });
33-
const tempYarnCache = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches', 'cache-'));
34-
3531
const env = {
3632
...process.env,
3733
...envVars,
38-
YARN_CACHE_FOLDER: tempYarnCache, // Use a separate yarn cache for each build commmand because multiple yarn commands running at the same time may corrupt the cache
3934
};
4035

4136
const buildResult = await spawnAsync(recipe.buildCommand, {

packages/e2e-tests/lib/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export const DEFAULT_BUILD_TIMEOUT_SECONDS = 60 * 5;
33
export const DEFAULT_TEST_TIMEOUT_SECONDS = 60 * 2;
44
export const VERDACCIO_VERSION = '5.22.1';
55
export const PUBLISH_PACKAGES_DOCKER_IMAGE_NAME = 'publish-packages';
6-
export const TMP_DIR = 'tmp';

packages/e2e-tests/lib/runAllTestApps.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
/* eslint-disable no-console */
2-
import * as fs from 'fs';
3-
import * as os from 'os';
4-
import * as path from 'path';
52

63
import { constructRecipeInstances } from './constructRecipeInstances';
74
import { buildAndTestApp } from './runTestApp';
@@ -11,7 +8,7 @@ export async function runAllTestApps(
118
recipePaths: string[],
129
envVarsToInject: Record<string, string | undefined>,
1310
): Promise<void> {
14-
const maxParallel = process.env.CI ? 1 : 1; // For now we are disabling parallel execution because it was causing problems (runners were too slow and timeouts happened)
11+
const maxParallel = process.env.CI ? 3 : 6;
1512

1613
const recipeInstances = constructRecipeInstances(recipePaths);
1714

@@ -37,8 +34,6 @@ export async function runAllTestApps(
3734

3835
const failed = results.filter(result => result.buildFailed || result.testFailed);
3936

40-
fs.rmSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches'), { force: true, recursive: true });
41-
4237
if (failed.length) {
4338
console.log(`${failed.length} test(s) failed.`);
4439
process.exit(1);

packages/e2e-tests/lib/runTestApp.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
/* eslint-disable no-console */
2-
3-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs';
2+
import * as fsExtra from 'fs-extra';
43
import * as path from 'path';
54

65
import { buildApp } from './buildApp';
7-
import { TMP_DIR } from './constants';
86
import { testApp } from './testApp';
97
import type { Env, RecipeInstance, RecipeTestResult } from './types';
108

11-
let tmpDirCount = 0;
12-
139
// This should never throw, we always return a result here
1410
export async function buildAndTestApp(
1511
recipeInstance: RecipeInstance,
@@ -18,9 +14,11 @@ export async function buildAndTestApp(
1814
const { recipe, portModulo, portGap } = recipeInstance;
1915
const recipeDirname = path.dirname(recipe.path);
2016

21-
const targetDir = path.join(TMP_DIR, `${recipe.testApplicationName}-${tmpDirCount++}`);
17+
const tmpFolder = path.join(__dirname, '..', 'tmp');
18+
await fs.promises.mkdir(tmpFolder, { recursive: true });
19+
const targetDir = await fs.promises.mkdtemp(path.join(tmpFolder, 'tmp-app-'));
2220

23-
await fs.copy(recipeDirname, targetDir);
21+
await fsExtra.copy(recipeDirname, targetDir);
2422

2523
const env: Env = {
2624
...envVarsToInject,
@@ -31,7 +29,7 @@ export async function buildAndTestApp(
3129
try {
3230
await buildApp(targetDir, recipeInstance, env);
3331
} catch (error) {
34-
await fs.remove(targetDir);
32+
await fsExtra.remove(targetDir);
3533

3634
return {
3735
...recipeInstance,
@@ -42,15 +40,17 @@ export async function buildAndTestApp(
4240
}
4341

4442
// This cannot throw, we always return a result here
45-
const results = await testApp(targetDir, recipeInstance, env);
46-
47-
// Cleanup
48-
await fs.remove(targetDir);
49-
50-
return {
51-
...recipeInstance,
52-
buildFailed: false,
53-
testFailed: results.some(result => result.result !== 'PASS'),
54-
tests: results,
55-
};
43+
return testApp(targetDir, recipeInstance, env)
44+
.finally(() => {
45+
// Cleanup
46+
void fsExtra.remove(targetDir);
47+
})
48+
.then(results => {
49+
return {
50+
...recipeInstance,
51+
buildFailed: false,
52+
testFailed: results.some(result => result.result !== 'PASS'),
53+
tests: results,
54+
};
55+
});
5656
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "create-next-app",
4-
"buildCommand": "yarn install && npx playwright install && yarn build",
4+
"buildCommand": "pnpm install && npx playwright install && pnpm build",
55
"tests": [
66
{
77
"testName": "Playwright tests - Prod Mode",

packages/e2e-tests/test-applications/create-react-app/src/App.test.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "create-react-app",
4-
"buildCommand": "yarn install && yarn build",
4+
"buildCommand": "pnpm install && pnpm build",
55
"tests": []
66
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"noEmit": true,
1717
"jsx": "react"
1818
},
19-
"include": ["src"]
19+
"include": ["src"],
20+
"exclude": ["src/**/*.test.tsx"]
2021
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "nextjs-13-app-dir",
4-
"buildCommand": "yarn install && npx playwright install && yarn build",
4+
"buildCommand": "pnpm install && npx playwright install && pnpm build",
55
"buildAssertionCommand": "yarn ts-node --script-mode assert-build.ts",
66
"tests": [
77
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "node-express-app",
4-
"buildCommand": "yarn install && yarn build",
4+
"buildCommand": "pnpm install && pnpm build",
55
"tests": [
66
{
77
"testName": "Test express server",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "standard-frontend-react-tracing-import",
4-
"buildCommand": "yarn install && npx playwright install && yarn build",
4+
"buildCommand": "pnpm install && npx playwright install && pnpm build",
55
"tests": [
66
{
77
"testName": "Playwright tests",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "standard-frontend-react",
4-
"buildCommand": "yarn install && npx playwright install && yarn build",
4+
"buildCommand": "pnpm install && npx playwright install && pnpm build",
55
"tests": [
66
{
77
"testName": "Playwright tests",

0 commit comments

Comments
 (0)