Skip to content

test(e2e): Use pnpm for e2e tests #7930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v2
with:
version: 7
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v2
with:
version: 7
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ To get you started with the recipe, you can copy the following into `test-recipe
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "My New Test Application",
"buildCommand": "yarn install",
"buildCommand": "pnpm install",
"tests": [
{
"testName": "My new test",
"testCommand": "yarn test",
"testCommand": "pnpm test",
"timeoutSeconds": 60
}
]
Expand Down
5 changes: 0 additions & 5 deletions packages/e2e-tests/lib/buildApp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */

import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';

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

fs.mkdirSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches'), { recursive: true });
const tempYarnCache = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches', 'cache-'));

const env = {
...process.env,
...envVars,
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
};

const buildResult = await spawnAsync(recipe.buildCommand, {
Expand Down
1 change: 0 additions & 1 deletion packages/e2e-tests/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export const DEFAULT_BUILD_TIMEOUT_SECONDS = 60 * 5;
export const DEFAULT_TEST_TIMEOUT_SECONDS = 60 * 2;
export const VERDACCIO_VERSION = '5.22.1';
export const PUBLISH_PACKAGES_DOCKER_IMAGE_NAME = 'publish-packages';
export const TMP_DIR = 'tmp';
7 changes: 1 addition & 6 deletions packages/e2e-tests/lib/runAllTestApps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable no-console */
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

import { constructRecipeInstances } from './constructRecipeInstances';
import { buildAndTestApp } from './runTestApp';
Expand All @@ -11,7 +8,7 @@ export async function runAllTestApps(
recipePaths: string[],
envVarsToInject: Record<string, string | undefined>,
): Promise<void> {
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)
const maxParallel = process.env.CI ? 3 : 6;

const recipeInstances = constructRecipeInstances(recipePaths);

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

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

fs.rmSync(path.join(os.tmpdir(), 'e2e-test-yarn-caches'), { force: true, recursive: true });

if (failed.length) {
console.log(`${failed.length} test(s) failed.`);
process.exit(1);
Expand Down
40 changes: 20 additions & 20 deletions packages/e2e-tests/lib/runTestApp.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* eslint-disable no-console */

import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as fsExtra from 'fs-extra';
import * as path from 'path';

import { buildApp } from './buildApp';
import { TMP_DIR } from './constants';
import { testApp } from './testApp';
import type { Env, RecipeInstance, RecipeTestResult } from './types';

let tmpDirCount = 0;

// This should never throw, we always return a result here
export async function buildAndTestApp(
recipeInstance: RecipeInstance,
Expand All @@ -18,9 +14,11 @@ export async function buildAndTestApp(
const { recipe, portModulo, portGap } = recipeInstance;
const recipeDirname = path.dirname(recipe.path);

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

await fs.copy(recipeDirname, targetDir);
await fsExtra.copy(recipeDirname, targetDir);

const env: Env = {
...envVarsToInject,
Expand All @@ -31,7 +29,7 @@ export async function buildAndTestApp(
try {
await buildApp(targetDir, recipeInstance, env);
} catch (error) {
await fs.remove(targetDir);
await fsExtra.remove(targetDir);

return {
...recipeInstance,
Expand All @@ -42,15 +40,17 @@ export async function buildAndTestApp(
}

// This cannot throw, we always return a result here
const results = await testApp(targetDir, recipeInstance, env);

// Cleanup
await fs.remove(targetDir);

return {
...recipeInstance,
buildFailed: false,
testFailed: results.some(result => result.result !== 'PASS'),
tests: results,
};
return testApp(targetDir, recipeInstance, env)
.finally(() => {
// Cleanup
void fsExtra.remove(targetDir);
})
.then(results => {
return {
...recipeInstance,
buildFailed: false,
testFailed: results.some(result => result.result !== 'PASS'),
tests: results,
};
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "create-next-app",
"buildCommand": "yarn install && npx playwright install && yarn build",
"buildCommand": "pnpm install && npx playwright install && pnpm build",
"tests": [
{
"testName": "Playwright tests - Prod Mode",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "create-react-app",
"buildCommand": "yarn install && yarn build",
"buildCommand": "pnpm install && pnpm build",
"tests": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
"include": ["src"],
"exclude": ["src/**/*.test.tsx"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "nextjs-13-app-dir",
"buildCommand": "yarn install && npx playwright install && yarn build",
"buildCommand": "pnpm install && npx playwright install && pnpm build",
"buildAssertionCommand": "yarn ts-node --script-mode assert-build.ts",
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "node-express-app",
"buildCommand": "yarn install && yarn build",
"buildCommand": "pnpm install && pnpm build",
"tests": [
{
"testName": "Test express server",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "standard-frontend-react-tracing-import",
"buildCommand": "yarn install && npx playwright install && yarn build",
"buildCommand": "pnpm install && npx playwright install && pnpm build",
"tests": [
{
"testName": "Playwright tests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "standard-frontend-react",
"buildCommand": "yarn install && npx playwright install && yarn build",
"buildCommand": "pnpm install && npx playwright install && pnpm build",
"tests": [
{
"testName": "Playwright tests",
Expand Down