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

tests: improve playwright test readability #5149

Merged

Conversation

artshllk
Copy link
Contributor

@artshllk artshllk commented Oct 1, 2024

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

This pull request improves the test suites by adding step() markers across tests for better debugging in the future. I also refactored the code to follow the DRY principle, reducing redundancy and improving maintainability.

Type of change

  • Code refactor (applying DRY principle)
  • This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas (including JSDoc for methods)
  • My changes generates no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

Hi thanks for the PR.
I have left a few comments below

* @param {string} text - The message to log, indicating the current step.
* @returns {void} Indicates that this function does not return a value.
*/
export function step(text) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This somewhat mucks with the dot printing way of the node test runner to display its progress.
Since in the event of a failiour, the place where the failiour is is reported, I don't think this adds value.

=> please remove this part of the PR

If some of the comments around them can be improved via the work you put in, that is fair gain and what I would like to see instead.

Note though comments have to describe something non-trivial.
For example the following would not be a good comment

// Taking SQLite snapshot
await takeSqliteSnapshot(page);


test.describe("Uptime Kuma Setup", () => {

// Skip tests if the SQLite database already exists (only run once per session)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: does not add value imo

Suggested change
// Skip tests if the SQLite database already exists (only run once per session)

* @param {string} monitorType - The monitor type to select (default is "dns").
* @returns {Promise<void>} - A promise that resolves when the form setup is complete.
*/
async function setupMonitorForm(page, testInfo, monitorType = "dns") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

About this function, please remove the parts which make this the testcases harder to read and duplicate that code instead.
DRY is not a goal for testcases, debuggability is.
Sorry if I was unclear about this in #5148 (comment)

For example the following would be much better for readability in a testcase

await page.goto("./add");
await login(page);
await screenshot(testInfo, page);
await selectMonitorType("dns")

Comment on lines 10 to 12
/*
* Hook to take a screenshot after each test
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think the code below is clear enough in this

Suggested change
/*
* Hook to take a screenshot after each test
*/

@CommanderStorm CommanderStorm added area:core issues describing changes to the core of uptime kuma pr:please address review comments this PR needs a bit more work to be mergable labels Oct 2, 2024
@artshllk
Copy link
Contributor Author

artshllk commented Oct 2, 2024

Hi thanks for the PR. I have left a few comments below

Thank you for the feedback! I'm learning and practicing as I go, and I’ve made the updates based on your suggestions. I hope everything looks good now, but feel free to let me know if anything else needs adjustment. Great working together on this :)

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

Thanks for the refactoring ♥️

@CommanderStorm CommanderStorm changed the title pw - improve playwright tests tests: improve playwright test readability Oct 3, 2024
@CommanderStorm CommanderStorm merged commit a309cf0 into louislam:master Oct 3, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core issues describing changes to the core of uptime kuma pr:please address review comments this PR needs a bit more work to be mergable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants