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

doc: recommend writing tests in new files and including comments #57028

Merged
merged 1 commit into from
Feb 15, 2025

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 13, 2025

The previous phrasing encouraged or did not discourage appending new test cases to existing files - a practice that can reduce the debuggability of the tests over time as they get bigger and bigger, some times thousands of lines long with hundreds of test cases, and make the CI output increasingly difficult to read when one of the test cases fail in a very long test.

This patch updates the guideline to explicitly discourage appending test cases this way. Also recommend including an opening comment to describe what the test does to optimize the test towards the scenario when it fails.

For some concrete examples:

  1. Previously I had to split test-crypto-dh.js and test-wasi.js because they were timing out in the CI, some might be related to actual bugs but there is no way to figure out which test specifically is timing out in a long test, so it had to be split to isolate them.
  2. When the test crashes like this https://ci.nodejs.org/job/node-test-commit-arm-debug/17147/nodes=ubuntu2204_debug-arm64/testReport/junit/(root)/parallel/test_child_process_exec_maxbuf/ it's difficult to figure out exactly which test case is crashing

To avoid losing git history I would not recommend splitting existing tests unless there's a ongoing motivation to do so (e.g. it's flaking in the CI). But I think we should at least discourage new tests to be written in a way that exacerbate the problem.

The previous phrasing encouraged or did not discourage appending
new test cases to existing files - a practice that can reduce
the debuggability of the tests over time as they get bigger and
bigger, some times thousands of lines long with hundreds of
test cases, and make the CI output increasingly difficult to
read when one of the test cases fail in a very long test.

This patch updates the guideline to explicitly discourage appending
test cases this way. Also recommend including an opening comment
to describe what the test does to optimize the test towards the
scenario when it fails.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/tsc

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Feb 13, 2025
@joyeecheung
Copy link
Member Author

joyeecheung commented Feb 13, 2025

cc @jasnell @nodejs/tsc since we discussed this in the TSC meeting before. In recent code reviews I noticed that many are still appending new test cases this way, which is probably guided by the doc, so I think we need to update the docs to have a ground to ask for changes when people do this in the PR.

@lpinca lpinca added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 13, 2025
@jakecastelli jakecastelli added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 14, 2025
@jakecastelli
Copy link
Member

I personally found naming a test (file name) is also hard, do we have any convention or guide for it?

@joyeecheung
Copy link
Member Author

I usually start with writing the comment and then take keywords from my comment to create the name. Not sure if that counts as guides.

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 15, 2025
@nodejs-github-bot nodejs-github-bot merged commit ff51d83 into nodejs:main Feb 15, 2025
26 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in ff51d83

targos pushed a commit that referenced this pull request Feb 17, 2025
The previous phrasing encouraged or did not discourage appending
new test cases to existing files - a practice that can reduce
the debuggability of the tests over time as they get bigger and
bigger, some times thousands of lines long with hundreds of
test cases, and make the CI output increasingly difficult to
read when one of the test cases fail in a very long test.

This patch updates the guideline to explicitly discourage appending
test cases this way. Also recommend including an opening comment
to describe what the test does to optimize the test towards the
scenario when it fails.

PR-URL: #57028
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ulises Gascón <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Jake Yuesong Li <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Tierney Cyren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants