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

fix: solve npm audit issues by replacing tape and tap-spec with Ava #282

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Fork this repo, write code and send a pull request. Easy!
* 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.
* If possible, avoid general dependency updates in the feature branch.
* 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".
* 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.
* 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.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"devDependencies": {
"@types/node": "^14.14.6",
"ava": "^3.15.0",
"eslint": "7.x",
"eslint-config-airbnb-base": "14.x",
"eslint-plugin-import": "2.x",
Expand All @@ -47,8 +48,6 @@
"prebuildify": "^4.1.1",
"proxyquire": "2.x",
"sinon": "9.x",
"tap-spec": "5.x",
"tape": "5.x",
"typescript": "^4.0.5",
"webworker": "0.x"
},
Expand All @@ -59,9 +58,9 @@
"install": "node ./scripts/prepublish.js && npm run build",
"lint": "eslint .",
"test": "npm run lint && npm run test-unit",
"test-components": "npm run build-components && tape ./tests/components/**/*.js | tap-spec",
"test-components": "npm run build-components && ava ./tests/components/**/*.js",
"test-integration": "node ./tests/integration/index",
"test-unit": "tape ./tests/unit/**/*.js | tap-spec",
"test-unit": "ava ./tests/unit/**/*.js",
"type-declarations": "tsc --outFile ./lib/typedeclarations.d.ts"
},
"engines": {
Expand Down
18 changes: 9 additions & 9 deletions tests/components/converterstest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const test = require('tape');
const test = require('ava');
const converters = require('./build/Release/converters.node');

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

t.deepEquals(res, `${expected}`);
t.deepEquals(typeof res, typeof '');
t.deepEqual(res, `${expected}`);
t.deepEqual(typeof res, typeof '');
});

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

t.deepEquals(res, expected);
t.deepEqual(res, expected);
});

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

t.deepEquals(res, expected);
t.deepEquals(typeof res, typeof true);
t.deepEqual(res, expected);
t.deepEqual(typeof res, typeof true);
});

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

t.deepEquals(res, expected);
t.deepEquals(resNeg, expectedNeg);
t.deepEqual(res, expected);
t.deepEqual(resNeg, expectedNeg);
});

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

t.deepEquals(res, expected);
t.deepEqual(res, expected);
});
60 changes: 30 additions & 30 deletions tests/unit/index/apitest.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
const { EventEmitter } = require('events');
const test = require('tape');
const test = require('ava');
const ZooKeeper = require('../../../lib/index');

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

t.equal(typeof zk.a_create, 'function');
t.equal(typeof zk.a_createTtl, 'function');
t.equal(typeof zk.a_exists, 'function');
t.equal(typeof zk.a_get, 'function');
t.equal(typeof zk.a_get_acl, 'function');
t.equal(typeof zk.a_get_children, 'function');

t.equal(typeof zk.a_get_children2, 'function');
t.equal(typeof zk.a_set, 'function');
t.equal(typeof zk.a_set_acl, 'function');
t.equal(typeof zk.a_sync, 'function');
t.equal(typeof zk.add_auth, 'function');

t.equal(typeof zk.aw_exists, 'function');
t.equal(typeof zk.aw_get, 'function');
t.equal(typeof zk.aw_get_children, 'function');
t.equal(typeof zk.aw_get_children2, 'function');
t.equal(typeof zk.close, 'function');

t.equal(zk.config, undefined);
t.equal(typeof zk.connect, 'function');
t.equal(zk.data_as_buffer, true);
t.equal(zk.encoding, null);
t.equal(typeof zk.init, 'function');

t.equal(zk.logger, undefined);
t.equal(typeof zk.mkdirp, 'function');
t.equal(typeof zk.setEncoding, 'function');
t.equal(typeof zk.setLogger, 'function');
t.is(typeof zk.a_create, 'function');
t.is(typeof zk.a_createTtl, 'function');
t.is(typeof zk.a_exists, 'function');
t.is(typeof zk.a_get, 'function');
t.is(typeof zk.a_get_acl, 'function');
t.is(typeof zk.a_get_children, 'function');

t.is(typeof zk.a_get_children2, 'function');
t.is(typeof zk.a_set, 'function');
t.is(typeof zk.a_set_acl, 'function');
t.is(typeof zk.a_sync, 'function');
t.is(typeof zk.add_auth, 'function');

t.is(typeof zk.aw_exists, 'function');
t.is(typeof zk.aw_get, 'function');
t.is(typeof zk.aw_get_children, 'function');
t.is(typeof zk.aw_get_children2, 'function');
t.is(typeof zk.close, 'function');

t.is(zk.config, undefined);
t.is(typeof zk.connect, 'function');
t.is(zk.data_as_buffer, true);
t.is(zk.encoding, null);
t.is(typeof zk.init, 'function');

t.is(zk.logger, undefined);
t.is(typeof zk.mkdirp, 'function');
t.is(typeof zk.setEncoding, 'function');
t.is(typeof zk.setLogger, 'function');

t.true(zk instanceof EventEmitter);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/index/configtest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const test = require('tape');
const test = require('ava');
const ZooKeeper = require('../../../lib/index');

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

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

t.equal(zk.config.connect, expected);
t.is(zk.config.connect, expected);
});

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

const zk = new ZooKeeper(expected);

t.equal(zk.config.connect, expected);
t.equal(Object.keys(zk.config).length, 1);
t.is(zk.config.connect, expected);
t.is(Object.keys(zk.config).length, 1);
});
6 changes: 3 additions & 3 deletions tests/unit/index/encodingtest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const test = require('tape');
const test = require('ava');
const ZooKeeper = require('../../../lib/index');

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

t.equal(zk.encoding, expected);
t.equal(zk.data_as_buffer, false);
t.is(zk.encoding, expected);
t.is(zk.data_as_buffer, false);
});
8 changes: 4 additions & 4 deletions tests/unit/index/loggertest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
const test = require('tape');
const test = require('ava');
const ZooKeeper = require('../../../lib/index');

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

t.equal(zk.logger, console.log);
t.is(zk.logger, console.log);
});

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

t.equal(typeof zk.logger, 'function');
t.is(typeof zk.logger, 'function');
});

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

t.equal(zk.logger, undefined);
t.is(zk.logger, undefined);
});
12 changes: 6 additions & 6 deletions tests/unit/util/helpertest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const sinon = require('sinon');
const test = require('tape');
const test = require('ava');
const { deprecationLog } = require('../../../lib/helper');

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

deprecationLogStub(Test.name, 'method');

t.equal(deprecationLogStub.callCount, 1);
t.equal(deprecationLogStub.getCall(0).args[0], 'Test');
t.equal(deprecationLogStub.getCall(0).args[1], 'method');
t.is(deprecationLogStub.callCount, 1);
t.is(deprecationLogStub.getCall(0).args[0], 'Test');
t.is(deprecationLogStub.getCall(0).args[1], 'method');
});

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

Test.method();

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

consoleStub.restore();
});
62 changes: 31 additions & 31 deletions tests/unit/util/promisetest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const sinon = require('sinon');
const test = require('tape');
const test = require('ava');

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

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

promise.get('property').then((actual) => {
t.equal(actual, expected);
return promise.get('property').then((actual) => {
t.is(actual, expected);
});
});

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

promise.put('property', expected).then((actual) => {
t.equal(actual, expected);
return promise.put('property', expected).then((actual) => {
t.is(actual, expected);
});
});

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

promise.call('multiply', 2, 3).then((actual) => {
t.equal(actual, 2 * 3);
return promise.call('multiply', 2, 3).then((actual) => {
t.is(actual, 2 * 3);
});
});

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

promise.addCallback(callback).then((actual) => {
t.equal(actual, 20);
t.equal(callback.callCount, 1);
t.equal(callback.getCall(0).args[0], 10);
return promise.addCallback(callback).then((actual) => {
t.is(actual, 20);
t.is(callback.callCount, 1);
t.is(callback.getCall(0).args[0], 10);
});
});

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

promise.addErrback(callback).then((actual) => {
t.equal(actual, 20);
t.equal(callback.callCount, 1);
t.equal(callback.getCall(0).args[0], 10);
return promise.addErrback(callback).then((actual) => {
t.is(actual, 20);
t.is(callback.callCount, 1);
t.is(callback.getCall(0).args[0], 10);
});
});

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

promise(true).addBoth(callback)
return promise(true).addBoth(callback)
.then((actual) => {
t.equal(actual, 20);
t.equal(callback.callCount, 1);
t.equal(callback.getCall(0).args[0], 10);
t.is(actual, 20);
t.is(callback.callCount, 1);
t.is(callback.getCall(0).args[0], 10);
return promise(false).addBoth(errback);
})
.catch((actual) => {
t.true(actual instanceof Error);
t.equal(actual.message, 'errback!');
t.equal(errback.callCount, 1);
t.equal(errback.getCall(0).args[0], 10);
t.is(actual.message, 'errback!');
t.is(errback.callCount, 1);
t.is(errback.getCall(0).args[0], 10);
});
});

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

promise(true).addCallbacks(callback, errback)
return promise(true).addCallbacks(callback, errback)
.then((actual) => {
t.equal(actual, 20);
t.equal(callback.callCount, 1);
t.equal(callback.getCall(0).args[0], 10);
t.equal(errback.callCount, 0);
t.is(actual, 20);
t.is(callback.callCount, 1);
t.is(callback.getCall(0).args[0], 10);
t.is(errback.callCount, 0);
callback.resetHistory();
errback.resetHistory();
return promise(false).addCallbacks(callback, errback);
})
.catch((actual) => {
t.true(actual instanceof Error);
t.equal(actual.message, 'errback!');
t.equal(callback.callCount, 0);
t.equal(errback.callCount, 1);
t.equal(errback.getCall(0).args[0], 10);
t.is(actual.message, 'errback!');
t.is(callback.callCount, 0);
t.is(errback.callCount, 1);
t.is(errback.getCall(0).args[0], 10);
});
});
Loading