Skip to content
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

Switch from Cypress to Playwright #107

Merged
merged 35 commits into from
Aug 22, 2023
Merged

Switch from Cypress to Playwright #107

merged 35 commits into from
Aug 22, 2023

Conversation

ProchaLu
Copy link
Member

@ProchaLu ProchaLu commented Aug 7, 2023

Issue https://github.com/upleveled/courses/issues/1895

Description

This PR replaces the existing Cypress end-to-end tests with Playwright.

@ProchaLu ProchaLu self-assigned this Aug 7, 2023
@karlhorky
Copy link
Member

karlhorky commented Aug 7, 2023

Nice, can you write comments for every part of the diff? (incl. each config setting, separately)

Comment on lines 5 to 9
webServer: {
command: 'pnpm start',
port: 3000,
reuseExistingServer: !process.env.CI,
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To launch a development web server during the tests. It specifies the command to start the server, the port number, and whether to reuse an existing server (reuseExistingServer).
https://playwright.dev/docs/api/class-testconfig#test-config-web-server

Copy link
Member

@karlhorky karlhorky Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove reuseExistingServer - it creates inconsistent behavior where locally, Playwright will not fail if there's a server already running

two potential problems I thought of:

  1. student runs something else on port 3000 (test will fail from other application not fulfilling the test conditions)
  2. student runs dev server on port 3000 (test may fail from inconsistencies between development and production environments)

Copy link
Member

@karlhorky karlhorky Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the latest diff, it appears that reuseExistingServer was removed in 10f606a, although not commented here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command: 'pnpm start',

should this be changed at all based on the research below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the command from pnpm start to /node_modules/.bin/next start will not make any difference if we only test on the build server. The local build server will already have all of the dependencies installed, and there is no need to save memory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • it doesn't have to do with dependencies being installed - it's about running with lower RSS (Resident Set Size)
  • we should minimize this in every environment, always

Copy link
Member Author

@ProchaLu ProchaLu Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the webServer start command
98d4078

Copy link
Member

@karlhorky karlhorky Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, to be clear, the commit 98d4078 changes the start command to ./node_modules/.bin/next start

the research hasn't been yet completed in upleveled/next-js-example-spring-2023-atvie#10, but to get this merged quicker, we can put this in with the ./node_modules/.bin/next start suggestion for now, so approving this for now 👍 but leaving this conversation unresolved until we finish the research in the future

if we decide to change to output: 'standalone' in the future, then we need to change all of the ./node_modules/.bin/next start occurrences back - I started adding some TODOs for you here: upleveled/next-js-example-spring-2023-atvie#10 (comment)

playwright.config.ts Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved
Comment on lines 34 to 35
- name: Install Playwright
run: pnpm playwright install --with-deps chromium
Copy link
Member Author

@ProchaLu ProchaLu Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install Chromium browser

.gitignore Outdated Show resolved Hide resolved
pages/index.jsx Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved

test('Navigate and check page content', async ({ page }) => {
await page.goto('/');
await expect(page.getByTestId('homePageTitle')).toBeVisible();
Copy link
Member

@karlhorky karlhorky Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is not consistent with the others that we have:

  • it uses homePageTitle instead of pageTitle
  • it does not check the content of the element
  • you may also want to consider moving it to the bottom of the block, to be consistent with the position in the other blocks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data-test-id attribute was changed to pageTitle and added an assertion that the h1 is not empty.

commit 8de6c11

Copy link
Member

@karlhorky karlhorky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 🚀

@ProchaLu ProchaLu merged commit 73bf53a into main Aug 22, 2023
2 checks passed
@ProchaLu ProchaLu deleted the switch-to-playwright branch August 22, 2023 12:18
Comment on lines +5 to +8
webServer: {
command: './node_modules/.bin/next start',
port: 3000,
},
Copy link
Member

@karlhorky karlhorky Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add stdout: 'pipe' (default is 'ignore', which discards stdout from the process), added in:

this can be useful for debugging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants