GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert: adds rejects() and doesNotReject() by feugy · Pull Request #18023 · nodejs/node

Conversation

@feugy

@feugy feugy commented Jan 7, 2018 •
edited by tniessen
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Implement async equivalent of assert.throws() and assert.doesNotThrow().

This PR is a follow-up of #17843, but takes into account James' suggestion to bring this as experimental feature, without change the existing API.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

assert

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label Jan 7, 2018
joyeecheung
joyeecheung reviewed Jan 9, 2018
View reviewed changes
Comment thread lib/assert.js Outdated

@joyeecheung joyeecheung Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: s/conveniency/convenience/?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you 😅

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@joyeecheung joyeecheung Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe name assert.doesNotThrow as a top level function and reference it directly here to avoid being messed up by monkey-patched assert.doesNotThrow

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread lib/assert.js Outdated

@joyeecheung joyeecheung Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe name assert.throws as a top level function and reference it directly here to avoid being messed up by monkey-patched assert.throws

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@feugy feugy Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👌

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@joyeecheung joyeecheung Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Since other assigned APIs do not return promises here:

require('assert').promises.fail().then(() => {}); // does not work

This behavior looks somewhat strange to me..

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

To me as well. I would rather have a dedicated assert.rejects function. Reject is used for promises, so this is a good fit out of my perspective.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's an interesting point.

My intention was to keep the existing behaviour for all assert functions except throws() and doesNotThrow(), which are the only two able to run (potentially async) code.
I wouldn't like to force people writing:

const assert = require('assert').promises

await assert(something)

But we can definitely add new functions like reject() that would be async equivalent of existing one.
Are there any other function you would like to cover?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@joyeecheung joyeecheung Jan 10, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If we are not talking about redesigning a new assert API here, providing a promisified version of the existing assert APIs is good enough to me. Something like

for (const key of Object.keys(assert)) {
  const syncFunc = assert[key];
  promises[key] = async function (...args) { return syncFunc(...args) };
}
// override throws later, or in the block

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 11, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

hum, but it's actually what I'd like to avoid.

There's no point making assert.ok() or assert.fail() asynchronous. It will make the API more cumbersome to use with no benefit.

It make sense for assert.throws() and assert.doesNotThrow() to turn this code (that we used quite a lot in our projects):

it('should report database option errors', async () => {
  try {
    await transferData({}, '');
    throw new Error('it should have failed');
  } catch (err) {
    assert(err.message.includes('"host" is required'));
  }
});

into

it('should report database option errors', async () =>
  assert.throws(async () => transferData({}, ''), /^Error: "host" is required/)
);

I don't want to redesign the whole API, but rather wants to support the above.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BridgeAR
BridgeAR reviewed Jan 9, 2018
View reviewed changes
Comment thread test/parallel/test-assert.js Outdated

@BridgeAR BridgeAR Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why not?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In this PR, you have currently (all synchronous):

  • require('assert').equal
  • require('assert').strict.equal
  • require('assert').promises.equal
  • require('assert').promises.strict.equal

I wasn't sure it worth providing require('assert').strict.promises. Do you think it worth it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Jan 11, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In general strict and regular assert should have exactly the same API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 11, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copy that

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Jan 9, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

To me as well. I would rather have a dedicated assert.rejects function. Reject is used for promises, so this is a good fit out of my perspective.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Jan 9, 2018
@BridgeAR

BridgeAR commented Jan 11, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Because there seems to be a bit of confusion in the discussion:

I personally am strongly against adding a new promise API.

The only thing that should be added out of my perspective are two new functions rejects and doesNotReject. These two would be accessible in both the legacy and strict mode.

They behave similar to the current throws and doesNotThrow functions but they are async instead of sync. No other assert function should be async as there is no reason for it as far as I can tell.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feugy

feugy commented Jan 11, 2018

Copy link
Copy Markdown
Contributor Author

@BridgeAR, by bringing assert.promises, I was following the advise @jasnell gave me on my previous PR.

But what you suggested above makes more sense, so I'm 100% with you, and implement it if @joyeecheung is happy with it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Jan 11, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@feugy If adding asynchronous versions of the synchronous APIs doesn't make sense, then maybe we don't even need to add them to assert.promises. It's fine to only have throws() and doesNotThrow() in assert.promises, and we can work out other APIs later. IMO assert.promises don't need to be feature-complete in this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apapirovski
apapirovski reviewed Jan 11, 2018
View reviewed changes

@apapirovski apapirovski left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is a good start but I'm also in favour of using rejects and doesNotReject instead of a separate promises namespace.

(Worth noting that this would also be in line with the fact that promises emit unhandledRejection rather than uncaughtException.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@apapirovski apapirovski Jan 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can this be moved down closer to trySyncBlock which is its first usage? Or otherwise, move up those two functions here.

I would actually even suggest just inlining this function since it's only used twice. The savings are minimal and now the error thrown will have an extra function in the trace. The latter can be worked around (captureStackTrace) but I don't think it's worth it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@apapirovski apapirovski Jan 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We don't need the common.platformTimeout here. Just matters that it's async.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@apapirovski apapirovski Jan 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nits:
s/doNotThrows()/doesNotThrow()
s/truely/truly
s/other/others

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@apapirovski apapirovski Jan 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

s/or let it bubble/or rethrow.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@apapirovski apapirovski Jan 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

catch (err) or catch (e) is more in line with other usage in the code base.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@feugy
feugy force-pushed the async-assert-throws branch from 447adf8 to c0ba6ad Compare January 11, 2018 23:19
@feugy feugy changed the title assert: asynchronous throws() and doesNotThrow() assert: adds rejects() and doesNotReject() Jan 11, 2018
@feugy

feugy commented Jan 18, 2018

Copy link
Copy Markdown
Contributor Author

Hello gents!

What do you think about the latest update?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Jan 18, 2018
View reviewed changes

@jasnell jasnell left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM if CI is green

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell

jasnell commented Jan 18, 2018

Copy link
Copy Markdown
Member

Hello gents!

quick fyi... we're not all "gents" :-)

joyeecheung and BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feugy

feugy commented Jan 18, 2018

Copy link
Copy Markdown
Contributor Author

Sorry, it's bad habit 😓
I'll start documenting the new functions then.

jasnell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR reviewed Jan 19, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Overall it is already looking very promising to me! Just a few small comments :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is actually a slightly different behavior as before.

Before assert.throws(() => {}, 'foo', undefined) would also result in an error. That is not the case anymore with this change. As this is completely independent from the actual change here, I would rather not have this included, especially as I think this should throw.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You're absolutely right!

To keep this code in an internal function, and not break the existing behaviour, I've used rest params and splat so arguments.length would still make sense.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The comment is actually not correct anymore as it is only a no-op in case actual is the sentinel.

I personally feel like it is not necessary to have these comments here because the code is easy to understand but others might disagree.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👌

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Super tiny nit:

Destructuring would be nice as in const { promisify } = require('util')

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am not totally happy with this test as it does not test that the code does not fail sync.

So I would write something like:

assert.doesNotThrow(() => {
  assert.rejects(
    () => assert.fail(),
    common.expectsError({
      code: 'ERR_ASSERTION',
      type: assert.AssertionError,
      message: 'Failed',
      operator: undefined,
      actual: undefined,
      expected: undefined
    })
  )
});

The same applies to the test below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👌

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If I am not mistaken, we do not know if these really work because the function itself might theoretically execute sync.

So a better test out of my perspective would be:

let promise;
let threw = false;
try {
  promise = assert.doesNotReject(async () => {
    await wait(10);
    assert.fail();
  });
} catch (err) {
  threw = true;
}
assert.strictEqual(threw, false);
assert.rejects(() => promise,
  common.expectsError({
    code: 'ERR_ASSERTION',
    type: assert.AssertionError,
    message: 'Got unwanted exception ... '
    ...
  })
);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👌

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Hm, I would say it tests the functionality of assert.rejects() and assert.doesNotReject() but not that it "ensures" async support for those as they should always be async.

I would describe it as e.g. "Tests assert.rejects() and assert.doesNotReject() by checking their expected output and by verifying that they do not work sync."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Jan 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am a bit surprised that this for the stackStartFn shall work. this should normally refer to either assert.ok or assert.strict.
Can you please write a test for this as well if none exist? :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I added a test, and you were absolutely right.
Providing explicit values keeps the existing stack-traces:

https://github.com/feugy/node/blob/6cdbbe6f520862edda962dbf8507c9e7917bdd1e/test/parallel/test-assert-async.js#L60-L98

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@feugy
feugy force-pushed the async-assert-throws branch 2 times, most recently from 6cdbbe6 to 6779293 Compare January 21, 2018 22:26
BridgeAR
BridgeAR reviewed Jan 23, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The code change itself looks very good now! Just the tests might need a bit more polishing :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Super super tiny nit: you can actually access the own function without assert. It would just save some characters.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Leko reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@joyeecheung joyeecheung Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It also keep you away from monkey-patching. I would prefer referencing it directly here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: It would be really nice if the error message is changed to Missing expected rejection.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The two tests above are already tested for in test-assert.js. This adds the check for the error stack, so it indeed tests something new, but in that case I would rather replace the ones in test-assert.js with these tests instead of "duplicating" them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This tests the same as https://github.com/nodejs/node/pull/18023/files#diff-cdf49dc677a8ea6f00de9f95639355e8R44.
What was not yet tested for is if the functions throws sync.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Using a async function as wrapper will actually hide if the function is executed sync or async. So I would just use the pattern as above without the async wrapper.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR

BridgeAR commented Jan 23, 2018

Copy link
Copy Markdown
Member

@feugy thanks a lot for being so patient!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Leko
Leko approved these changes Jan 23, 2018
View reviewed changes

@Leko Leko left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
joyeecheung
joyeecheung approved these changes Jan 23, 2018
View reviewed changes
Comment thread lib/assert.js Outdated

@joyeecheung joyeecheung Jan 23, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It also keep you away from monkey-patching. I would prefer referencing it directly here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@joyeecheung

joyeecheung commented Jan 23, 2018

Copy link
Copy Markdown
Member

LGTM with @BridgeAR 's comments addressed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maclover7
maclover7 force-pushed the master branch from bb5575a to 993b716 Compare January 26, 2018 22:02
@cjihrig
cjihrig force-pushed the master branch from 993b716 to 082f952 Compare January 26, 2018 22:36
@feugy
feugy force-pushed the async-assert-throws branch from 6779293 to 4f2a349 Compare January 27, 2018 14:56
feugy
feugy commented Jan 27, 2018
View reviewed changes
Comment thread doc/api/assert.md Outdated

@feugy feugy Jan 27, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe the next lines (copied from assert.doesNotThrow() doc) may be skipped in favour of a reference?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree. I would actually even go so far and remove everything from here on. A text like:

Besides the async nature to await the completion it behaves identical to `assert.doesNotThrow()`.

Keep an example with async await and also maybe add a example using promises.

The same can be applied to the reject function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
feugy
feugy commented Jan 27, 2018
View reviewed changes
Comment thread lib/assert.js Outdated

@feugy feugy Jan 27, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

operator & message will now contain appropriate values

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There is the unwritten rule to not use multi line template strings in Node.js. This does look somewhat elegant but it is probably best to just have something like: Missing expected ${fnType}${details}.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
feugy
feugy commented Jan 27, 2018
View reviewed changes
Comment thread test/parallel/test-assert.js Outdated

@feugy feugy Jan 27, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I wasn't confident to replace common.expectsError() with such custom assertions, but couldn't find a better way to reuse the existing test, as suggested.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would actually just keep this as is and just add a single line to one of the existing tests that checks for assert.ok(!err.stack.includes('at throws').

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BridgeAR
BridgeAR reviewed Feb 2, 2018
View reviewed changes
Comment thread doc/api/assert.md Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This exceeds 80 characters.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit (non-blocking): I personally prefer the following to save lines:

assert.throws = function throws(block, ...args) {
  expectsError(throws, getActual(block), ...args);
};

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feugy feugy Feb 3, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I also prefer function expressions.
But even named, function expression do not benefit from hoisting.

This would imply to use assert.doesNotReject() here, and here.

Same goes for other functions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Feb 6, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good point. We could check for the function name instead but that could theoretically be manipulated.

So just keep it as is. Thanks for the heads up.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Feb 6, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Hm, while looking at the code again: we actually already use the function name and do not strictly test if it it a "valid" function. So we could indeed just switch to name checking only.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/assert.md Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree. I would actually even go so far and remove everything from here on. A text like:

Besides the async nature to await the completion it behaves identical to `assert.doesNotThrow()`.

Keep an example with async await and also maybe add a example using promises.

The same can be applied to the reject function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/assert.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There is the unwritten rule to not use multi line template strings in Node.js. This does look somewhat elegant but it is probably best to just have something like: Missing expected ${fnType}${details}.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am relatively certain that this is going to trigger a lint error. The err should probably be in parentheses. The same applies to the test below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

After thinking about this again, the try catch and the threw is not necessary here at all. If the promise throws the test would fail right away. threw is only necessary for tests that check for threw === true. So the tests can be much smaller (I know I originally suggested this pattern).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The wrapper is not needed as the test would fail right away if assert.rejects would fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert-async.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The wrapper is not needed due to the reason mentioned above.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would actually just keep this as is and just add a single line to one of the existing tests that checks for assert.ok(!err.stack.includes('at throws').

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-assert.js Outdated

@BridgeAR BridgeAR Feb 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Hm, I am not certain if that is actually true? I thought that frame would actually be excluded? Do the tests pass?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@feugy
feugy force-pushed the async-assert-throws branch from 4f2a349 to 556ecdc Compare February 3, 2018 14:40
@apapirovski

apapirovski commented Mar 2, 2018

Copy link
Copy Markdown
Contributor

@BridgeAR It seems to me like rejections have slightly different semantics than throw. Since it's currently possible to just entirely ignore unhandledRejection in our code, I can see a use for doesNotReject. Just IMO of course...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Mar 2, 2018

Copy link
Copy Markdown
Member

@apapirovski I agree that it is not exactly the same but the reason for that is that we have another issue that has to be solved as well. See #15126.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski

apapirovski commented Mar 2, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@BridgeAR Yeah, I'm aware and have dug around in that PR, actually, but that code will take a while to land given the performance implications. I'm not really certain we have a great path forward that doesn't impact performance. Maybe I'm wrong...

(I have some thoughts on how to do it without all of the C++ boundary crossing but only theoretical atm.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski

apapirovski commented Mar 5, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@BridgeAR given that this is only semver-minor whereas any changes to uncaught Promise handling would be semver-major, do you think it would be ok to land as is? Especially in the light of the recent rejection of the doesNotThrow deprecation?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski

apapirovski commented Mar 5, 2018

Copy link
Copy Markdown
Contributor

CI: https://ci.nodejs.org/job/node-test-pull-request/13496/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Mar 5, 2018

Copy link
Copy Markdown
Member

@apapirovski yes, I am now ok with landing it as is. I will open another PR to add a comment to it similar to doesNotThrow afterwards.

@feugy thanks a lot for your work and for being patient :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feugy

feugy commented Mar 6, 2018

Copy link
Copy Markdown
Contributor Author

It's all fine!
I'll resolve the conflict soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feugy
assert: add rejects() and doesNotReject()
7a94ce8
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().
@feugy
feugy force-pushed the async-assert-throws branch from 0a031d0 to 7a94ce8 Compare March 10, 2018 08:31
@feugy

feugy commented Mar 10, 2018

Copy link
Copy Markdown
Contributor Author

And done! What's next?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Mar 11, 2018
@feugy @BridgeAR
assert: add rejects() and doesNotReject()
599337f
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().

PR-URL: nodejs#18023
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@BridgeAR

BridgeAR commented Mar 11, 2018

Copy link
Copy Markdown
Member

Landed in 599337f 🎉

I removed the experimental as I do not really see that and fixed a typo in the docs while landing.

feugy reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR closed this Mar 11, 2018
@feugy feugy mentioned this pull request Mar 17, 2018
Instrumenting assert.throws() power-assert-js/espower#39
Closed
@MylesBorins MylesBorins added the backport-requested-v9.x label Mar 20, 2018
@MylesBorins

MylesBorins commented Mar 20, 2018

Copy link
Copy Markdown
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@not-an-aardvark not-an-aardvark mentioned this pull request Mar 28, 2018
assert: ensure .rejects() disallows sync throws #19650
Closed
3 tasks done
@targos targos mentioned this pull request Apr 2, 2018
assert: add warning about assert.doesNotReject #19462
Closed
4 tasks done
@not-an-aardvark

not-an-aardvark commented Apr 4, 2018

Copy link
Copy Markdown
Contributor

If this gets backported, it should be backported at the same time as #19650 (possibly in the same commit).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
@feugy @BridgeAR
assert: add rejects() and doesNotReject()
3b4f4c4
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().

PR-URL: nodejs#18023
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
@feugy @MayaLekova
assert: add rejects() and doesNotReject()
c0dd4b5
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().

PR-URL: nodejs#18023
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins added the dont-land-on-v8.x label Aug 7, 2018
@MylesBorins MylesBorins removed the dont-land-on-v8.x label Nov 1, 2018
@MylesBorins MylesBorins mentioned this pull request Nov 1, 2018
[v8.x] backport assert: add rejects() and doesNotReject() #24019
Closed
4 tasks
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Nov 1, 2018
@feugy @MylesBorins
assert: add rejects() and doesNotReject()
4ee80bc
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().

PR-URL: nodejs#18023
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 4, 2018
@feugy @MylesBorins
assert: add rejects() and doesNotReject()
3babc5b
Implement asynchronous equivalent for assert.throws() and
assert.doesNotThrow().

Backport-PR-URL: #24019
PR-URL: #18023
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@BethGriggs BethGriggs mentioned this pull request Nov 12, 2018
v8.13.0 proposal #23974
Merged
@beevelop beevelop mentioned this pull request Nov 20, 2018
2018-11-20 Version 8.13.0 'Carbon' (LTS) @MylesBorins prepared by @BethGriggs beevelop/docker-android-nodejs#250
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 8, 2026
feat: implement basic expressions, function calls and literals Seddryck/Expressif.Syntax#2
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BridgeAR BridgeAR BridgeAR approved these changes
@jasnell jasnell jasnell approved these changes
@joyeecheung joyeecheung joyeecheung approved these changes
+2 more reviewers
@apapirovski apapirovski apapirovski left review comments
@Leko Leko Leko approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

assert Issues and PRs related to the assert subsystem. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@feugy @BridgeAR @joyeecheung @jasnell @apapirovski @MylesBorins @not-an-aardvark @Leko @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.