Skip to content

Commit 36386f8

Browse files
committed
port modulo logic lol
1 parent 18ae133 commit 36386f8

File tree

10 files changed

+15
-17
lines changed

10 files changed

+15
-17
lines changed

packages/e2e-tests/lib/buildApp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function buildApp(appDir: string, recipeInstance: RecipeInstance, e
3737
env: {
3838
...process.env,
3939
...env,
40+
4041
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
4142
} as unknown as NodeJS.ProcessEnv,
4243
});

packages/e2e-tests/lib/constructRecipeInstances.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import type { Recipe, RecipeInput, RecipeInstance } from './types';
44

55
export function constructRecipeInstances(recipePaths: string[]): RecipeInstance[] {
66
const recipes = buildRecipes(recipePaths);
7-
let reservedPortCount = 0;
8-
const recipeInstances: RecipeInstance[] = [];
9-
10-
const basePort = 3001;
7+
const recipeInstances: Omit<RecipeInstance, 'portModulo' | 'portGap'>[] = [];
118

129
recipes.forEach(recipe => {
1310
recipe.versions.forEach(version => {
@@ -21,13 +18,11 @@ export function constructRecipeInstances(recipePaths: string[]): RecipeInstance[
2118
label: `${recipe.testApplicationName}${dependencyOverridesInformationString}`,
2219
recipe,
2320
dependencyOverrides,
24-
port: basePort + reservedPortCount,
2521
});
26-
reservedPortCount++;
2722
});
2823
});
2924

30-
return recipeInstances;
25+
return recipeInstances.map((instance, i) => ({ ...instance, portModulo: i, portGap: recipeInstances.length }));
3126
}
3227

3328
function buildRecipes(recipePaths: string[]): Recipe[] {

packages/e2e-tests/lib/runTestApp.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function buildAndTestApp(
1515
recipeInstance: RecipeInstance,
1616
envVarsToInject: Record<string, string | undefined>,
1717
): Promise<RecipeTestResult> {
18-
const { recipe, port } = recipeInstance;
18+
const { recipe, portModulo, portGap } = recipeInstance;
1919
const recipeDirname = path.dirname(recipe.path);
2020

2121
const targetDir = path.join(TMP_DIR, `${recipe.testApplicationName}-${tmpDirCount++}`);
@@ -24,7 +24,8 @@ export async function buildAndTestApp(
2424

2525
const env: Env = {
2626
...envVarsToInject,
27-
PORT: port.toString(),
27+
PORT_MODULO: portModulo.toString(),
28+
PORT_GAP: portGap.toString(),
2829
};
2930

3031
try {

packages/e2e-tests/lib/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export interface RecipeInstance {
3737
label: string;
3838
recipe: Recipe;
3939
dependencyOverrides?: DependencyOverrides;
40-
port: number;
40+
portModulo: number;
41+
portGap: number;
4142
}
4243

4344
export interface RecipeTestResult extends RecipeInstance {

packages/e2e-tests/test-applications/create-next-app/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const config: PlaywrightTestConfig = {
6060
/* Run your local dev server before starting the tests */
6161
webServer: {
6262
command: process.env.TEST_MODE === 'prod' ? 'yarn start' : 'yarn dev',
63-
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
63+
port: 3000 + Number(process.env.PORT_MODULO ?? 0),
6464
},
6565
};
6666

packages/e2e-tests/test-applications/nextjs-app-dir/playwright.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (!testEnv) {
77
throw new Error('No test env defined');
88
}
99

10-
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
10+
const port = 3000 + Number(process.env.PORT_MODULO ?? 0);
1111

1212
/**
1313
* See https://playwright.dev/docs/test-configuration.
@@ -60,7 +60,7 @@ const config: PlaywrightTestConfig = {
6060
},
6161
{
6262
command: 'yarn ts-node-script start-event-proxy.ts',
63-
port: 27496,
63+
port: 3000 + Number(process.env.PORT_MODULO ?? 0) + Number(process.env.PORT_GAP ?? 0),
6464
},
6565
],
6666
};

packages/e2e-tests/test-applications/node-express-app/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const config: PlaywrightTestConfig = {
5858
/* Run your local dev server before starting the tests */
5959
webServer: {
6060
command: 'yarn start',
61-
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
61+
port: 3000 + Number(process.env.PORT_MODULO ?? 0),
6262
},
6363
};
6464

packages/e2e-tests/test-applications/node-express-app/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Sentry.init({
1717
});
1818

1919
const app = express();
20-
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
20+
const port = 3000 + Number(process.env.PORT_MODULO ?? 0);
2121

2222
app.use(Sentry.Handlers.requestHandler());
2323
app.use(Sentry.Handlers.tracingHandler());

packages/e2e-tests/test-applications/standard-frontend-react-tracing-import/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const config: PlaywrightTestConfig = {
6060
/* Run your local dev server before starting the tests */
6161
webServer: {
6262
command: 'yarn start',
63-
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
63+
port: 3000 + Number(process.env.PORT_MODULO ?? 0),
6464
},
6565
};
6666

packages/e2e-tests/test-applications/standard-frontend-react/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const config: PlaywrightTestConfig = {
6060
/* Run your local dev server before starting the tests */
6161
webServer: {
6262
command: 'yarn start',
63-
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
63+
port: 3000 + Number(process.env.PORT_MODULO ?? 0),
6464
},
6565
};
6666

0 commit comments

Comments
 (0)