chai-bites 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/index.d.ts +1 -1
- package/index.js +4 -6
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
Fork of [chai-bytes](https://www.npmjs.com/package/chai-bytes) published as ESM with relaxed input types.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Chai Assertions for Byte Arrays Equality
|
|
4
4
|
|
|
5
5
|
[![Build status][workflow-image]][workflow-url]
|
|
6
6
|
[![Code coverage][coveralls-image]][coveralls-url]
|
|
@@ -16,14 +16,14 @@ Fork of [chai-bytes](https://www.npmjs.com/package/chai-bytes) with relaxed inpu
|
|
|
16
16
|
[license-image]: https://img.shields.io/github/license/slowli/chai-bytes.svg
|
|
17
17
|
[license-url]: https://opensource.org/licenses/Apache-2.0
|
|
18
18
|
|
|
19
|
-
**chai-
|
|
19
|
+
**chai-bytes** extends [Chai][chai] with a `equalBytes` function,
|
|
20
20
|
which can be used to test equality of byte arrays (i.e., `Uint8Array` instances).
|
|
21
21
|
|
|
22
22
|
## Basic Usage
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
25
|
const { expect, assert } = require('chai')
|
|
26
|
-
.use(require('chai-
|
|
26
|
+
.use(require('chai-bytes'));
|
|
27
27
|
|
|
28
28
|
const buffer = new Uint8Array([ 1, 2, 3, 4, 5 ]);
|
|
29
29
|
expect(buffer).to.equalBytes('0102030405');
|
|
@@ -44,13 +44,13 @@ a `TypeError` is thrown.
|
|
|
44
44
|
|
|
45
45
|
## Developer Notes
|
|
46
46
|
|
|
47
|
-
**chai-
|
|
47
|
+
**chai-bytes** uses combined code coverage from the tested browser environments
|
|
48
48
|
(Firefox and PhantomJS). This is because PhantomJS is a typical old environment
|
|
49
49
|
that may have problems with `Uint8Array`s (e.g., it misses a substantial parts
|
|
50
50
|
of their methods).
|
|
51
51
|
|
|
52
52
|
## License
|
|
53
53
|
|
|
54
|
-
**chai-
|
|
54
|
+
**chai-bytes** is available under [Apache-2.0 license](LICENSE).
|
|
55
55
|
|
|
56
56
|
[chai]: https://chaijs.com/
|
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare global {
|
|
|
12
12
|
* expect(new Uint8Array([1, 2])).to.equalBytes([1, 2]);
|
|
13
13
|
* expect(new Uint8Array[65, 66, 67])).to.equalBytes('414243');
|
|
14
14
|
*/
|
|
15
|
-
equalBytes(bytes?: string | ArrayLike<number
|
|
15
|
+
equalBytes(bytes?: string | ArrayLike<number>, msg?: string): Assertion;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface Assert {
|
package/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
function every (buffer, predicate) {
|
|
4
2
|
if (Uint8Array && Uint8Array.prototype.every) {
|
|
5
3
|
return buffer.every(predicate);
|
|
@@ -20,10 +18,10 @@ function every (buffer, predicate) {
|
|
|
20
18
|
* expect(new Uint8Array([1, 2])).to.equalBytes([1, 2]);
|
|
21
19
|
* expect(new Uint8Array[65, 66, 67])).to.equalBytes('414243');
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
export default function (chai) {
|
|
24
22
|
const Assertion = chai.Assertion;
|
|
25
23
|
|
|
26
|
-
Assertion.addMethod('equalBytes', function (expected) {
|
|
24
|
+
Assertion.addMethod('equalBytes', function (expected, message) {
|
|
27
25
|
if (typeof expected === 'string') {
|
|
28
26
|
if (expected.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(expected)) {
|
|
29
27
|
throw new TypeError('Invalid hex string: ' + expected);
|
|
@@ -50,8 +48,8 @@ module.exports = function (chai) {
|
|
|
50
48
|
|
|
51
49
|
this.assert(
|
|
52
50
|
assert,
|
|
53
|
-
'expected #{this} to equal #{exp}',
|
|
54
|
-
'expected #{this} to not equal #{exp}',
|
|
51
|
+
message ?? 'expected #{this} to equal #{exp}',
|
|
52
|
+
message ?? 'expected #{this} to not equal #{exp}',
|
|
55
53
|
expected
|
|
56
54
|
);
|
|
57
55
|
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chai-bites",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Chai assertions for byte arrays equality",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/achingbrain/chai-bites.git"
|
|
7
|
+
"url": "git+https://github.com/achingbrain/chai-bites.git"
|
|
8
8
|
},
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/achingbrain/chai-bites/issues"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"node": ">=10"
|
|
14
14
|
},
|
|
15
15
|
"main": "index.js",
|
|
16
|
+
"type": "module",
|
|
16
17
|
"types": "index.d.ts",
|
|
17
18
|
"files": [
|
|
18
19
|
"index.js",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"babel-plugin-istanbul": "^6.0.0",
|
|
41
42
|
"babelify": "^10.0.0",
|
|
42
43
|
"browserify": "^17.0.0",
|
|
43
|
-
"chai": "^
|
|
44
|
+
"chai": "^5.1.0",
|
|
44
45
|
"coveralls": "^3.1.1",
|
|
45
46
|
"karma": "^6.3.4",
|
|
46
47
|
"karma-browserify": "^8.1.0",
|
|
@@ -48,11 +49,8 @@
|
|
|
48
49
|
"karma-firefox-launcher": "^2.1.1",
|
|
49
50
|
"karma-mocha": "^2.0.1",
|
|
50
51
|
"karma-mocha-reporter": "^2.2.5",
|
|
51
|
-
"mocha": "^
|
|
52
|
-
"semistandard": "^
|
|
53
|
-
"typescript": "^4.
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"chai": ">=2 <5"
|
|
52
|
+
"mocha": "^10.4.0",
|
|
53
|
+
"semistandard": "^17.0.0",
|
|
54
|
+
"typescript": "^5.4.5"
|
|
57
55
|
}
|
|
58
56
|
}
|