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

test_runner: display failed test stack trace with dot reporter #52655

Merged
merged 1 commit into from May 7, 2024

Conversation

mihir254
Copy link
Contributor

@mihir254 mihir254 commented Apr 23, 2024

Add failed test names and stack trace to dot reporter output

Fixes: #51769

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner labels Apr 23, 2024
@@ -23,6 +29,14 @@ module.exports = async function* dot(source) {
}
}
yield '\n';

if (failedTests.length > 0) {
yield `${colors.red}${failedTestSymbol} failing tests:${colors.white}\n`;
Copy link
Member

Choose a reason for hiding this comment

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

Use uppercase when possible

Failed tests:

Copy link
Contributor Author

@mihir254 mihir254 Apr 23, 2024

Choose a reason for hiding this comment

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

Sure, I'll keep that in mind. I assumed it should be consistent with the spec reporter, which uses "failing tests:"

Copy link
Member

Choose a reason for hiding this comment

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

@nodejs/test_runner WDYT about the formatting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I also make it Failed tests: for spec reporter?

Copy link
Member

Choose a reason for hiding this comment

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

can be in a separate PR

if (type === 'test:pass') {
yield '.';
}
if (type === 'test:fail') {
yield 'X';
failedTests.push(data);
Copy link
Member

Choose a reason for hiding this comment

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

For the internals of Node.js, we use primordials, so try to use them when possible (ArrayPrototypePush)

@RedYetiDev
Copy link
Member

Also, please lint your source code and commit message.

(You just need to the put the change in the commit message, E.G. test: print failed tests with dot reporter, and the rest can go in the PR description)

Copy link
Member

@atlowChemi atlowChemi left a comment

Choose a reason for hiding this comment

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

The commit should be prefixed with the node submodule changed, which in this case is test_runner and not test (test refers to the tests used in the Nodejs CI)

Please note that you will have to regenerate the snapshots for this to work. You will have to run the following command NODE_REGENERATE_SNAPSHOTS=1 ./node test/parallel/test-runner-output.mjs see:

node/test/common/README.md

Lines 690 to 694 in 1681786

### `NODE_REGENERATE_SNAPSHOTS`
If set, test snapshots for a the current test are regenerated.
for example `NODE_REGENERATE_SNAPSHOTS=1 out/Release/node test/parallel/test-runner-output.mjs`
will update all the test runner output snapshots.

lib/internal/test_runner/reporter/dot.js Outdated Show resolved Hide resolved
lib/internal/test_runner/reporter/dot.js Outdated Show resolved Hide resolved
@@ -23,6 +29,14 @@ module.exports = async function* dot(source) {
}
}
yield '\n';

if (failedTests.length > 0) {
yield `${colors.red}${failedTestSymbol} failing tests:${colors.white}\n`;
Copy link
Member

Choose a reason for hiding this comment

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

We might want to use util.styleText, though I am not sure we want to, as it could be affected from user-land

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since the issue mentioned spec reporter, I tried to match it to how it's done in spec.js. If it is required to be changed, should it only be done for dot reporter or for spec reporter as well?

Copy link
Member

Choose a reason for hiding this comment

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

The util.styleText was added after these reporters 🙂
Anyway, not sure we want to use it here. @MoLow @cjihrig WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

It might be worth to change it globally, but I think that’s an issue for a different PR.

if (failedTests.length > 0) {
yield `${colors.red}${failedTestSymbol} failing tests:${colors.white}\n`;
for (const test of failedTests) {
const message = `${colors.red}${failedTestSymbol} ${test.name} ${colors.gray}(${test.details.duration_ms}ms)\n`;
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to reset the output color after this?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you please add a unit test?

@MoLow
Copy link
Member

MoLow commented Apr 24, 2024

Can you please add a unit test?

there are existing tests in place that need to be updated. see #52655 (review)

Copy link
Member

@RedYetiDev RedYetiDev left a comment

Choose a reason for hiding this comment

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

A lot of the test snapshots should not have changed

@mihir254
Copy link
Contributor Author

▶ test runner output (4860.751ms)
ℹ tests 47
ℹ suites 1
ℹ pass 44
ℹ fail 0
ℹ cancelled 0
ℹ skipped 3
ℹ todo 0
ℹ duration_ms 4870.7587
node:assert:173
throw err;
^

AssertionError [ERR_ASSERTION]: Unexpected global(s) found: DT_AGENT_INJECTED
at process. (C:\Users\M_Bhansali\Desktop\Projects\open source\node\test\common\index.js:396:14)
at process.emit (node:events:532:35) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: undefined,
operator: 'fail'
}

I get this after regenerating the snapshots, any idea what this could be about?
Thanks

@RedYetiDev
Copy link
Member

Chances are something that your PR changed caused an issue with testing in general. Try isolating the issue (via fiddling with the REPL or tests)

@@ -0,0 +1,15 @@
'use strict'

const symbols = {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure how I feel about this name 🤔
WDYT about reporterUnicodeSymbolMap etc?

Copy link
Member

Choose a reason for hiding this comment

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

We could also export them directly, or would that be an issue with prototypes?

Copy link
Member

Choose a reason for hiding this comment

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

It is not an issue... we need this when creating an object, not a string (so module.exports.something = '\u2176' is just fine 🤷🏽‍♂️
But I don't think we should export them directly, as we would want this file to have additional common code for the reporters, see #52655 (comment)

@atlowChemi
Copy link
Member

@mihir254 the submodule in the first commit is wrong, and in addition, the commit is 123 chars long, while the max allowed is 72.
Could you rebase and fix the commit message? If you need any help with that please let me know 🙂
see https://github.com/nodejs/node/actions/runs/8823097502/job/24235510052?pr=52655#step:6:13 and

#### Commit message guidelines
A good commit message should describe what changed and why.
1. The first line should:
* contain a short description of the change (preferably 50 characters or
less, and no more than 72 characters)
* be entirely in lowercase with the exception of proper nouns, acronyms, and
the words that refer to code, like function/variable names
* be prefixed with the name of the changed [subsystem](#appendix-subsystems)
and start with an imperative verb. Check the output of `git log --oneline
files/you/changed` to find out what subsystems your changes touch.
Examples:
* `net: add localAddress and localPort to Socket`
* `src: fix typos in async_wrap.h`
2. Keep the second line blank.
3. Wrap all other lines at 72 columns (except for long URLs).
4. If your patch fixes an open issue, you can add a reference to it at the end
of the log. Use the `Fixes:` prefix and the full issue URL. For other
references use `Refs:`.
Examples:
* `Fixes: https://github.com/nodejs/node/issues/1337`
* `Refs: https://eslint.org/docs/rules/space-in-parens.html`
* `Refs: https://github.com/nodejs/node/pull/3615`
5. If your commit introduces a breaking change (`semver-major`), it should
contain an explanation about the reason of the breaking change, which
situation would trigger the breaking change, and what is the exact change.
Sample complete commit message:
```text
subsystem: explain the commit in one line
The body of the commit message should be one or more paragraphs, explaining
things in more detail. Please word-wrap to keep columns to 72 characters or
less.
Fixes: https://github.com/nodejs/node/issues/1337
Refs: https://eslint.org/docs/rules/space-in-parens.html
```
If you are new to contributing to Node.js, please try to do your best at
conforming to these guidelines, but do not worry if you get something wrong.
One of the existing contributors will help get things situated and the
contributor landing the pull request will ensure that everything follows
the project guidelines.

@mihir254 mihir254 changed the title test: enhance dot reporter to display failed test names test_runner: display failed test stack trace with dot reporter Apr 25, 2024
Copy link
Member

@RedYetiDev RedYetiDev left a comment

Choose a reason for hiding this comment

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

I'm not quite sure if I like the amount of changes this PR has introduced (I'm not sure if they are all needed), but that's just my opinion.

As for changes, the globals error in most snapshots shouldn't be there (I think). AFAIK there is not global with that name.

throw err;
^

AssertionError [ERR_ASSERTION]: Unexpected global(s) found: __DT_AGENT_INJECTED__
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure what this global is, but I don't think it was here before

Copy link
Contributor Author

@mihir254 mihir254 Apr 26, 2024

Choose a reason for hiding this comment

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

I perhaps did not expect so many commits to line up in the PR. Should I create a fresh PR with the latest changes?
I have changed 3 test_runner/reporter files and 2 snapshots, in total.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can also create 2 different PRs, one for displaying mages in dot router and other for adding a stack trace to it.

Copy link
Member

Choose a reason for hiding this comment

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

You could rebase and squash some commits, if this is an issue (it would also allow fixing the first commit message)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@@ -1 +1,11 @@
.X
✖ Failed tests:
Copy link
Member

Choose a reason for hiding this comment

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

I think there might be a space too much before Failed tests:

Also, I'm would remove the x before and add a newline after the dots.

@RedYetiDev RedYetiDev added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 26, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 26, 2024
@nodejs-github-bot
Copy link
Collaborator

@RedYetiDev
Copy link
Member

@mihir254 according to the CI, there may be a merge conflict in the dot reporter

08:07:52 CONFLICT (content): Merge conflict in lib/internal/test_runner/reporter/dot.js

@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2024
@nodejs-github-bot
Copy link
Collaborator


constructor() {
super({ __proto__: null, writableObjectMode: true });
colors.refresh();
this.#inspectOptions = { __proto__: null, colors: colors.shouldColorize(process.stdout), breakLength: Infinity };
this.#colors = {
Copy link
Member

Choose a reason for hiding this comment

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

moving colors to utils breaks when there is no TTY, see https://ci.nodejs.org/job/node-test-commit-custom-suites-freestyle/35939/console:

colors cannot be deconstructed too early.

11:01:44         not ok 41 - test-runner/output/arbitrary-output-colored.js
11:01:44           ---
11:01:44           duration_ms: 5585.15492
11:01:44           location: '/home/iojs/build/workspace/node-test-commit-custom-suites-freestyle/test/parallel/test-runner-output.mjs:155:5'
11:01:44           failureType: 'testCodeFailure'
11:01:44           error: |-
11:01:44             Expected values to be strictly equal:
11:01:44             + actual - expected ... Lines skipped
11:01:44             
11:01:44               "{ foo: [32m'bar'[39m }\n" +
11:01:44                 '[33m1[39m\n' +
11:01:44             +   '✔ passing test [90m(*ms)[39m[39m\n' +
11:01:44             +   'ℹ tests 1[39m\n' +
11:01:44             +   'ℹ suites 0[39m\n' +
11:01:44             +   'ℹ pass 1[39m\n' +
11:01:44             +   'ℹ fail 0[39m\n' +
11:01:44             +   'ℹ cancelled 0[39m\n' +
11:01:44             +   'ℹ skipped 0[39m\n' +
11:01:44             +   'ℹ todo 0[39m\n' +
11:01:44             +   'ℹ duration_ms *[39m\n' +
11:01:44             -   '[32m✔ passing test [90m(*ms)[39m[39m\n' +
11:01:44             -   '[34mℹ tests 1[39m\n' +
11:01:44             -   '[34mℹ suites 0[39m\n' +
11:01:44             -   '[34mℹ pass 1[39m\n' +
11:01:44             -   '[34mℹ fail 0[39m\n' +
11:01:44             -   '[34mℹ cancelled 0[39m\n' +
11:01:44             -   '[34mℹ skipped 0[39m\n' +
11:01:44             -   '[34mℹ todo 0[39m\n' +
11:01:44             -   '[34mℹ duration_ms *[39m\n' +
11:01:44                 'TAP version 13\n' +
11:01:44             ...
11:01:44                 '# skipped 0\n' +
11:01:44                 '# todo 0\n' +
11:01:44                 '# duration_ms *\n'

Copy link
Member

Choose a reason for hiding this comment

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

changing reporterColorMap to a function might be the easiest fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arbitrary-output-colored test passes on my machine. How can I reproduce the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changing reporterColorMap to a function might be the easiest fix

are you suggesting to replace the map with a function in utils.js or modify the constructor in spec.js?

Copy link
Member

Choose a reason for hiding this comment

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

test passes on my machine. How can I reproduce the error?

with FORCE_COLOR=0 NODE_REGENERATE_SNAPSHOTS=1 ./node test/parallel/test-runner-output.mjs

Copy link
Member

Choose a reason for hiding this comment

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

are you suggesting to replace the map with a function in utils.js or modify the constructor in spec.js?

either will work I think

Copy link
Member

Choose a reason for hiding this comment

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

this might be an easier & cleaner fix:

diff --git a/lib/internal/test_runner/reporter/utils.js b/lib/internal/test_runner/reporter/utils.js
index caa35959ee..42c4ffa3cd 100644
--- a/lib/internal/test_runner/reporter/utils.js
+++ b/lib/internal/test_runner/reporter/utils.js
@@ -28,9 +28,15 @@ const reporterUnicodeSymbolMap = {
 
 const reporterColorMap = {
   '__proto__': null,
-  'test:fail': colors.red,
-  'test:pass': colors.green,
-  'test:diagnostic': colors.blue,
+  get 'test:fail'() {
+    return colors.red;
+  },
+  get 'test:pass'() {
+    return colors.green;
+  },
+  get 'test:diagnostic'() {
+    return colors.blue;
+  },
 };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test passes on my machine. How can I reproduce the error?

with FORCE_COLOR=0 NODE_REGENERATE_SNAPSHOTS=1 ./node test/parallel/test-runner-output.mjs

Still passes all tests :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the suggested changes, please let me know if I need to add anything else.

@RedYetiDev
Copy link
Member

RedYetiDev commented May 5, 2024

Your first commit was 48eecd379b73dc9be0959f2f919254a8c5f11fc8, so maybe try squashing everything after that commit?

Then you can more easier handle conflicts? (Gotten via git pull)

IIRC this correct, but take it with a grain of salt

@mihir254
Copy link
Contributor Author

mihir254 commented May 6, 2024

There are some tests failing for other reasons:
example - node-test-commit-windows-fanned failed
image
How do I go about fixing these errors? Is there a specific file that I need to include? Thanks!

@RedYetiDev
Copy link
Member

There are some tests failing for other reasons: example - node-test-commit-windows-fanned failed image How do I go about fixing these errors? Is there a specific file that I need to include? Thanks!

IIRC you can ignore those, as it's a CI issue, not a PR issue.

@mihir254 mihir254 requested a review from MoLow May 7, 2024 06:02
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 7, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 7, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@MoLow MoLow left a comment

Choose a reason for hiding this comment

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

LGTM. the fix indeed made the tests pass - the failures are unrelated

@nodejs-github-bot
Copy link
Collaborator

@MoLow MoLow added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 7, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels May 7, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/52655
✔  Done loading data for nodejs/node/pull/52655
----------------------------------- PR info ------------------------------------
Title      test_runner: display failed test stack trace with dot reporter (#52655)
Author     Mihir Bhansali  (@mihir254, first-time contributor)
Branch     mihir254:modifying-dot-reporter -> nodejs:main
Labels     author ready, needs-ci, commit-queue-squash, test_runner
Commits    6
 - test_runner: dot reporter displays failed test names
 - lint
 - fix tests
 - test_runner: fix assertions in dot-reporter tests
 - fixed indentation and lint errors
 - test_runner: reporterColorMap changed to map functions
Committers 1
 - Mihir Bhansali 
PR-URL: https://github.com/nodejs/node/pull/52655
Fixes: https://github.com/nodejs/node/issues/51769
Reviewed-By: Matteo Collina 
Reviewed-By: Moshe Atlow 
Reviewed-By: Chemi Atlow 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/52655
Fixes: https://github.com/nodejs/node/issues/51769
Reviewed-By: Matteo Collina 
Reviewed-By: Moshe Atlow 
Reviewed-By: Chemi Atlow 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 23 Apr 2024 17:23:18 GMT
   ✔  Approvals: 3
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/52655#pullrequestreview-2042141691
   ✔  - Moshe Atlow (@MoLow) (TSC): https://github.com/nodejs/node/pull/52655#pullrequestreview-2042377524
   ✔  - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/52655#pullrequestreview-2031600698
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-05-07T08:03:44Z: https://ci.nodejs.org/job/node-test-pull-request/59007/
- Querying data for job/node-test-pull-request/59007/
   ✔  Last Jenkins CI successful
   ⚠  PR author is a new contributor: @mihir254(mbmihirbhansali@gmail.com)
   ⚠  - commit 18eeb02527f3 is authored by moshe@atlow.co.il
   ⚠  - commit 748da16cb019 is authored by moshe@atlow.co.il
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/8983972314

PR-URL: nodejs#52655
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@MoLow MoLow merged commit 69f2ace into nodejs:main May 7, 2024
16 checks passed
@MoLow
Copy link
Member

MoLow commented May 7, 2024

Landed in 69f2ace

@MoLow
Copy link
Member

MoLow commented May 7, 2024

Thanks for the contribution @mihir254 🎉

Ch3nYuY pushed a commit to Ch3nYuY/node that referenced this pull request May 8, 2024
PR-URL: nodejs#52655
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
targos pushed a commit that referenced this pull request May 8, 2024
PR-URL: #52655
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
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. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test_runner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_runner: print failed tests with dot reporter
8 participants