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

Sync with Node.js master #44

Merged
merged 131 commits into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
7e03626
Nuke everything
lukechilds Apr 11, 2019
81f7a51
Setup project with latest Node.js assert
lukechilds Apr 11, 2019
f0459c7
Add tests from Node.js master
lukechilds Apr 11, 2019
35d0687
Add tape wrapper to run all Node.js tests
lukechilds Apr 11, 2019
c859c25
Add test/common from Node.js master
lukechilds Apr 11, 2019
531c948
Fix markdown formatting
lukechilds Apr 11, 2019
a7bbffa
Delete .out files
lukechilds Apr 12, 2019
1812064
Don't catch warnings
lukechilds Apr 12, 2019
13705e5
Don't crash the process on unhandled rejections
lukechilds Apr 12, 2019
e48ac96
Added assert test fixtures
lukechilds Apr 12, 2019
002f90a
Don't use internal Node.js functionality in test/parallel/test-assert.js
lukechilds Apr 16, 2019
7fb556c
Remove failing stacktrace test
lukechilds Apr 16, 2019
180e659
Test against Node.js v12.0.0-rc.1 on Travis
lukechilds Apr 16, 2019
534807d
Add internal/errors.js
lukechilds Apr 16, 2019
fc589c5
Move internal dependencies from internal/errors.js
lukechilds Apr 16, 2019
00dc6d5
Test userland assert and Node.js core assert
lukechilds Apr 17, 2019
ca9dfd4
Add internal/assert/assertion_error.js
lukechilds Apr 17, 2019
4561702
Remove internal dependencies from internal/assert/assertion_error.js
lukechilds Apr 17, 2019
d2b2815
Remove internal/util/inspect dependency
lukechilds Apr 17, 2019
aff2924
Add required functionality from internal/util/types
lukechilds Apr 17, 2019
841653d
Add internal/constants.js
lukechilds Apr 17, 2019
989ec48
Don't try and skip native modules
lukechilds Apr 17, 2019
3dd7736
Add lib/internal/util/comparisons.js
lukechilds Apr 17, 2019
52e8b60
Remove internal dependencies from internal/util/comparisons.js
lukechilds Apr 18, 2019
d97f564
Use 'util.types' over './internal/util/types'
lukechilds Apr 18, 2019
0fa9c35
Access prototype methods correctly
lukechilds Apr 18, 2019
256f4a5
Uncurry Object prototype methods
lukechilds Apr 18, 2019
95c2a11
Add acorn and acorn-walk deps
lukechilds Apr 19, 2019
7f9913a
Add an assert loader module to ensure tests always get the correct as…
lukechilds Apr 19, 2019
4e1a419
Simplify Travis tests
lukechilds Apr 19, 2019
ebc6fcf
Use userland buffer implementation
lukechilds Apr 19, 2019
942cec7
Use userland util.inspect and don't enforce error message tests
lukechilds Apr 29, 2019
749841c
Don't generate error messages from sourcefiles on filesytem
lukechilds Apr 29, 2019
ad08be4
Remove dead code and unused dependencies after disabling source error…
lukechilds Apr 29, 2019
882a8f2
Remove worker_threads dependency
lukechilds Apr 30, 2019
b6ac118
Remove dead code from test/common/index.js
lukechilds Apr 30, 2019
91e77d3
Loosen check on stack content
lukechilds Apr 30, 2019
49e82eb
Don't use modern try catch syntax without error
lukechilds Apr 30, 2019
34576bd
Use @lukechilds/util until util.types PR is merged and updated
lukechilds Apr 30, 2019
e8fcf5b
Make sure unhandled rejections fail the tests
lukechilds Apr 30, 2019
59d4762
Correctly report failed async tests
lukechilds Apr 30, 2019
8fd9244
Update util to version with stricter Promise check
lukechilds Apr 30, 2019
d83e6c8
Don't get call site
lukechilds Apr 30, 2019
4dc5788
Check get process.stderr.getColorDepth exists before calling it
lukechilds Apr 30, 2019
be82ea8
Don't let BigInt cause syntax errors in unsupported environments
lukechilds Apr 30, 2019
3ae25ae
Skip color tests in environments where process.stderr.getColorDepth i…
lukechilds Apr 30, 2019
80883d7
Remove more dead code from test/common/index.js
lukechilds May 1, 2019
690a253
Clarify commented out test
lukechilds May 1, 2019
1943c34
Remove filesystem tests
lukechilds May 1, 2019
36ebeef
Convert async functions to Promise returning functions
lukechilds May 1, 2019
a73e9fc
Add airtap
lukechilds May 1, 2019
1ad38b9
Remove first line tests
lukechilds May 1, 2019
ec9a26b
Remove glob dependency in tests
lukechilds May 1, 2019
769a400
Create require wrapper so browserify can resolve test files
lukechilds May 1, 2019
c6b42a1
Remove assert-loader
lukechilds May 1, 2019
05db8d1
Check process.stdout process.stderr exist before accessing isTTY
lukechilds May 1, 2019
c4f805a
Check process.stderr exists before accessing getColorDepth
lukechilds May 1, 2019
e8b1454
Don't compare against fake process/global when in browser environment
lukechilds May 1, 2019
5d4a2d7
Fallback to console.warn if process.emitWarning doesn't exist
lukechilds May 1, 2019
c0a8b57
Setup stderr params to check position indicator
lukechilds May 1, 2019
831da4e
Check Error.captureStackTrace is available before calling
lukechilds May 1, 2019
e3c6cd2
Loosen stack checks in browser tests
lukechilds May 1, 2019
b66acad
Skip typed array tests for unsupported types
lukechilds May 1, 2019
a8bb28c
Disable more message tests
lukechilds May 1, 2019
1048c9c
Use browserify util now util.types support is merged
lukechilds May 2, 2019
584a70f
Fix conditional typed array tests
lukechilds May 2, 2019
5b80664
Relace error comparison tests for browsers
lukechilds May 2, 2019
37af185
Comment out failing Safari test
lukechilds May 2, 2019
507dd93
Don't strictly compare different error objects
lukechilds May 2, 2019
b61b165
Add transpilation build step
lukechilds May 2, 2019
9396f70
Require assert file directly so path can be resolved once transpiled
lukechilds May 2, 2019
3e5c87b
Ensure source is always built before tests are run
lukechilds May 2, 2019
73c7970
Enable testing without rebuilding
lukechilds May 3, 2019
b37b3c9
Add source files test script
lukechilds May 3, 2019
1e22927
Implement internal/errors.js like in readable-stream
lukechilds May 3, 2019
9d3becd
Add error code in constructor
lukechilds May 3, 2019
f4c09e2
Use Object.getOwnPropertyDescriptor shim
lukechilds May 3, 2019
7e753f3
Remove uneeded code from internal errors
lukechilds May 3, 2019
5fac364
Move object.getownpropertydescriptors to devDependencies
lukechilds May 3, 2019
7f7ce29
Fallback to toString check if regex falgs are unsupported
lukechilds May 3, 2019
5fe29a6
Make sure getTime is never called on a non-date object
lukechilds May 3, 2019
ff7e7c6
Skip proxy tests if proxies are unsupported
lukechilds May 3, 2019
cdba9c9
Revert "Use Object.getOwnPropertyDescriptor shim"
lukechilds May 3, 2019
1e2a19c
Only use getOwnPropertyDescriptors shim when unsupported natively
lukechilds May 3, 2019
b85ee43
Revert "Make sure getTime is never called on a non-date object"
lukechilds May 3, 2019
c966391
Simplify RegExp if statement
lukechilds May 3, 2019
b94b20b
Skip Symbol.toStringTag tests if unsupported
lukechilds May 3, 2019
4c0cf19
Conditionally load polyfills required for testing
lukechilds May 3, 2019
5640ef1
Test against Node.js 12, 10, 8, 6
lukechilds May 3, 2019
c56d5a4
Add airtap browser testing
lukechilds May 3, 2019
b0d4319
babel env should have EdgeHTML version not Edger browser version
lukechilds May 4, 2019
f29b01e
Don't worry if some browsers have less accurate stacks
lukechilds May 4, 2019
73bfbbd
Don't test error type, this will fail in older browsers, testing the …
lukechilds May 4, 2019
d3eabae
Add dev build script
lukechilds May 4, 2019
dc0ffec
Conditionally use Object.assign shim
lukechilds May 4, 2019
f794ca4
Conditionally use Object.is shim
lukechilds May 4, 2019
3361aac
Prefer forEach over for of so it doesn't require Symbol once transpiled
lukechilds May 4, 2019
5489eaf
Use String.endsWith shim
lukechilds May 4, 2019
64b13ad
Return empty array for Object.getOwnPropertySymbols if it doesn't exist
lukechilds May 4, 2019
80cf08a
Remove for of loops so transpiled source doens't require Symbol.iterator
lukechilds May 4, 2019
208ed6e
Shim String.repeat
lukechilds May 4, 2019
8756e80
Shim String.includes
lukechilds May 4, 2019
e0d1daa
Don't check error messages
lukechilds May 4, 2019
236d57c
Disable more error.message and error.operator tests
lukechilds May 4, 2019
4e62553
Move array-from to dev dependencies
lukechilds May 5, 2019
c40e528
Remove more error.operator tests
lukechilds May 5, 2019
4e28243
Skip Symbol tests if Symbol is unsupported
lukechilds May 5, 2019
2f912be
Prefer forEach over for of so it doesn't require Symbol once transpiled
lukechilds May 5, 2019
43b94b7
Remove remaining for of loops
lukechilds May 5, 2019
5ca2494
Use startsWith shim
lukechilds May 5, 2019
e5a82e3
Conditionally shim Number.isNaN
lukechilds May 5, 2019
4f9e5d9
Shim Array.fill
lukechilds May 5, 2019
f46eea3
Disable another message test
lukechilds May 5, 2019
ad955fa
Allow creating Maps/Sets from arrays in IE
lukechilds May 5, 2019
d4a0766
Don't rely on entries or values iterators to create arrays
lukechilds May 5, 2019
cbcb1ef
Stop false early return triggering in IE
lukechilds May 5, 2019
31cf2c9
Only test Symbol if it's supported
lukechilds May 5, 2019
198f473
Exit early for IE if we detect a type mismatch
lukechilds May 5, 2019
b224393
Update readme
lukechilds May 6, 2019
b713ab7
Add contribution docs to readme
lukechilds May 6, 2019
7e5079f
Fix npm badges
lukechilds May 6, 2019
e74df3e
Fix typo
lukechilds May 6, 2019
3e94cfd
Reduce heading size
lukechilds May 6, 2019
759faf8
Simplify String.repeat shim
lukechilds May 6, 2019
548c2a9
Add better commenting regrding test removals
lukechilds May 6, 2019
0a71309
Remove buffer dependency in favour of Buffer.compare shim
lukechilds May 10, 2019
c5da086
Run build script on npm prepare event
lukechilds May 11, 2019
4554bbf
Only include production files in npm releases
lukechilds May 12, 2019
f799c89
Revert version number change in package.json
lukechilds May 12, 2019
3d79914
Merge branch 'master' into sync-with-node-master
lukechilds May 12, 2019
e1cbf4d
Update babel IE target version to 11
lukechilds May 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .zuul.yml → .airtap.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ui: mocha-qunit
tunnel: ngrok
browsers:
- name: chrome
version: latest
Expand All @@ -8,6 +6,8 @@ browsers:
- name: safari
version: latest
- name: ie
version: 9..latest
version: latest
- name: microsoftedge
version: latest
sauce_connect: true
loopback: airtap.local
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
build

node_modules
npm-debug.log
package-lock.json
yarn.lock
*.swp
39 changes: 14 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
language: node_js
before_install:
- nvm install-latest-npm
matrix:
include:
- node_js: '0.8'
env: TASK=test-node
- node_js: '0.10'
env: TASK=test-node
- node_js: '0.11'
env: TASK=test-node
- node_js: '0.12'
env: TASK=test-node
- node_js: 1
env: TASK=test-node
- node_js: 2
env: TASK=test-node
- node_js: 3
env: TASK=test-node
- node_js: 4
env: TASK=test-node
- node_js: 5
env: TASK=test-node
- node_js: '0.10'
env: TASK=test-browser
script: "npm run $TASK"
node_js:
- 'stable'
- '12'
- '10'
- '8'
- '6'
script:
- 'npm test'
# Run browser tests on one node version.
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers; fi'
addons:
sauce_connect: true
hosts:
- airtap.local
env:
global:
- secure: qThuKBZQtkooAvzaYldECGNqvKGPRTnXx62IVyhSbFlsCY1VCmjhLldhyPDiZQ3JqL1XvSkK8OMDupiHqZnNE0nGijoO4M/kaEdjBB+jpjg3f8I6te2SNU935SbkfY9KHAaFXMZwdcq7Fk932AxWEu+FMSDM+080wNKpEATXDe4=
Expand Down
106 changes: 37 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,73 @@
# assert

[![Build Status](https://travis-ci.org/browserify/commonjs-assert.svg?branch=master)](https://travis-ci.org/browserify/commonjs-assert)

This module is used for writing unit tests for your applications, you can access it with `require('assert')`.
> The [`assert`](https://nodejs.org/api/assert.html) module from Node.js, for the browser.

It aims to be fully compatibe with the [node.js assert module](http://nodejs.org/api/assert.html), same API and same behavior, just adding support for web browsers.
The API and code may contain traces of the [CommonJS Unit Testing 1.0 spec](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) which they were based on, but both have evolved significantly since then.
[![Build Status](https://travis-ci.org/browserify/commonjs-assert.svg?branch=master)](https://travis-ci.org/browserify/commonjs-assert)
[![npm](https://img.shields.io/npm/dm/assert.svg)](https://www.npmjs.com/package/assert)
[![npm](https://img.shields.io/npm/v/assert.svg)](https://www.npmjs.com/package/assert)

A `strict` and a `legacy` mode exist, while it is recommended to only use `strict mode`.
With browserify, simply `require('assert')` or use the `assert` global and you will get this module.

## Strict mode
The goal is to provide an API that is as functionally identical to the [Node.js `assert` API](https://nodejs.org/api/assert.html) as possible. Read the [official docs](https://nodejs.org/api/assert.html) for API documentation.

When using the `strict mode`, any `assert` function will use the equality used in the strict function mode. So `assert.deepEqual()` will, for example, work the same as `assert.deepStrictEqual()`.
## Install

It can be accessed using:
To use this module directly (without browserify), install it as a dependency:

```js
const assert = require('assert').strict;
```
npm install assert
```

## Legacy mode
## Usage

> Deprecated: Use strict mode instead.
The goal is to provide an API that is as functionally identical to the [Node.js `assert` API](https://nodejs.org/api/assert.html) as possible. Read the [official docs](https://nodejs.org/api/assert.html) for API documentation.

When accessing `assert` directly instead of using the `strict` property, the
[Abstract Equality Comparison](https://tc39.github.io/ecma262/#sec-abstract-equality-comparison) will be used for any function without a
"strict" in its name (e.g. `assert.deepEqual()`).
### Inconsistencies with Node.js `assert`

It can be accessed using:
Due to differences between browsers, some error properties such as `message` and `stack` will be inconsistent. However the assertion behaviour is as close as possible to Node.js and the same error `code` will always be used.

```js
const assert = require('assert');
```
## Contributing

It is recommended to use the `strict mode` instead as the Abstract Equality Comparison can often have surprising results. Especially
in case of `assert.deepEqual()` as the used comparison rules there are very lax.
To contribute, work on the source files. Then build and run the tests against the built files. Be careful to not introduce syntax that will be transpiled down to unsupported syntax. For example, `for...of` loops will be transpiled to use `Symbol.iterator` which is unavailable in IE.

E.g.
### Build scripts

```js
// WARNING: This does not throw an AssertionError!
assert.deepEqual(/a/gi, new Date());
```
#### `npm run build`

Builds the project into the `build` dir.

## assert.fail(actual, expected, message, operator)
Throws an exception that displays the values for actual and expected separated by the provided operator.
#### `npm run dev`

## assert(value, message), assert.ok(value, [message])
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
Watches source files for changes and rebuilds them into the `build` dir.

## assert.equal(actual, expected, [message])
Tests shallow, coercive equality with the equal comparison operator ( == ).
#### `npm run test`

## assert.notEqual(actual, expected, [message])
Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
Builds the source files into the `build` dir and then runs the tests against the built project.

## assert.deepEqual(actual, expected, [message])
Tests for deep equality.
#### `npm run test:nobuild`

## assert.deepStrictEqual(actual, expected, [message])
Tests for deep equality, as determined by the strict equality operator ( === )
Runs the tests against the built project without rebuilding first.

## assert.notDeepEqual(actual, expected, [message])
Tests for any deep inequality.
This is useful if you're debugging in the transpiled code and want to re-run the tests without overwriting any changes you may have made.

## assert.strictEqual(actual, expected, [message])
Tests strict equality, as determined by the strict equality operator ( === )
#### `npm run test:source`

## assert.notStrictEqual(actual, expected, [message])
Tests strict non-equality, as determined by the strict not equal operator ( !== )
Runs the tests against the unbuilt source files.

## assert.throws(block, [error], [message])
Expects block to throw an error. error can be constructor, regexp or validation function.
This will only work on modern Node.js versions.

Validate instanceof using constructor:
#### `npm run test:browsers`

```javascript
assert.throws(function() { throw new Error("Wrong value"); }, Error);
```
Run browser tests against the all targets in the cloud.

Validate error message using RegExp:
Requires airtap credentials to be configured on your machine.

```javascript
assert.throws(function() { throw new Error("Wrong value"); }, /value/);
```
#### `npm run test:browsers:local`

Custom error validation:
Run a local browser test server. No airtap configuration required.

```javascript
assert.throws(function() {
throw new Error("Wrong value");
}, function(err) {
if ( (err instanceof Error) && /value/.test(err) ) {
return true;
}
}, "unexpected error");
```
When paired with `npm run dev` any changes you make to the source files will be automatically transpiled and served on the next request to the test server.

## assert.doesNotThrow(block, [message])
Expects block not to throw an error, see assert.throws for details.
## License

## assert.ifError(value)
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.
MIT © Joyent, Inc. and other Node contributors
Loading