Skip to content

Commit b65e3fb

Browse files
authored
Sync with Node.js master (#44)
2 parents 8386769 + e1cbf4d commit b65e3fb

23 files changed

+5259
-863
lines changed

.zuul.yml .airtap.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ui: mocha-qunit
2-
tunnel: ngrok
31
browsers:
42
- name: chrome
53
version: latest
@@ -8,6 +6,8 @@ browsers:
86
- name: safari
97
version: latest
108
- name: ie
11-
version: 9..latest
9+
version: latest
1210
- name: microsoftedge
1311
version: latest
12+
sauce_connect: true
13+
loopback: airtap.local

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
build
2+
13
node_modules
4+
npm-debug.log
5+
package-lock.json
6+
yarn.lock
7+
*.swp

.travis.yml

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
language: node_js
2-
before_install:
3-
- nvm install-latest-npm
4-
matrix:
5-
include:
6-
- node_js: '0.8'
7-
env: TASK=test-node
8-
- node_js: '0.10'
9-
env: TASK=test-node
10-
- node_js: '0.11'
11-
env: TASK=test-node
12-
- node_js: '0.12'
13-
env: TASK=test-node
14-
- node_js: 1
15-
env: TASK=test-node
16-
- node_js: 2
17-
env: TASK=test-node
18-
- node_js: 3
19-
env: TASK=test-node
20-
- node_js: 4
21-
env: TASK=test-node
22-
- node_js: 5
23-
env: TASK=test-node
24-
- node_js: '0.10'
25-
env: TASK=test-browser
26-
script: "npm run $TASK"
2+
node_js:
3+
- 'stable'
4+
- '12'
5+
- '10'
6+
- '8'
7+
- '6'
8+
script:
9+
- 'npm test'
10+
# Run browser tests on one node version.
11+
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers; fi'
12+
addons:
13+
sauce_connect: true
14+
hosts:
15+
- airtap.local
2716
env:
2817
global:
2918
- secure: qThuKBZQtkooAvzaYldECGNqvKGPRTnXx62IVyhSbFlsCY1VCmjhLldhyPDiZQ3JqL1XvSkK8OMDupiHqZnNE0nGijoO4M/kaEdjBB+jpjg3f8I6te2SNU935SbkfY9KHAaFXMZwdcq7Fk932AxWEu+FMSDM+080wNKpEATXDe4=

README.md

+37-69
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,73 @@
11
# assert
22

3-
[![Build Status](https://travis-ci.org/browserify/commonjs-assert.svg?branch=master)](https://travis-ci.org/browserify/commonjs-assert)
4-
5-
This module is used for writing unit tests for your applications, you can access it with `require('assert')`.
3+
> The [`assert`](https://nodejs.org/api/assert.html) module from Node.js, for the browser.
64
7-
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.
8-
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.
5+
[![Build Status](https://travis-ci.org/browserify/commonjs-assert.svg?branch=master)](https://travis-ci.org/browserify/commonjs-assert)
6+
[![npm](https://img.shields.io/npm/dm/assert.svg)](https://www.npmjs.com/package/assert)
7+
[![npm](https://img.shields.io/npm/v/assert.svg)](https://www.npmjs.com/package/assert)
98

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

12-
## Strict mode
11+
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.
1312

14-
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()`.
13+
## Install
1514

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

18-
```js
19-
const assert = require('assert').strict;
17+
```
18+
npm install assert
2019
```
2120

22-
## Legacy mode
21+
## Usage
2322

24-
> Deprecated: Use strict mode instead.
23+
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.
2524

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

30-
It can be accessed using:
27+
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.
3128

32-
```js
33-
const assert = require('assert');
34-
```
29+
## Contributing
3530

36-
It is recommended to use the `strict mode` instead as the Abstract Equality Comparison can often have surprising results. Especially
37-
in case of `assert.deepEqual()` as the used comparison rules there are very lax.
31+
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.
3832

39-
E.g.
33+
### Build scripts
4034

41-
```js
42-
// WARNING: This does not throw an AssertionError!
43-
assert.deepEqual(/a/gi, new Date());
44-
```
35+
#### `npm run build`
4536

37+
Builds the project into the `build` dir.
4638

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

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

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

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

59-
## assert.deepEqual(actual, expected, [message])
60-
Tests for deep equality.
47+
#### `npm run test:nobuild`
6148

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

65-
## assert.notDeepEqual(actual, expected, [message])
66-
Tests for any deep inequality.
51+
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.
6752

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

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

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

77-
Validate instanceof using constructor:
59+
#### `npm run test:browsers`
7860

79-
```javascript
80-
assert.throws(function() { throw new Error("Wrong value"); }, Error);
81-
```
61+
Run browser tests against the all targets in the cloud.
8262

83-
Validate error message using RegExp:
63+
Requires airtap credentials to be configured on your machine.
8464

85-
```javascript
86-
assert.throws(function() { throw new Error("Wrong value"); }, /value/);
87-
```
65+
#### `npm run test:browsers:local`
8866

89-
Custom error validation:
67+
Run a local browser test server. No airtap configuration required.
9068

91-
```javascript
92-
assert.throws(function() {
93-
throw new Error("Wrong value");
94-
}, function(err) {
95-
if ( (err instanceof Error) && /value/.test(err) ) {
96-
return true;
97-
}
98-
}, "unexpected error");
99-
```
69+
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.
10070

101-
## assert.doesNotThrow(block, [message])
102-
Expects block not to throw an error, see assert.throws for details.
71+
## License
10372

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

0 commit comments

Comments
 (0)