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: fix global after not failing the tests #48913

Merged

Conversation

rluvaton
Copy link
Member

@rluvaton rluvaton commented Jul 25, 2023

Fix: #48867

I'm not sure about the solution, WDYT? 🤔

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@rluvaton rluvaton marked this pull request as ready for review July 25, 2023 08:17
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jul 25, 2023
@rluvaton rluvaton marked this pull request as draft July 25, 2023 08:17
@rluvaton rluvaton marked this pull request as ready for review July 25, 2023 08:23
@rluvaton rluvaton marked this pull request as draft July 25, 2023 08:24
@rluvaton rluvaton marked this pull request as ready for review July 25, 2023 18:12
---
duration_ms: *
...
not ok 0 - <root>
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should change this name. @cjihrig WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the root test should even show up in the output like this because users will have no clue what it is (the root test is basically an implementation detail). For failed global hooks, I think we should try to do something similar to what we do when we run a test file with no tests that exits with non-zero.

In case it's not clear what I mean:

// foo.js
process.exit(1);
$ node --test foo.js
✖ /private/tmp/foo.js (23.390208ms)
  'test failed'

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 27.586916

✖ failing tests:

✖ /private/tmp/foo.js (23.390208ms)
  'test failed'

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, can you take a look?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I should have been a bit more explicit. When I said "something similar" I meant specify the name of the hook, not the filename. For example, "global after hook" or something alone those lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

When the before failed we have:

'use strict';
const { it, before } = require('node:test');

before(() => {
  throw new Error('this should fail the test')
});

it('this is a test', () => {
  console.log('this is a test')
});
✖ this is a test (0.679959ms)
  Error: this should fail the test
      at TestContext.<anonymous> (/Users/rluvaton/dev/open-source/node/node-fork/test/fixtures/test-runner/output/global_after_should_fail_the_test.js:5:9)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:581:25)
      at TestHook.run (node:internal/test_runner/test:774:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:517:20
      at async Test.runHook (node:internal/test_runner/test:515:7)
      at async Test.run (node:internal/test_runner/test:554:9)
      at async startSubtest (node:internal/test_runner/harness:204:3)

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 116.542583

✖ failing tests:

✖ this is a test (0.679959ms)
  Error: this should fail the test
      at TestContext.<anonymous> (/Users/rluvaton/dev/open-source/node/node-fork/test/fixtures/test-runner/output/global_after_should_fail_the_test.js:5:9)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:581:25)
      at TestHook.run (node:internal/test_runner/test:774:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:517:20
      at async Test.runHook (node:internal/test_runner/test:515:7)
      at async Test.run (node:internal/test_runner/test:554:9)
      at async startSubtest (node:internal/test_runner/harness:204:3)

Copy link
Contributor

@cjihrig cjihrig Jul 25, 2023

Choose a reason for hiding this comment

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

With Node 20.5.0, a failing global before() fails the test run with the same error shown in #48913 (comment). I pulled down this PR locally, and verified there is no difference.

With Node 20.5.0, a failing global after() does not fail the test run, and is a bug. This PR does address that, but the failure should be more accurate IMO:

this is a test
✔ this is a test (1.356584ms)
✖ /tmp/foo.js (0.22ms)
  Error: this should fail the test
      at TestContext.<anonymous> (/private/tmp/foo.js:5:9)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:581:25)
      at TestHook.run (node:internal/test_runner/test:774:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:517:20
      at async Test.runHook (node:internal/test_runner/test:515:7)
      at async after (node:internal/test_runner/test:543:9)
      at async Test.run (node:internal/test_runner/test:591:7)
      at async process.exitHandler (node:internal/test_runner/harness:144:5)

ℹ tests 1
ℹ suites 0
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 0.22

✖ failing tests:

✖ /tmp/foo.js (0.22ms)
  Error: this should fail the test
      at TestContext.<anonymous> (/private/tmp/foo.js:5:9)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:581:25)
      at TestHook.run (node:internal/test_runner/test:774:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:517:20
      at async Test.runHook (node:internal/test_runner/test:515:7)
      at async after (node:internal/test_runner/test:543:9)
      at async Test.run (node:internal/test_runner/test:591:7)
      at async process.exitHandler (node:internal/test_runner/harness:144:5)

Just looking at that output, I would have no idea that the failure is because the after hook failed. That is important information for users. That's what I'm saying we need to change in #48913 (comment).

EDIT: More specifically, it would be good if ✖ /tmp/foo.js (0.22ms) in this example said ✖ global after hook (0.22ms)

Copy link
Member

Choose a reason for hiding this comment

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

More specifically, it would be good if ✖ /tmp/foo.js (0.22ms) in this example said ✖ global after hook (0.22ms)

it has a failureType: 'hookFailed' , wich is printed in case of the tap reporter, but in spec we seem to omit it.
still - there is a stack trace, isnt that good enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean it's better than the existing bug, but seems like something we could improve 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally, I would prefer each hook that failed to tell that it failed from that hook

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be in a different PR, and in that PR I would also align the before to match the right behavior...

@MoLow MoLow requested a review from cjihrig July 25, 2023 18:55
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

@rluvaton
Copy link
Member Author

The test test/parallel/test-runner-cli.js is failing as it picked up new test files, #48787 would have fixed that

@MoLow MoLow added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 26, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 26, 2023
@nodejs-github-bot
Copy link
Collaborator

@MoLow
Copy link
Member

MoLow commented Jul 27, 2023

@rluvaton the new tests seem to fail on windows https://ci.nodejs.org/job/node-test-binary-windows-js-suites/22188/RUN_SUBSET=1,nodes=win2012r2-COMPILED_BY-vs2019-x86/console

00:29:13         not ok 7 - test-runner/output/global_after_should_fail_the_test.js
00:29:13           ---
00:29:13           duration_ms: 780.562048
00:29:13           failureType: 'testCodeFailure'
00:29:13           error: |-
00:29:13             Expected values to be strictly equal:
00:29:13             + actual - expected ... Lines skipped
00:29:13             
00:29:13               'this is a test\n' +
00:29:13                 'TAP version 13\n' +
00:29:13             ...
00:29:13                 '  duration_ms: *\n' +
00:29:13                 '  ...\n' +
00:29:13             +   'not ok 2 - C:\\\\workspace\\\\node-test-binary-windows-js-suites\\\\node\\\\test\\\\fixtures\\\\test-runner\\\\output\\\\global_after_should_fail_the_test.js\n' +
00:29:13             -   'not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.js\n' +
00:29:13                 '  ---\n' +
00:29:13             ...
00:29:13                 '# skipped 0\n' +
00:29:13                 '# todo 0\n' +
00:29:13                 '# duration_ms *\n'

@rluvaton
Copy link
Member Author

I pushed a fix, hope this would work

@MoLow
Copy link
Member

MoLow commented Jul 27, 2023

@rluvaton commits like this dont actually trigger the CI

@rluvaton
Copy link
Member Author

What would you do to trigger a CI?

@nodejs-github-bot nodejs-github-bot merged commit c58e8fc into nodejs:main Aug 2, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in c58e8fc

@rluvaton rluvaton deleted the fix-after-not-failing-the-root-test branch August 2, 2023 20:06
pluris pushed a commit to pluris/node that referenced this pull request Aug 6, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
pluris pushed a commit to pluris/node that referenced this pull request Aug 7, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this pull request Aug 14, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
RafaelGSS pushed a commit that referenced this pull request Aug 15, 2023
PR-URL: #48913
Fixes: #48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
RafaelGSS pushed a commit to RafaelGSS/node that referenced this pull request Aug 15, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
rluvaton added a commit to rluvaton/node that referenced this pull request Aug 15, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@RafaelGSS RafaelGSS added the backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. label Aug 17, 2023
@RafaelGSS
Copy link
Member

Due to fact, #48877 didn't land cleanly on v20.x-staging. This PR somehow, depends on it. So we'll need a manual backport.

Reference: https://github.com/nodejs/node/blob/main/doc/contributing/backporting-to-release-lines.md

rluvaton added a commit to rluvaton/node that referenced this pull request Aug 18, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@rluvaton rluvaton added backport-open-v20.x Indicate that the PR has an open backport and removed backport-requested-v20.x PRs awaiting manual backport to the v20.x-staging branch. labels Aug 18, 2023
@rluvaton
Copy link
Member Author

rluvaton added a commit to rluvaton/node that referenced this pull request Sep 4, 2023
PR-URL: nodejs#48913
Fixes: nodejs#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
UlisesGascon pushed a commit that referenced this pull request Sep 10, 2023
PR-URL: #48913
Backport-PR-URL: #49225
Fixes: #48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@UlisesGascon UlisesGascon mentioned this pull request Sep 10, 2023
@targos targos added backported-to-v20.x PRs backported to the v20.x-staging branch. and removed backport-open-v20.x Indicate that the PR has an open backport labels Nov 12, 2023
targos pushed a commit that referenced this pull request Nov 27, 2023
PR-URL: #48913
Backport-PR-URL: #49225
Fixes: #48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48913
Backport-PR-URL: nodejs/node#49225
Fixes: nodejs/node#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#48913
Backport-PR-URL: nodejs/node#49225
Fixes: nodejs/node#48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@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. backported-to-v20.x PRs backported to the v20.x-staging branch. 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 Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

after not failing the root test
9 participants