Skip to content

test(e2e): Avoid race condition with event proxy #7965

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 7 commits into from
Apr 26, 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ jobs:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8.3.1
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8.3.1
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion packages/e2e-tests/lib/runTestApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function buildAndTestApp(

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

await fsExtra.copy(recipeDirname, targetDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const config: PlaywrightTestConfig = {

/* Run your local dev server before starting the tests */
webServer: {
command: testEnv === 'development' ? `yarn next dev -p ${port}` : `yarn next start -p ${port}`,
command: testEnv === 'development' ? `pnpm next dev -p ${port}` : `pnpm next start -p ${port}`,
port,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"tests": [
{
"testName": "Playwright tests - Prod Mode",
"testCommand": "yarn test:prod"
"testCommand": "pnpm test:prod"
},
{
"testName": "Playwright tests - Dev Mode",
"testCommand": "yarn test:dev"
"testCommand": "pnpm test:dev"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"next": "13.2.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "4.9.4"
},
"devDependencies": {
"typescript": "4.9.4",
"wait-port": "1.0.4",
"ts-node": "10.9.1",
"@playwright/test": "^1.27.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ if (!testEnv) {
throw new Error('No test env defined');
}

const port = Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO);
const nextPort = Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO);
const eventProxyPort = Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO) + Number(process.env.PORT_GAP);

/**
* See https://playwright.dev/docs/test-configuration.
Expand Down Expand Up @@ -36,7 +37,7 @@ const config: PlaywrightTestConfig = {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: `http://localhost:${port}`,
baseURL: `http://localhost:${nextPort}`,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand All @@ -55,12 +56,15 @@ const config: PlaywrightTestConfig = {
/* Run your local dev server before starting the tests */
webServer: [
{
command: testEnv === 'development' ? `yarn next dev -p ${port}` : `yarn next start -p ${port}`,
port,
command: 'pnpm ts-node-script start-event-proxy.ts',
port: eventProxyPort,
},
{
command: 'yarn ts-node-script start-event-proxy.ts',
port: Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO) + Number(process.env.PORT_GAP),
command:
testEnv === 'development'
? `pnpm wait-port ${eventProxyPort} && pnpm next dev -p ${nextPort}`
: `pnpm wait-port ${eventProxyPort} && pnpm next start -p ${nextPort}`,
port: nextPort,
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "nextjs-13-app-dir",
"buildCommand": "pnpm install && npx playwright install && pnpm build",
"buildAssertionCommand": "yarn ts-node --script-mode assert-build.ts",
"buildAssertionCommand": "pnpm ts-node --script-mode assert-build.ts",
"tests": [
{
"testName": "Prod Mode",
"testCommand": "yarn test:prod"
"testCommand": "pnpm test:prod"
},
{
"testName": "Dev Mode",
"testCommand": "yarn test:dev"
"testCommand": "pnpm test:dev"
}
],
"canaryVersions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"private": true,
"scripts": {
"build": "yarn tsc",
"build": "tsc",
"start": "node dist/app.js",
"test": "yarn playwright test"
"test": "playwright test"
},
"dependencies": {
"@sentry/integrations": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const config: PlaywrightTestConfig = {

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn start',
command: 'pnpm start',
port: Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tests": [
{
"testName": "Test express server",
"testCommand": "yarn test",
"testCommand": "pnpm test",
"timeoutSeconds": 60
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const config: PlaywrightTestConfig = {

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn start',
command: 'pnpm start',
port: Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO),
env: {
PORT: String(Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tests": [
{
"testName": "Playwright tests",
"testCommand": "yarn test"
"testCommand": "pnpm test"
}
],
"canaryVersions": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const config: PlaywrightTestConfig = {

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn start',
command: 'pnpm start',
port: Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO),
env: {
PORT: String(Number(process.env.BASE_PORT) + Number(process.env.PORT_MODULO)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tests": [
{
"testName": "Playwright tests",
"testCommand": "yarn test"
"testCommand": "pnpm test"
}
],
"canaryVersions": [
Expand Down