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

Assertion code parsing does not occur using TestContext's assert. #54760

Closed
avivkeller opened this issue Sep 4, 2024 · 0 comments · Fixed by #54776
Closed

Assertion code parsing does not occur using TestContext's assert. #54760

avivkeller opened this issue Sep 4, 2024 · 0 comments · Fixed by #54776
Labels
assert Issues and PRs related to the assert subsystem. test_runner Issues and PRs related to the test runner subsystem.

Comments

@avivkeller
Copy link
Member

avivkeller commented Sep 4, 2024

The following code snippet:

import test from 'node:test';
import assert from 'node:assert';

await test('foo', t => {
  assert.ok("Hello" === "World");
});

Produces the following output:

✖ foo (27.753865ms)
  AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
  
    assert.ok("Hello" === "World")
  
      at TestContext.<anonymous> (file:///repro.mjs:5:10)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:887:25)
      at Test.start (node:internal/test_runner/test:786:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:280:17)
      at async file:///repro.mjs:4:1 {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

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

✖ failing tests:

test at repro.mjs:4:7
✖ foo (27.753865ms)
  AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
  
    assert.ok("Hello" === "World")
  
      at TestContext.<anonymous> (file:///repro.mjs:5:10)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:887:25)
      at Test.start (node:internal/test_runner/test:786:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:280:17)
      at async file:///repro.mjs:4:1 {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

Notice how the error message includes the failing assertion assert.ok("Hello" === "World").

In contrast, the following code snippet:

import test from 'node:test';
import assert from 'node:assert';

await test('foo', t => {
  t.assert.ok("Hello" === "World");
});

Results in a much less descriptive error:

✖ foo (9.450763ms)
  AssertionError [ERR_ASSERTION]: false == true
      at assert.<computed> [as ok] (node:internal/test_runner/test:263:18)
      at TestContext.<anonymous> (file:///repro.mjs:5:12)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:887:25)
      at Test.start (node:internal/test_runner/test:786:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:280:17)
      at async file:///repro.mjs:4:1 {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

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

✖ failing tests:

test at repro.mjs:4:7
✖ foo (9.450763ms)
  AssertionError [ERR_ASSERTION]: false == true
      at assert.<computed> [as ok] (node:internal/test_runner/test:263:18)
      at TestContext.<anonymous> (file:///repro.mjs:5:12)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:887:25)
      at Test.start (node:internal/test_runner/test:786:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:280:17)
      at async file:///repro.mjs:4:1 {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

Notice that this output lacks the detailed error message with the specific failing assertion.

Ref: nodejs/help#4461

@avivkeller avivkeller added assert Issues and PRs related to the assert subsystem. repro-exists test_runner Issues and PRs related to the test runner subsystem. labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant