Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: improve assert.markdown copy #4360

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Dec 20, 2015

General improvements to assert.markdown, including examples

@jasnell jasnell added the doc Issues and PRs related to the documentations. label Dec 20, 2015
@mscdex mscdex added the assert Issues and PRs related to the assert subsystem. label Dec 20, 2015
`require('assert')`. However, it is recommended that a userland assertion
library be used instead.
The `assert` module was originally written and included in Node.js in order
to facilitate Node.js' own unit tests. While it can be used by JavaScript
Copy link
Member

Choose a reason for hiding this comment

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

Node.js' own unit tests -> unit tests for Node.js itself.

Copy link
Member

Choose a reason for hiding this comment

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

Nit to facilitate -> for use with

@jasnell
Copy link
Member Author

jasnell commented Dec 20, 2015

@Trott ... updated per your feedback. PTAL

library be used instead.
The `assert` module is for use with Node.js' own unit tests. While it can be
used by JavaScript running within Node.js by using `require('assert')`, it is
recommended that a third-party ("userland") assertion module be used instead.
Copy link
Member

Choose a reason for hiding this comment

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

At a minimum, I would remove by JavaScript running so you just have:

While it can be used within Node.js by using require('assert'), it is recommended that a....

Copy link
Member

Choose a reason for hiding this comment

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

third-party may be problematic. If the user writes their own userland assertion module, then it's second-party, right? I may be overthinking this.

@jasnell
Copy link
Member Author

jasnell commented Dec 21, 2015

@Trott ... fixed!

@jasnell
Copy link
Member Author

jasnell commented Dec 23, 2015

@nodejs/ctc @nodejs/collaborators ... can I please get some additional review on this one

This module is used so that Node.js can test itself. It can be accessed with
`require('assert')`. However, it is recommended that a userland assertion
library be used instead.
The `assert` module is for use with Node.js' own unit tests. While it can be
Copy link
Contributor

Choose a reason for hiding this comment

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

Node.js's

Copy link
Member

Choose a reason for hiding this comment

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

The tendency to favor Node.js' over Node.js's is so strong that I don't even bother correcting it directly and instead recommend rewording entirely to avoid the possessive. So, for example, something like:

The assert module is for use with unit tests in the source code for Node.js.

@jasnell
Copy link
Member Author

jasnell commented Dec 23, 2015

@domenic @Trott ... fixed.

This module is used so that Node.js can test itself. It can be accessed with
`require('assert')`. However, it is recommended that a userland assertion
library be used instead.
The `assert` module is for use with the unit tests in the Node.js source.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is also used (in node's own source and by others), as it is used in C and other languages: to assert invariants in the code. There are lots of unit testing modules around, but I'm not aware of an alternate module for this use. We should avoid characterizing this as a bad unit test library, even if that's one of the things node uses it for.

@jasnell
Copy link
Member Author

jasnell commented Dec 24, 2015

@sam-github ... made another revision to that intro paragraph. PTAL

potentially surprising results. For example, this does not throw an
`AssertionError` because the properties on the [`Error`][] object are
non-enumerable:
Only considers enumerable "own" properties are considered. The `deepEqual()`
Copy link
Contributor

Choose a reason for hiding this comment

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

considers is used twice in this sentence and sounds a bit odd

should it be
Only enumerable "own" properties are considered

Copy link
Member Author

Choose a reason for hiding this comment

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

heh.. whoops

@jasnell
Copy link
Member Author

jasnell commented Dec 24, 2015

@thealphanerd ... fixed!

The API for the `assert` module is [Locked][]. This means that there will be no
additions or changes to any of the methods implemented and exposed by
the module. It is recommended that an alternative ("userland" or third-party)
assertion module be used instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

I assert ;-) that no such modules exist for the purpose for which assert is well-suited, and arguably intended, in-source assertions of invariants.

Can you point to examples of userland modules for this purpose, @jasnell?

Pointing people writing unit tests elsewhere is a good idea, there are lots of unit test frameworks around.

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 cannot. This is just an edit of the existing text. I'd be fine with
removing the recommendation
On Dec 23, 2015 10:03 PM, "Sam Roberts" [email protected] wrote:

In doc/api/assert.markdown
#4360 (comment):

@@ -2,42 +2,130 @@

 Stability: 3 - Locked

-This module is used so that Node.js can test itself. It can be accessed with
-require('assert'). However, it is recommended that a userland assertion
-library be used instead.
+While the assert module is generally intended for internal use by Node.js
+itself, it can be used by user code calling require('assert').
+
+The API for the assert module is [Locked][]. This means that there will be no
+additions or changes to any of the methods implemented and exposed by
+the module. It is recommended that an alternative ("userland" or third-party)
+assertion module be used instead.

I assert ;-) that no such modules exist for the purpose for which assert
is well-suited, and arguably intended, in-source assertions of invariants.

Can you point to examples of userland modules for this purpose, @jasnell
https://github.com/jasnell?

Pointing people writing unit tests elsewhere is a good idea, there are
lots of unit test frameworks around.


Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/4360/files#r48397585.

Copy link
Member

Choose a reason for hiding this comment

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

Nit: no scare quotes around userland

@jasnell
Copy link
Member Author

jasnell commented Dec 24, 2015

@sam-github @Trott ... updated and removed that recommendation.

`assert.equal(!!value, true, message)`.

If `value` is not truthy, an `AssertionError` is thrown with a `message`
property set equal to the value of the `message` parameter. If the `message`
parameter is undefined, a default error message is assigned.
Copy link
Contributor

Choose a reason for hiding this comment

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

undefined

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's see if u I remember how to do this. You mean: undefined

EDIT: auto correct fix.

General improvements to assert.markdown copy including
new and improved examples
@jasnell
Copy link
Member Author

jasnell commented Dec 28, 2015

@thefourtheye @trevnorris ... fixed, commits squashed. PTAL

@trevnorris
Copy link
Contributor

LGTM

jasnell added a commit that referenced this pull request Dec 28, 2015
General improvements to assert.markdown copy including
new and improved examples

PR-URL: #4360
Reviewed-By: Trevor Norris <[email protected]>
@jasnell
Copy link
Member Author

jasnell commented Dec 28, 2015

Landed in 3e648eb

@jasnell jasnell closed this Dec 28, 2015
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request Jan 6, 2016
General improvements to assert.markdown copy including
new and improved examples

PR-URL: nodejs#4360
Reviewed-By: Trevor Norris <[email protected]>
jasnell added a commit that referenced this pull request Jan 7, 2016
General improvements to assert.markdown copy including
new and improved examples

PR-URL: #4360
Reviewed-By: Trevor Norris <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
General improvements to assert.markdown copy including
new and improved examples

PR-URL: #4360
Reviewed-By: Trevor Norris <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jan 19, 2016
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
General improvements to assert.markdown copy including
new and improved examples

PR-URL: nodejs#4360
Reviewed-By: Trevor Norris <[email protected]>
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. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants