Skip to content

Commit b3f5b5d

Browse files
authored
Merge pull request #282 from DavidVujic/use_ava_test
fix: solve npm audit issues by replacing tape and tap-spec with Ava
2 parents 3b5c9fe + 3d292fe commit b3f5b5d

12 files changed

+127
-131
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Fork this repo, write code and send a pull request. Easy!
77
* If possible, isolate the changes in the branch to the feature only. Merges will be easier if general refactorings, that are not specific to the feature, are made in separate branches.
88
* If possible, avoid general dependency updates in the feature branch.
99
* If possible, send pull requests early. Don't wait too long, even if the feature is not completely done. The new code can very likely be merged without causing any problems (if the code changes are not of type breaking features). Think of it as "silent releases".
10-
* If you think it is relevant and add value: write unit test(s). Use the`tape` unit test library. They could also be valuable as description of features.
10+
* If you think it is relevant and add value: write unit test(s). Use the`ava` unit test library. They could also be valuable as description of features.

Diff for: package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"@types/node": "^14.14.6",
42+
"ava": "^3.15.0",
4243
"eslint": "7.x",
4344
"eslint-config-airbnb-base": "14.x",
4445
"eslint-plugin-import": "2.x",
@@ -47,8 +48,6 @@
4748
"prebuildify": "^4.1.1",
4849
"proxyquire": "2.x",
4950
"sinon": "9.x",
50-
"tap-spec": "5.x",
51-
"tape": "5.x",
5251
"typescript": "^4.0.5",
5352
"webworker": "0.x"
5453
},
@@ -59,9 +58,9 @@
5958
"install": "node ./scripts/prepublish.js && npm run build",
6059
"lint": "eslint .",
6160
"test": "npm run lint && npm run test-unit",
62-
"test-components": "npm run build-components && tape ./tests/components/**/*.js | tap-spec",
61+
"test-components": "npm run build-components && ava ./tests/components/**/*.js",
6362
"test-integration": "node ./tests/integration/index",
64-
"test-unit": "tape ./tests/unit/**/*.js | tap-spec",
63+
"test-unit": "ava ./tests/unit/**/*.js",
6564
"type-declarations": "tsc --outFile ./lib/typedeclarations.d.ts"
6665
},
6766
"engines": {

Diff for: tests/components/converterstest.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const test = require('tape');
1+
const test = require('ava');
22
const converters = require('./build/Release/converters.node');
33

44
test('Integer is converted to string', (t) => {
55
t.plan(2);
66
const expected = 4711;
77
const res = converters.toStrTest(expected);
88

9-
t.deepEquals(res, `${expected}`);
10-
t.deepEquals(typeof res, typeof '');
9+
t.deepEqual(res, `${expected}`);
10+
t.deepEqual(typeof res, typeof '');
1111
});
1212

1313
test('Unix time is converted to date', (t) => {
@@ -23,16 +23,16 @@ test('Unix time is converted to date', (t) => {
2323
const r = new Date(converted * 1000);
2424
const res = `${r.getFullYear()}-${r.getMonth()}-${r.getDate()}}`;
2525

26-
t.deepEquals(res, expected);
26+
t.deepEqual(res, expected);
2727
});
2828

2929
test('Object value is converted to bool', (t) => {
3030
t.plan(2);
3131
const expected = true;
3232
const res = converters.toBoolTest({ val: 'true' });
3333

34-
t.deepEquals(res, expected);
35-
t.deepEquals(typeof res, typeof true);
34+
t.deepEqual(res, expected);
35+
t.deepEqual(typeof res, typeof true);
3636
});
3737

3838
test('Object value is converted to integer', (t) => {
@@ -42,14 +42,14 @@ test('Object value is converted to integer', (t) => {
4242
const res = converters.toIntTest({ val: '4711' });
4343
const resNeg = converters.toIntTest({ val: '-1' });
4444

45-
t.deepEquals(res, expected);
46-
t.deepEquals(resNeg, expectedNeg);
45+
t.deepEqual(res, expected);
46+
t.deepEqual(resNeg, expectedNeg);
4747
});
4848

4949
test('Object value is converted to unsigned integer', (t) => {
5050
t.plan(1);
5151
const expected = 4711;
5252
const res = converters.toUintTest('4711');
5353

54-
t.deepEquals(res, expected);
54+
t.deepEqual(res, expected);
5555
});

Diff for: tests/unit/index/apitest.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
const { EventEmitter } = require('events');
2-
const test = require('tape');
2+
const test = require('ava');
33
const ZooKeeper = require('../../../lib/index');
44

55
function assertPublicApi(zk, t) {
66
t.plan(26);
77

8-
t.equal(typeof zk.a_create, 'function');
9-
t.equal(typeof zk.a_createTtl, 'function');
10-
t.equal(typeof zk.a_exists, 'function');
11-
t.equal(typeof zk.a_get, 'function');
12-
t.equal(typeof zk.a_get_acl, 'function');
13-
t.equal(typeof zk.a_get_children, 'function');
14-
15-
t.equal(typeof zk.a_get_children2, 'function');
16-
t.equal(typeof zk.a_set, 'function');
17-
t.equal(typeof zk.a_set_acl, 'function');
18-
t.equal(typeof zk.a_sync, 'function');
19-
t.equal(typeof zk.add_auth, 'function');
20-
21-
t.equal(typeof zk.aw_exists, 'function');
22-
t.equal(typeof zk.aw_get, 'function');
23-
t.equal(typeof zk.aw_get_children, 'function');
24-
t.equal(typeof zk.aw_get_children2, 'function');
25-
t.equal(typeof zk.close, 'function');
26-
27-
t.equal(zk.config, undefined);
28-
t.equal(typeof zk.connect, 'function');
29-
t.equal(zk.data_as_buffer, true);
30-
t.equal(zk.encoding, null);
31-
t.equal(typeof zk.init, 'function');
32-
33-
t.equal(zk.logger, undefined);
34-
t.equal(typeof zk.mkdirp, 'function');
35-
t.equal(typeof zk.setEncoding, 'function');
36-
t.equal(typeof zk.setLogger, 'function');
8+
t.is(typeof zk.a_create, 'function');
9+
t.is(typeof zk.a_createTtl, 'function');
10+
t.is(typeof zk.a_exists, 'function');
11+
t.is(typeof zk.a_get, 'function');
12+
t.is(typeof zk.a_get_acl, 'function');
13+
t.is(typeof zk.a_get_children, 'function');
14+
15+
t.is(typeof zk.a_get_children2, 'function');
16+
t.is(typeof zk.a_set, 'function');
17+
t.is(typeof zk.a_set_acl, 'function');
18+
t.is(typeof zk.a_sync, 'function');
19+
t.is(typeof zk.add_auth, 'function');
20+
21+
t.is(typeof zk.aw_exists, 'function');
22+
t.is(typeof zk.aw_get, 'function');
23+
t.is(typeof zk.aw_get_children, 'function');
24+
t.is(typeof zk.aw_get_children2, 'function');
25+
t.is(typeof zk.close, 'function');
26+
27+
t.is(zk.config, undefined);
28+
t.is(typeof zk.connect, 'function');
29+
t.is(zk.data_as_buffer, true);
30+
t.is(zk.encoding, null);
31+
t.is(typeof zk.init, 'function');
32+
33+
t.is(zk.logger, undefined);
34+
t.is(typeof zk.mkdirp, 'function');
35+
t.is(typeof zk.setEncoding, 'function');
36+
t.is(typeof zk.setLogger, 'function');
3737

3838
t.true(zk instanceof EventEmitter);
3939
}

Diff for: tests/unit/index/configtest.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('tape');
1+
const test = require('ava');
22
const ZooKeeper = require('../../../lib/index');
33

44
test('inject config', (t) => {
@@ -8,7 +8,7 @@ test('inject config', (t) => {
88

99
const zk = new ZooKeeper({ connect: expected });
1010

11-
t.equal(zk.config.connect, expected);
11+
t.is(zk.config.connect, expected);
1212
});
1313

1414
test('inject connection config as a string', (t) => {
@@ -18,6 +18,6 @@ test('inject connection config as a string', (t) => {
1818

1919
const zk = new ZooKeeper(expected);
2020

21-
t.equal(zk.config.connect, expected);
22-
t.equal(Object.keys(zk.config).length, 1);
21+
t.is(zk.config.connect, expected);
22+
t.is(Object.keys(zk.config).length, 1);
2323
});

Diff for: tests/unit/index/encodingtest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('tape');
1+
const test = require('ava');
22
const ZooKeeper = require('../../../lib/index');
33

44
test('inject encoding will set data as buffer to false', (t) => {
@@ -9,6 +9,6 @@ test('inject encoding will set data as buffer to false', (t) => {
99
const zk = new ZooKeeper();
1010
zk.setEncoding(expected);
1111

12-
t.equal(zk.encoding, expected);
13-
t.equal(zk.data_as_buffer, false);
12+
t.is(zk.encoding, expected);
13+
t.is(zk.data_as_buffer, false);
1414
});

Diff for: tests/unit/index/loggertest.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
const test = require('tape');
2+
const test = require('ava');
33
const ZooKeeper = require('../../../lib/index');
44

55
test('Inject custom logger', (t) => {
@@ -8,7 +8,7 @@ test('Inject custom logger', (t) => {
88
const zk = new ZooKeeper();
99
zk.setLogger(console.log);
1010

11-
t.equal(zk.logger, console.log);
11+
t.is(zk.logger, console.log);
1212
});
1313

1414
test('Use default logger', (t) => {
@@ -17,7 +17,7 @@ test('Use default logger', (t) => {
1717
const zk = new ZooKeeper();
1818
zk.setLogger(true);
1919

20-
t.equal(typeof zk.logger, 'function');
20+
t.is(typeof zk.logger, 'function');
2121
});
2222

2323
test('Explicit set use no logger', (t) => {
@@ -26,5 +26,5 @@ test('Explicit set use no logger', (t) => {
2626
const zk = new ZooKeeper();
2727
zk.setLogger(false);
2828

29-
t.equal(zk.logger, undefined);
29+
t.is(zk.logger, undefined);
3030
});

Diff for: tests/unit/util/helpertest.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const sinon = require('sinon');
2-
const test = require('tape');
2+
const test = require('ava');
33
const { deprecationLog } = require('../../../lib/helper');
44

55
class Test {
@@ -14,9 +14,9 @@ test('deprecation log is called with proper arguments', (t) => {
1414

1515
deprecationLogStub(Test.name, 'method');
1616

17-
t.equal(deprecationLogStub.callCount, 1);
18-
t.equal(deprecationLogStub.getCall(0).args[0], 'Test');
19-
t.equal(deprecationLogStub.getCall(0).args[1], 'method');
17+
t.is(deprecationLogStub.callCount, 1);
18+
t.is(deprecationLogStub.getCall(0).args[0], 'Test');
19+
t.is(deprecationLogStub.getCall(0).args[1], 'method');
2020
});
2121

2222
test('deprecation log gives proper message', (t) => {
@@ -25,8 +25,8 @@ test('deprecation log gives proper message', (t) => {
2525

2626
Test.method();
2727

28-
t.equal(consoleStub.callCount, 1);
29-
t.equal(consoleStub.getCall(0).args[0], 'ZOOKEEPER LOG: Test::method is being deprecated!');
28+
t.is(consoleStub.callCount, 1);
29+
t.is(consoleStub.getCall(0).args[0], 'ZOOKEEPER LOG: Test::method is being deprecated!');
3030

3131
consoleStub.restore();
3232
});

Diff for: tests/unit/util/promisetest.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const sinon = require('sinon');
2-
const test = require('tape');
2+
const test = require('ava');
33

44
const ZkPromise = require('../../../lib/promise');
55

@@ -11,8 +11,8 @@ test('ZkPromise get', (t) => {
1111
property: expected,
1212
});
1313

14-
promise.get('property').then((actual) => {
15-
t.equal(actual, expected);
14+
return promise.get('property').then((actual) => {
15+
t.is(actual, expected);
1616
});
1717
});
1818

@@ -22,8 +22,8 @@ test('ZkPromise put', (t) => {
2222
const expected = 'value';
2323
const promise = ZkPromise.resolve({});
2424

25-
promise.put('property', expected).then((actual) => {
26-
t.equal(actual, expected);
25+
return promise.put('property', expected).then((actual) => {
26+
t.is(actual, expected);
2727
});
2828
});
2929

@@ -34,8 +34,8 @@ test('ZkPromise call', (t) => {
3434
multiply: (a, b) => a * b,
3535
});
3636

37-
promise.call('multiply', 2, 3).then((actual) => {
38-
t.equal(actual, 2 * 3);
37+
return promise.call('multiply', 2, 3).then((actual) => {
38+
t.is(actual, 2 * 3);
3939
});
4040
});
4141

@@ -45,10 +45,10 @@ test('ZkPromise addCallback', (t) => {
4545
const callback = sinon.stub().callsFake((value) => value * 2);
4646
const promise = ZkPromise.resolve(10);
4747

48-
promise.addCallback(callback).then((actual) => {
49-
t.equal(actual, 20);
50-
t.equal(callback.callCount, 1);
51-
t.equal(callback.getCall(0).args[0], 10);
48+
return promise.addCallback(callback).then((actual) => {
49+
t.is(actual, 20);
50+
t.is(callback.callCount, 1);
51+
t.is(callback.getCall(0).args[0], 10);
5252
});
5353
});
5454

@@ -58,10 +58,10 @@ test('ZkPromise addErrback', (t) => {
5858
const callback = sinon.stub().callsFake((value) => value * 2);
5959
const promise = ZkPromise.reject(10);
6060

61-
promise.addErrback(callback).then((actual) => {
62-
t.equal(actual, 20);
63-
t.equal(callback.callCount, 1);
64-
t.equal(callback.getCall(0).args[0], 10);
61+
return promise.addErrback(callback).then((actual) => {
62+
t.is(actual, 20);
63+
t.is(callback.callCount, 1);
64+
t.is(callback.getCall(0).args[0], 10);
6565
});
6666
});
6767

@@ -75,18 +75,18 @@ test('ZkPromise addBoth', (t) => {
7575
// eslint-disable-next-line max-len
7676
const promise = (succeeds) => new ZkPromise((resolve, reject) => (succeeds ? resolve(10) : reject(10)));
7777

78-
promise(true).addBoth(callback)
78+
return promise(true).addBoth(callback)
7979
.then((actual) => {
80-
t.equal(actual, 20);
81-
t.equal(callback.callCount, 1);
82-
t.equal(callback.getCall(0).args[0], 10);
80+
t.is(actual, 20);
81+
t.is(callback.callCount, 1);
82+
t.is(callback.getCall(0).args[0], 10);
8383
return promise(false).addBoth(errback);
8484
})
8585
.catch((actual) => {
8686
t.true(actual instanceof Error);
87-
t.equal(actual.message, 'errback!');
88-
t.equal(errback.callCount, 1);
89-
t.equal(errback.getCall(0).args[0], 10);
87+
t.is(actual.message, 'errback!');
88+
t.is(errback.callCount, 1);
89+
t.is(errback.getCall(0).args[0], 10);
9090
});
9191
});
9292

@@ -100,21 +100,21 @@ test('ZkPromise addCallbacks', (t) => {
100100
// eslint-disable-next-line max-len
101101
const promise = (succeeds) => new ZkPromise((resolve, reject) => (succeeds ? resolve(10) : reject(10)));
102102

103-
promise(true).addCallbacks(callback, errback)
103+
return promise(true).addCallbacks(callback, errback)
104104
.then((actual) => {
105-
t.equal(actual, 20);
106-
t.equal(callback.callCount, 1);
107-
t.equal(callback.getCall(0).args[0], 10);
108-
t.equal(errback.callCount, 0);
105+
t.is(actual, 20);
106+
t.is(callback.callCount, 1);
107+
t.is(callback.getCall(0).args[0], 10);
108+
t.is(errback.callCount, 0);
109109
callback.resetHistory();
110110
errback.resetHistory();
111111
return promise(false).addCallbacks(callback, errback);
112112
})
113113
.catch((actual) => {
114114
t.true(actual instanceof Error);
115-
t.equal(actual.message, 'errback!');
116-
t.equal(callback.callCount, 0);
117-
t.equal(errback.callCount, 1);
118-
t.equal(errback.getCall(0).args[0], 10);
115+
t.is(actual.message, 'errback!');
116+
t.is(callback.callCount, 0);
117+
t.is(errback.callCount, 1);
118+
t.is(errback.getCall(0).args[0], 10);
119119
});
120120
});

0 commit comments

Comments
 (0)