diff --git a/package.json b/package.json index 636256d..fd3aa84 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "url": "https://www.patreon.com/tshemsedinov" }, "scripts": { - "test": "npm run lint && npm run types && node --test", + "test": "npm run lint && npm run types && node --test --test-reporter=tap", "types": "tsc -p tsconfig.json", "lint": "eslint . && prettier --check \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.ts\"", "fix": "eslint . --fix && prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.ts\"" diff --git a/test/async.js b/test/async.js index fe01cce..43f766d 100644 --- a/test/async.js +++ b/test/async.js @@ -1,23 +1,23 @@ 'use strict'; -const metatests = require('metatests'); +const test = require('node:test'); +const assert = require('node:assert'); const { toBool, timeout, delay, timeoutify } = require('..'); -metatests.test('Async: toBool', async (test) => { +test('Async: toBool', async () => { const success = await Promise.resolve('success').then(...toBool); - test.strictSame(success, true); + assert.strictEqual(success, true); const rejected = await Promise.reject(new Error('Ups')).then(...toBool); - test.strictSame(rejected, false); - test.end(); + assert.strictEqual(rejected, false); }); -metatests.test('Async: Abortable timeout', async (test) => { +test('Async: Abortable timeout', async () => { try { await timeout(10); - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (err) { - test.strictSame(err.code, 'ETIMEOUT'); - test.strictSame(err.message, 'Timeout of 10ms reached'); + assert.strictEqual(err.code, 'ETIMEOUT'); + assert.strictEqual(err.message, 'Timeout of 10ms reached'); } const ac = new AbortController(); setTimeout(() => { @@ -25,19 +25,18 @@ metatests.test('Async: Abortable timeout', async (test) => { }, 10); try { await timeout(100, ac.signal); - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (err) { - test.strictSame(err.message, 'Timeout aborted'); - test.end(); + assert.strictEqual(err.message, 'Timeout aborted'); } }); -metatests.test('Async: Abortable delay', async (test) => { +test('Async: Abortable delay', async () => { try { const res = await delay(10); - test.strictSame(res, undefined); + assert.strictEqual(res, undefined); } catch { - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } const ac = new AbortController(); setTimeout(() => { @@ -45,28 +44,26 @@ metatests.test('Async: Abortable delay', async (test) => { }, 10); try { await delay(100, ac.signal); - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (err) { - test.strictSame(err.message, 'Delay aborted'); - test.end(); + assert.strictEqual(err.message, 'Delay aborted'); } }); -metatests.test('Async: timeoutify', async (test) => { +test('Async: timeoutify', async () => { try { const request = delay(1000); await timeoutify(request, 10); - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (err) { - test.strictSame(err.code, 'ETIMEOUT'); - test.strictSame(err.message, 'Timeout of 10ms reached'); + assert.strictEqual(err.code, 'ETIMEOUT'); + assert.strictEqual(err.message, 'Timeout of 10ms reached'); } try { const request = delay(10); const response = await timeoutify(request, 1000); - test.strictSame(response, undefined); - test.end(); + assert.strictEqual(response, undefined); } catch { - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } }); diff --git a/test/collector.js b/test/collector.js index 87f749d..05e5ad8 100644 --- a/test/collector.js +++ b/test/collector.js @@ -1,9 +1,10 @@ 'use strict'; +const test = require('node:test'); +const assert = require('node:assert'); const { collect } = require('..'); -const metatests = require('metatests'); -metatests.test('Collector: keys', async (test) => { +test('Collector: keys', async () => { const expectedResult = { key1: 1, key2: 2 }; const dc = collect(['key1', 'key2']); @@ -16,11 +17,10 @@ metatests.test('Collector: keys', async (test) => { }, 100); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: exact', async (test) => { +test('Collector: exact', async () => { const dc = collect(['key1', 'key2']); setTimeout(() => { @@ -29,14 +29,13 @@ metatests.test('Collector: exact', async (test) => { try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'Unexpected key: wrongKey'); - test.end(); + assert.strictEqual(error.message, 'Unexpected key: wrongKey'); } }); -metatests.test('Collector: not exact', async (test) => { +test('Collector: not exact', async () => { const expectedResult = { key1: 1, wrongKey: 'someVal', key2: 2 }; const dc = collect(['key1', 'key2'], { exact: false }); @@ -54,14 +53,13 @@ metatests.test('Collector: not exact', async (test) => { try { const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); } catch (error) { - test.error(error); + assert.ifError(error); } }); -metatests.test('Collector: set after done', async (test) => { +test('Collector: set after done', async () => { const expectedResult = { key1: 1 }; const dc = collect(['key1']); @@ -74,16 +72,14 @@ metatests.test('Collector: set after done', async (test) => { }, 75); const result = await dc; - test.strictSame(result, expectedResult); + assert.deepStrictEqual(result, expectedResult); setTimeout(() => { dc.set('key3', 3); }, 100); - - test.end(); }); -metatests.test('Collector: timeout', async (test) => { +test('Collector: timeout', async () => { const dc = collect(['key1'], { timeout: 50 }); setTimeout(() => { @@ -92,21 +88,23 @@ metatests.test('Collector: timeout', async (test) => { }, 100); dc.signal.addEventListener('abort', (event) => { - test.strictSame(event.type, 'abort'); - test.assert(dc.signal.reason instanceof DOMException); - test.strictSame(dc.signal.reason.name, 'TimeoutError'); + assert.strictEqual(event.type, 'abort'); + assert(dc.signal.reason instanceof DOMException); + assert.strictEqual(dc.signal.reason.name, 'TimeoutError'); }); try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'The operation was aborted due to timeout'); - test.end(); + assert.strictEqual( + error.message, + 'The operation was aborted due to timeout', + ); } }); -metatests.test('Collector: default values', async (test) => { +test('Collector: default values', async () => { const defaults = { key1: 1 }; const dc1 = collect(['key1'], { defaults, timeout: 50 }); @@ -121,20 +119,22 @@ metatests.test('Collector: default values', async (test) => { }, 100); const result1 = await dc1; - test.strictSame(result1, defaults); + assert.deepStrictEqual(result1, defaults); const result3 = await dc3; - test.strictSame(result3, { ...defaults, key2: 1 }); + assert.deepStrictEqual(result3, { ...defaults, key2: 1 }); try { await dc2; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'The operation was aborted due to timeout'); + assert.strictEqual( + error.message, + 'The operation was aborted due to timeout', + ); } - test.end(); }); -metatests.test('Collector: fail', async (test) => { +test('Collector: fail', async () => { const dc = collect(['key1']); setTimeout(() => { @@ -143,14 +143,13 @@ metatests.test('Collector: fail', async (test) => { try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'Custom error'); - test.end(); + assert.strictEqual(error.message, 'Custom error'); } }); -metatests.test('Collector: take', async (test) => { +test('Collector: take', async () => { const expectedResult = { key1: 'User: Marcus' }; const dc = collect(['key1']); @@ -162,11 +161,10 @@ metatests.test('Collector: take', async (test) => { dc.take('key1', fn, 'Marcus'); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: wait', async (test) => { +test('Collector: wait', async () => { const expectedResult = { key1: 'User: Marcus' }; const dc = collect(['key1']); @@ -177,11 +175,10 @@ metatests.test('Collector: wait', async (test) => { dc.wait('key1', fn, 'Marcus'); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: wait for promise', async (test) => { +test('Collector: wait for promise', async () => { const expectedResult = { key1: 'User: Marcus' }; const dc = collect(['key1']); @@ -191,11 +188,10 @@ metatests.test('Collector: wait for promise', async (test) => { dc.wait('key1', promise); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: compose collect', async (test) => { +test('Collector: compose collect', async () => { const expectedResult = { key1: { sub1: 11 }, key2: 2, key3: { sub3: 31 } }; const dc = collect(['key1', 'key2', 'key3']); const key1 = collect(['sub1']); @@ -215,11 +211,10 @@ metatests.test('Collector: compose collect', async (test) => { }, 150); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: after done', async (test) => { +test('Collector: after done', async () => { const expectedResult = { key1: 1, key2: 2 }; const dc = collect(['key1', 'key2']); @@ -227,11 +222,10 @@ metatests.test('Collector: after done', async (test) => { dc.set('key2', 2); const result = await dc; - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); -metatests.test('Collector: then chain', (test) => { +test('Collector: then chain', () => { const expectedResult = { key1: 1, key2: 2, key3: 3 }; const dc = collect(['key1', 'key2']); @@ -239,12 +233,11 @@ metatests.test('Collector: then chain', (test) => { dc.set('key2', 2); dc.then((result) => ({ ...result, key3: 3 })).then((result) => { - test.strictSame(result, expectedResult); - test.end(); + assert.deepStrictEqual(result, expectedResult); }); }); -metatests.test('Collector: error in then chain', (test) => { +test('Collector: error in then chain', () => { const expectedResult = new Error('expected error'); const dc = collect(['key1', 'key2']); @@ -255,18 +248,15 @@ metatests.test('Collector: error in then chain', (test) => { throw new Error('expected error'); }).then( () => { - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); }, (error) => { - test.strictSame(error.message, expectedResult.message); - test.end(); + assert.strictEqual(error.message, expectedResult.message); }, ); }); -metatests.test('Collector: reassign is off', async (test) => { - test.plan(1); - +test('Collector: reassign is off', async () => { const expectedError = new Error('Collector reassign mode is off'); const dc = collect(['key1', 'key2'], { reassign: false }); @@ -276,13 +266,13 @@ metatests.test('Collector: reassign is off', async (test) => { try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, expectedError.message); + assert.strictEqual(error.message, expectedError.message); } }); -metatests.test('Collector: abort', async (test) => { +test('Collector: abort', async () => { const dc = collect(['key1', 'key2'], { timeout: 200 }); setTimeout(() => { @@ -294,21 +284,20 @@ metatests.test('Collector: abort', async (test) => { }, 100); dc.signal.addEventListener('abort', (event) => { - test.strictSame(event.type, 'abort'); - test.assert(dc.signal.reason instanceof DOMException); - test.strictSame(dc.signal.reason.name, 'AbortError'); + assert.strictEqual(event.type, 'abort'); + assert(dc.signal.reason instanceof DOMException); + assert.strictEqual(dc.signal.reason.name, 'AbortError'); }); try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'Collector aborted'); - test.end(); + assert.strictEqual(error.message, 'Collector aborted'); } }); -metatests.test('Collector: validate scheme(valid)', async (test) => { +test('Collector: validate scheme(valid)', async () => { const from = (schema) => (data) => { for (const [key, value] of Object.entries(data)) { const type = schema[key]; @@ -330,12 +319,11 @@ metatests.test('Collector: validate scheme(valid)', async (test) => { try { await dc; } catch { - test.error(new Error('Should not be executed')); - test.end(); + assert.ifError(new Error('Should not be executed')); } }); -metatests.test('Collector: validate scheme(invalid)', async (test) => { +test('Collector: validate scheme(invalid)', async () => { const from = (schema) => (data) => { for (const [key, value] of Object.entries(data)) { const type = schema[key]; @@ -356,8 +344,8 @@ metatests.test('Collector: validate scheme(invalid)', async (test) => { try { await dc; - test.error(new Error('Should not be executed')); + assert.ifError(new Error('Should not be executed')); } catch (error) { - test.strictSame(error.message, 'Schema validate error'); + assert.strictEqual(error.message, 'Schema validate error'); } }); diff --git a/test/crypro.js b/test/crypro.js index fa50c1c..58fd34a 100644 --- a/test/crypro.js +++ b/test/crypro.js @@ -1,52 +1,52 @@ 'use strict'; +const test = require('node:test'); +const assert = require('node:assert'); const metatests = require('metatests'); const metautil = require('..'); -const testRandom = (test, random) => { +const testRandom = (random) => { { const value = random(100, 100); - test.strictSame(typeof value, 'number'); - test.strictSame(value, 100); + assert.strictEqual(typeof value, 'number'); + assert.strictEqual(value, 100); } { const value = random(-100, -100); - test.strictSame(typeof value, 'number'); - test.strictSame(value, -100); + assert.strictEqual(typeof value, 'number'); + assert.strictEqual(value, -100); } { const value = random(0, 0); - test.strictSame(typeof value, 'number'); - test.strictSame(value, 0); + assert.strictEqual(typeof value, 'number'); + assert.strictEqual(value, 0); } for (let i = 0; i < 200; i++) { const value = random(); - test.strictSame(typeof value, 'number'); - test.assert(value >= 0, true); - test.assert(value <= 1, true); + assert.strictEqual(typeof value, 'number'); + assert(value >= 0); + assert(value <= 1); } for (let i = 0; i < 200; i++) { const value = random(100); - test.strictSame(typeof value, 'number'); - test.assert(value >= 0, true); - test.assert(value <= 100, true); + assert.strictEqual(typeof value, 'number'); + assert(value >= 0); + assert(value <= 100); } for (let i = 0; i < 200; i++) { const value = random(100, 200); - test.strictSame(typeof value, 'number'); - test.assert(value >= 100, true); - test.assert(value <= 200, true); + assert.strictEqual(typeof value, 'number'); + assert(value >= 100); + assert(value <= 200); } }; -metatests.test('Crypto: cryptoRandom', async (test) => { - testRandom(test, metautil.cryptoRandom); - test.end(); +test('Crypto: cryptoRandom', async () => { + testRandom(metautil.cryptoRandom); }); -metatests.test('Crypto: random', async (test) => { - testRandom(test, metautil.random); - test.end(); +test('Crypto: random', async () => { + testRandom(metautil.random); }); const CHARS = 'ABCD'; @@ -101,37 +101,34 @@ metatests.case( }, ); -metatests.test('Crypto: hashing passwords', async (test) => { +test('Crypto: hashing passwords', async () => { const password = 'password'; const hash = await metautil.hashPassword(password); - test.strictSame(typeof hash, 'string'); - test.strictSame(hash.length, 170); + assert.strictEqual(typeof hash, 'string'); + assert.strictEqual(hash.length, 170); const res = metautil.deserializeHash(hash); - test.strictEqual(res.params.N, 32768); - test.strictEqual(res.params.r, 8); - test.strictEqual(res.params.p, 1); - test.strictEqual(res.params.maxmem, 67108864); - test.strictEqual(res.salt.length, 32); - test.strictEqual(res.hash.length, 64); + assert.strictEqual(res.params.N, 32768); + assert.strictEqual(res.params.r, 8); + assert.strictEqual(res.params.p, 1); + assert.strictEqual(res.params.maxmem, 67108864); + assert.strictEqual(res.salt.length, 32); + assert.strictEqual(res.hash.length, 64); const serialized = metautil.serializeHash(res.hash, res.salt); - test.strictSame(serialized.length, 170); + assert.strictEqual(serialized.length, 170); const valid = await metautil.validatePassword(password, hash); - test.strictSame(valid, true); - - test.end(); + assert(valid, true); }); -metatests.test('Crypto: md5', async (test) => { +test('Crypto: md5', async () => { const hash = await metautil.md5('./.npmignore'); - test.strictSame(hash, '8278a9c6e40823bd7fde51d4ce8ac3f8'); - test.end(); + assert.strictEqual(hash, '8278a9c6e40823bd7fde51d4ce8ac3f8'); }); -metatests.test('Crypto: x509 names', async (test) => { +test('Crypto: x509 names', async () => { const cert = { subject: 'CN=localhost', subjectAltName: @@ -147,6 +144,5 @@ metatests.test('Crypto: x509 names', async (test) => { 'hello1.example.com', 'hello2.example.com', ]; - test.strictSame(names, expected); - test.end(); + assert.deepStrictEqual(names, expected); }); diff --git a/test/error.js b/test/error.js index 5d752d7..b14b905 100644 --- a/test/error.js +++ b/test/error.js @@ -1,9 +1,12 @@ 'use strict'; +const test = require('node:test'); +const assert = require('node:assert'); + const metatests = require('metatests'); const metautil = require('..'); -metatests.test('Error', async (test) => { +test('Error', async () => { const errors = { ENOUSER: 'User not found', ENEGPRICE: 'Negative price', @@ -11,51 +14,49 @@ metatests.test('Error', async (test) => { }; const e1 = new metautil.Error('Custom error', 1001); - test.strictSame(typeof e1.stack, 'string'); - test.strictSame(e1 instanceof Error, true); - test.strictSame(e1 instanceof metautil.Error, true); - test.strictSame(e1.message, 'Custom error'); - test.strictSame(e1.code, 1001); - test.strictSame(e1.cause, undefined); + assert.strictEqual(typeof e1.stack, 'string'); + assert(e1 instanceof Error); + assert(e1 instanceof metautil.Error); + assert.strictEqual(e1.message, 'Custom error'); + assert.strictEqual(e1.code, 1001); + assert.strictEqual(e1.cause, undefined); const e2 = new metautil.Error('Ups', { code: 1001, cause: e1 }); - test.strictSame(e2.code, 1001); - test.strictSame(e2.cause, e1); + assert.strictEqual(e2.code, 1001); + assert.strictEqual(e2.cause, e1); const e3 = new metautil.Error('Something went wrong'); - test.strictSame(e3.code, undefined); - test.strictSame(e3.cause, undefined); + assert.strictEqual(e3.code, undefined); + assert.strictEqual(e3.cause, undefined); const e4 = new metautil.Error('Something went wrong', 'ERRCODE'); - test.strictSame(e4.code, 'ERRCODE'); + assert.strictEqual(e4.code, 'ERRCODE'); const de1 = new metautil.DomainError('ENOUSER'); - test.strictSame(de1.message, 'Domain error'); - test.strictSame(de1.code, 'ENOUSER'); + assert.strictEqual(de1.message, 'Domain error'); + assert.strictEqual(de1.code, 'ENOUSER'); const e5 = de1.toError(errors); - test.strictSame(e5.message, 'User not found'); - test.strictSame(e5.code, 'ENOUSER'); + assert.strictEqual(e5.message, 'User not found'); + assert.strictEqual(e5.code, 'ENOUSER'); const de2 = new metautil.DomainError('ERR', { code: 'CODE' }); - test.strictSame(de2.message, 'Domain error'); - test.strictSame(de2.code, 'ERR'); + assert.strictEqual(de2.message, 'Domain error'); + assert.strictEqual(de2.code, 'ERR'); const e6 = de2.toError(errors); - test.strictSame(e6.message, 'Domain error'); - test.strictSame(e6.code, 'ERR'); + assert.strictEqual(e6.message, 'Domain error'); + assert.strictEqual(e6.code, 'ERR'); const de3 = new metautil.DomainError('ERR', { code: 'CODE', cause: e1 }); - test.strictSame(de3.message, 'Domain error'); - test.strictSame(de3.code, 'ERR'); - test.strictSame(de3.cause, e1); + assert.strictEqual(de3.message, 'Domain error'); + assert.strictEqual(de3.code, 'ERR'); + assert.strictEqual(de3.cause, e1); const de4 = new metautil.DomainError({ code: 'CODE', cause: e1 }); - test.strictSame(de4.message, 'Domain error'); - test.strictSame(de4.code, 'CODE'); - test.strictSame(de4.cause, e1); - - test.end(); + assert.strictEqual(de4.message, 'Domain error'); + assert.strictEqual(de4.code, 'CODE'); + assert.strictEqual(de4.cause, e1); }); class ExampleError {} diff --git a/test/events.js b/test/events.js index a21281d..c3cd502 100644 --- a/test/events.js +++ b/test/events.js @@ -1,35 +1,36 @@ 'use strict'; -const metatests = require('metatests'); +const test = require('node:test'); +const assert = require('node:assert'); const metautil = require('..'); -metatests.test('EventEmitter', async (test) => { +test('EventEmitter', async () => { const ee = new metautil.EventEmitter(); - test.strictSame(ee.getMaxListeners(), 10); - test.assert(ee.events instanceof Map); + assert.strictEqual(ee.getMaxListeners(), 10); + assert(ee.events instanceof Map); let onCount = 0; let onceCount = 0; ee.on('name1', (data) => { - test.strictSame(data, 'value'); + assert.strictEqual(data, 'value'); onCount++; }); ee.once('name1', (data) => { - test.strictSame(data, 'value'); + assert.strictEqual(data, 'value'); onceCount++; }); ee.emit('name1', 'value'); ee.emit('name1', 'value'); - test.strictSame(onCount, 2); - test.strictSame(onceCount, 1); + assert.strictEqual(onCount, 2); + assert.strictEqual(onceCount, 1); - test.strictSame(ee.listenerCount('name1'), 1); - test.strictSame(ee.listenerCount('name2'), 0); + assert.strictEqual(ee.listenerCount('name1'), 1); + assert.strictEqual(ee.listenerCount('name2'), 0); let count = 0; const fn = () => { @@ -37,27 +38,25 @@ metatests.test('EventEmitter', async (test) => { }; ee.on('name1', fn); ee.emit('name1', 'value'); - test.strictSame(count, 1); + assert.strictEqual(count, 1); - test.strictSame(ee.listenerCount('name1'), 2); + assert.strictEqual(ee.listenerCount('name1'), 2); ee.remove('name1', fn); - test.strictSame(ee.listenerCount('name1'), 1); + assert.strictEqual(ee.listenerCount('name1'), 1); ee.emit('name1', 'value'); - test.strictSame(count, 1); + assert.strictEqual(count, 1); ee.clear('name1'); - test.strictSame(ee.listenerCount('name1'), 0); + assert.strictEqual(ee.listenerCount('name1'), 0); setTimeout(() => { ee.emit('name3', 'value'); }, 50); const result = await metautil.once(ee, 'name3'); - test.strictSame(result, 'value'); + assert.strictEqual(result, 'value'); ee.clear(); - test.strictSame(ee.listenerCount('name3'), 0); - - test.end(); + assert.strictEqual(ee.listenerCount('name3'), 0); }); diff --git a/test/fs.js b/test/fs.js index 57ddd0e..00b34d5 100644 --- a/test/fs.js +++ b/test/fs.js @@ -2,27 +2,27 @@ const fsp = require('node:fs').promises; const path = require('node:path'); +const test = require('node:test'); +const assert = require('node:assert'); const metatests = require('metatests'); const metautil = require('..'); const { directoryExists, ensureDirectory } = metautil; -metatests.test('Fs: directoryExists', async (test) => { +test('Fs: directoryExists', async () => { const exists1 = await directoryExists('./test'); - test.strictSame(exists1, true); + assert.strictEqual(exists1, true); const exists2 = await directoryExists('./abrvalg'); - test.strictSame(exists2, false); - test.end(); + assert.strictEqual(exists2, false); }); -metatests.test('Fs: ensureDirectory', async (test) => { +test('Fs: ensureDirectory', async () => { const created1 = await ensureDirectory('./abc'); - test.strictSame(created1, true); + assert.strictEqual(created1, true); const created2 = await ensureDirectory('./abc'); - test.strictSame(created2, true); + assert.strictEqual(created2, true); await fsp.rmdir('./abc'); const created3 = await ensureDirectory('./LICENSE'); - test.strictSame(created3, false); - test.end(); + assert.strictEqual(created3, false); }); metatests.case( diff --git a/test/network.js b/test/network.js index 6798618..499d693 100644 --- a/test/network.js +++ b/test/network.js @@ -2,6 +2,8 @@ const http = require('node:http'); const { once } = require('node:events'); +const test = require('node:test'); +const assert = require('node:assert'); const metatests = require('metatests'); const metautil = require('..'); @@ -12,7 +14,7 @@ const RATES_API_KEY = '9e329e4313bc4462b04e07f314c6f7eb'; const RATES_API_URL = `https://${RATES_HOST}/${RATES_PATH}${RATES_API_KEY}`; const MATH_API_URL = 'https://api.mathjs.org/v4'; -metatests.test('Newtork: receiveBody', async (test) => { +test('Newtork: receiveBody', async () => { const value = Buffer.from('{ "a": 5 }'); let done = false; const body = { @@ -27,8 +29,7 @@ metatests.test('Newtork: receiveBody', async (test) => { }, }; const data = await metautil.receiveBody(body); - test.strictSame(data.toString(), '{ "a": 5 }'); - test.end(); + assert.strictEqual(data.toString(), '{ "a": 5 }'); }); metatests.case( @@ -75,31 +76,29 @@ metatests.case( }, ); -metatests.test('Network: httpApiCall', async (test) => { +test('Network: httpApiCall', async () => { const res1 = await metautil.httpApiCall(RATES_API_URL, { method: 'GET' }); - test.strictSame(typeof res1.disclaimer, 'string'); - test.strictSame(typeof res1.license, 'string'); - test.strictSame(typeof res1.timestamp, 'number'); - test.strictSame(res1.base, 'USD'); - test.strictSame(typeof res1.rates, 'object'); - test.strictSame(typeof res1.rates['UAH'], 'number'); + assert.strictEqual(typeof res1.disclaimer, 'string'); + assert.strictEqual(typeof res1.license, 'string'); + assert.strictEqual(typeof res1.timestamp, 'number'); + assert.strictEqual(res1.base, 'USD'); + assert.strictEqual(typeof res1.rates, 'object'); + assert.strictEqual(typeof res1.rates['UAH'], 'number'); const body = '{"expr":"2+3*sqrt(4)","precision":3}'; const options = { method: 'POST', body }; const res2 = await metautil.httpApiCall(MATH_API_URL, options); - test.strictSame(Object.keys(res2), ['result', 'error']); - test.strictSame(res2.result, '8'); - test.strictSame(res2.error, null); + assert.deepStrictEqual(Object.keys(res2), ['result', 'error']); + assert.strictEqual(res2.result, '8'); + assert.strictEqual(res2.error, null); const res3 = await metautil.httpApiCall(MATH_API_URL, { body }); - test.strictSame(Object.keys(res3), ['result', 'error']); - test.strictSame(res3.result, '8'); - test.strictSame(res3.error, null); - - test.end(); + assert.deepStrictEqual(Object.keys(res3), ['result', 'error']); + assert.strictEqual(res3.result, '8'); + assert.strictEqual(res3.error, null); }); -metatests.test('Network: httpApiCall (POST)', async (test) => { +test('Network: httpApiCall (POST)', async () => { const expectedBody = '{"key":"value"}'; const expectedLength = Buffer.byteLength(expectedBody).toString(); @@ -109,11 +108,11 @@ metatests.test('Network: httpApiCall (POST)', async (test) => { let body = ''; for await (const chunk of req) body += chunk; - test.strictSame(body, expectedBody); - test.strictSame(req.headers['content-length'], expectedLength); - test.strictSame(req.headers['content-type'], 'application/json'); - test.strictSame(req.headers['custom-header'], 'custom-value'); - test.strictSame(req.method, 'POST'); + assert.strictEqual(body, expectedBody); + assert.strictEqual(req.headers['content-length'], expectedLength); + assert.strictEqual(req.headers['content-type'], 'application/json'); + assert.strictEqual(req.headers['custom-header'], 'custom-value'); + assert.strictEqual(req.method, 'POST'); res.end('{"key":"value"}'); }); @@ -129,26 +128,26 @@ metatests.test('Network: httpApiCall (POST)', async (test) => { try { const res = await metautil.httpApiCall(url, { method, headers, body }); - test.strictSame(res, { key: 'value' }); + assert.deepStrictEqual(res, { key: 'value' }); } catch (err) { - test.error(err); + assert.ifError(err); } server.close(); }); -metatests.test('Network: httpApiCall (POST without body)', async (test) => { +test('Network: httpApiCall (POST without body)', async () => { const server = http.createServer(); server.on('request', async (req, res) => { let body = ''; for await (const chunk of req) body += chunk; - test.strictSame(req.headers['content-length'], '0'); - test.strictSame(req.headers['content-type'], 'application/json'); - test.strictSame(req.headers['custom-header'], 'custom-value'); - test.strictSame(req.method, 'POST'); - test.strictSame(body, ''); + assert.strictEqual(req.headers['content-length'], '0'); + assert.strictEqual(req.headers['content-type'], 'application/json'); + assert.strictEqual(req.headers['custom-header'], 'custom-value'); + assert.strictEqual(req.method, 'POST'); + assert.strictEqual(body, ''); res.end('{"key":"value"}'); }); @@ -162,22 +161,22 @@ metatests.test('Network: httpApiCall (POST without body)', async (test) => { try { const res = await metautil.httpApiCall(url, { method: 'POST', headers }); - test.strictSame(res, { key: 'value' }); + assert.deepStrictEqual(res, { key: 'value' }); } catch (err) { - test.error(err); + assert.ifError(err); } server.close(); }); -metatests.test('Network: httpApiCall (GET)', async (test) => { +test('Network: httpApiCall (GET)', async () => { const server = http.createServer(); server.on('request', (req, res) => { - test.strictSame(req.headers['content-length'], undefined); - test.strictSame(req.headers['content-type'], 'application/json'); - test.strictSame(req.headers['custom-header'], 'custom-value'); - test.strictSame(req.method, 'GET'); + assert.strictEqual(req.headers['content-length'], undefined); + assert.strictEqual(req.headers['content-type'], 'application/json'); + assert.strictEqual(req.headers['custom-header'], 'custom-value'); + assert.strictEqual(req.method, 'GET'); res.end('{"key":"value"}'); }); @@ -191,9 +190,9 @@ metatests.test('Network: httpApiCall (GET)', async (test) => { try { const res = await metautil.httpApiCall(url, { method: 'GET', headers }); - test.strictSame(res, { key: 'value' }); + assert.deepStrictEqual(res, { key: 'value' }); } catch (err) { - test.error(err); + assert.ifError(err); } server.close(); diff --git a/test/objects.js b/test/objects.js index ce4c24e..b1d2f28 100644 --- a/test/objects.js +++ b/test/objects.js @@ -1,9 +1,11 @@ 'use strict'; +const test = require('node:test'); +const assert = require('node:assert'); const metatests = require('metatests'); const metautil = require('..'); -metatests.test('Object: makePrivate', (test) => { +test('Object: makePrivate', () => { const obj = { field: 'value', CONSTANT: 1000, @@ -12,16 +14,15 @@ metatests.test('Object: makePrivate', (test) => { }, }; const iface = metautil.makePrivate(obj); - test.strictSame(typeof iface, 'object'); - test.strictSame(obj === iface, false); - test.strictSame(iface.field, undefined); - test.strictSame(iface.CONSTANT, 1000); - test.strictSame(typeof iface.method, 'function'); - test.strictSame(iface.method(3, 5), 8); - test.end(); + assert.strictEqual(typeof iface, 'object'); + assert.strictEqual(obj === iface, false); + assert.strictEqual(iface.field, undefined); + assert.strictEqual(iface.CONSTANT, 1000); + assert.strictEqual(typeof iface.method, 'function'); + assert.strictEqual(iface.method(3, 5), 8); }); -metatests.test('Object: protect', (test) => { +test('Object: protect', () => { const obj1 = { field1: 'value1', module1: { @@ -41,28 +42,26 @@ metatests.test('Object: protect', (test) => { metautil.protect(['module1'], obj1, obj2); try { obj1.field1 = 100; - test.strictSame(obj1.field1, 100); + assert.strictEqual(obj1.field1, 100); obj1.module1.method = () => {}; - test.strictSame(obj1.module1.method(3, 5), undefined); + assert.strictEqual(obj1.module1.method(3, 5), undefined); } catch (err) { - test.error(err); + assert.ifError(err); } try { obj2.field1 = 200; - test.strictSame(obj2.field1, 200); + assert.strictEqual(obj2.field1, 200); obj2.module2.method = () => {}; - test.strictSame(obj2.module2.method(3, 5), 8); + assert.strictEqual(obj2.module2.method(3, 5), 8); } catch (err) { - test.strictSame(err.constructor.name, 'TypeError'); + assert.strictEqual(err.constructor.name, 'TypeError'); } - test.end(); }); -metatests.test('Introspection: getSignature', async (test) => { +test('Introspection: getSignature', async () => { const method = ({ a, b, c }) => ({ a, b, c }); const signature = metautil.getSignature(method); - test.strictSame(signature, ['a', 'b', 'c']); - test.end(); + assert.deepStrictEqual(signature, ['a', 'b', 'c']); }); metatests.case( @@ -78,7 +77,7 @@ metatests.case( }, ); -metatests.test('Object: flatFields with keys names', (test) => { +test('Object: flatFields with keys names', () => { const source = { name: { first: 'Andrew', second: 'Johnson' }, old: true, @@ -96,11 +95,10 @@ metatests.test('Object: flatFields with keys names', (test) => { const result = metautil.flatObject(source, ['name', 'parent']); - test.strictSame(result, expected); - test.end(); + assert.deepStrictEqual(result, expected); }); -metatests.test('Object: flatFields duplicate key', (test) => { +test('Object: flatFields duplicate key', () => { const source = { name: { first: 'Andrew', second: 'Johnson' }, nameFirst: 'Andrew', @@ -108,15 +106,13 @@ metatests.test('Object: flatFields duplicate key', (test) => { parent: { mother: 'Eva', father: 'Adam' }, }; - test.throws( + assert.throws( () => metautil.flatObject(source), new Error('Can not combine keys: key "nameFirst" already exists'), ); - - test.end(); }); -metatests.test('Object: unflatFields with key names', (test) => { +test('Object: unflatFields with key names', () => { const fieldNames = ['name', 'parent']; const source = { @@ -137,11 +133,10 @@ metatests.test('Object: unflatFields with key names', (test) => { const result = metautil.unflatObject(source, fieldNames); - test.strictSame(result, expected); - test.end(); + assert.deepStrictEqual(result, expected); }); -metatests.test('Object: unflatFields naming collision', (test) => { +test('Object: unflatFields naming collision', () => { const fieldNames = ['name', 'parent']; const source = { @@ -154,15 +149,13 @@ metatests.test('Object: unflatFields naming collision', (test) => { parentFather: 'Adam', }; - test.throws( + assert.throws( () => metautil.unflatObject(source, fieldNames), new Error('Can not combine keys: key "name" already exists'), ); - - test.end(); }); -metatests.test('Object: namespaceByPath', (test) => { +test('Object: namespaceByPath', () => { const ns = { module1: { method(a, b) { @@ -176,23 +169,22 @@ metatests.test('Object: namespaceByPath', (test) => { }, }; const ent1 = metautil.namespaceByPath(ns, 'module2.method'); - test.strictSame(ent1, ns.module2.method); + assert.strictEqual(ent1, ns.module2.method); const ent2 = metautil.namespaceByPath(ns, 'module1.unknown'); - test.strictSame(ent2, null); + assert.strictEqual(ent2, null); const ent3 = metautil.namespaceByPath(ns, 'module3.method'); - test.strictSame(ent3, null); + assert.strictEqual(ent3, null); const ent4 = metautil.namespaceByPath(ns, 'unknown.unknown'); - test.strictSame(ent4, null); + assert.strictEqual(ent4, null); const ent5 = metautil.namespaceByPath(ns, 'module1'); - test.strictSame(ent5, ns.module1); + assert.strictEqual(ent5, ns.module1); const ent6 = metautil.namespaceByPath(ns, 'module3'); - test.strictSame(ent6, null); + assert.strictEqual(ent6, null); const ent7 = metautil.namespaceByPath(ns, ''); - test.strictSame(ent7, null); - test.end(); + assert.strictEqual(ent7, null); }); -metatests.test('Object: flatFields', (test) => { +test('Object: flatFields', () => { const source = { name: { first: 'Andrew', second: 'Johnson' }, old: true, @@ -210,8 +202,7 @@ metatests.test('Object: flatFields', (test) => { const result = metautil.flatObject(source); - test.strictSame(result, expected); - test.end(); + assert.deepStrictEqual(result, expected); }); metatests.case( diff --git a/test/pool.js b/test/pool.js index 4725228..bc50b9d 100644 --- a/test/pool.js +++ b/test/pool.js @@ -1,9 +1,10 @@ 'use strict'; -const metatests = require('metatests'); +const test = require('node:test'); +const assert = require('node:assert'); const metautil = require('..'); -metatests.test('Pool: add/next', async (test) => { +test('Pool: add/next', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -13,20 +14,18 @@ metatests.test('Pool: add/next', async (test) => { const obj3 = { a: 3 }; pool.add(obj3); - test.strictSame(await pool.next(), obj1); - test.strictSame(await pool.next(), obj2); - test.strictSame(await pool.next(), obj3); - test.strictSame(await pool.next(), obj1); - test.end(); + assert.strictEqual(await pool.next(), obj1); + assert.strictEqual(await pool.next(), obj2); + assert.strictEqual(await pool.next(), obj3); + assert.strictEqual(await pool.next(), obj1); }); -metatests.test('Pool: empty', async (test) => { +test('Pool: empty', async () => { const pool = new metautil.Pool(); - test.strictSame(await pool.next(), null); - test.end(); + assert.strictEqual(await pool.next(), null); }); -metatests.test('Pool: capture/next', async (test) => { +test('Pool: capture/next', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -36,30 +35,29 @@ metatests.test('Pool: capture/next', async (test) => { const obj3 = { a: 3 }; pool.add(obj3); - test.strictSame(pool.isFree(obj1), true); - test.strictSame(pool.isFree(obj2), true); - test.strictSame(pool.isFree(obj3), true); + assert.strictEqual(pool.isFree(obj1), true); + assert.strictEqual(pool.isFree(obj2), true); + assert.strictEqual(pool.isFree(obj3), true); const item = await pool.capture(); - test.strictSame(item, obj1); - test.strictSame(pool.isFree(item), false); - test.strictSame(await pool.next(), obj2); - test.strictSame(await pool.next(), obj3); - test.strictSame(await pool.next(), obj2); + assert.strictEqual(item, obj1); + assert.strictEqual(pool.isFree(item), false); + assert.strictEqual(await pool.next(), obj2); + assert.strictEqual(await pool.next(), obj3); + assert.strictEqual(await pool.next(), obj2); pool.release(item); - test.strictSame(pool.isFree(item), true); + assert.strictEqual(pool.isFree(item), true); try { pool.release(item); } catch (err) { - test.strictSame(err.message, 'Pool: release not captured'); + assert.strictEqual(err.message, 'Pool: release not captured'); } - test.strictSame(await pool.next(), obj3); - test.strictSame(await pool.next(), obj1); - test.end(); + assert.strictEqual(await pool.next(), obj3); + assert.strictEqual(await pool.next(), obj1); }); -metatests.test('Pool: capture/release', async (test) => { +test('Pool: capture/release', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -70,19 +68,18 @@ metatests.test('Pool: capture/release', async (test) => { pool.add(obj3); const item1 = await pool.capture(); - test.strictSame(item1, obj1); + assert.strictEqual(item1, obj1); const item2 = await pool.capture(); - test.strictSame(item2, obj2); + assert.strictEqual(item2, obj2); const item3 = await pool.capture(); - test.strictSame(item3, obj3); + assert.strictEqual(item3, obj3); pool.release(obj3); const item4 = await pool.capture(); - test.strictSame(item4, obj3); - test.end(); + assert.strictEqual(item4, obj3); }); -metatests.test('Pool: wait for release', async (test) => { +test('Pool: wait for release', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -94,18 +91,17 @@ metatests.test('Pool: wait for release', async (test) => { const item2 = await pool.capture(); pool.capture().then((item3) => { - test.strictSame(item3, obj2); + assert.strictEqual(item3, obj2); }); pool.capture().then((item4) => { - test.strictSame(item4, obj1); + assert.strictEqual(item4, obj1); }); pool.release(item2); pool.release(item1); - test.end(); }); -metatests.test('Pool: wait timeout', async (test) => { +test('Pool: wait timeout', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -114,21 +110,21 @@ metatests.test('Pool: wait timeout', async (test) => { pool.add(obj2); const item1 = await pool.capture(); - test.strictSame(item1, obj1); + assert.strictEqual(item1, obj1); const item2 = await pool.capture(); - test.strictSame(item2, obj2); + assert.strictEqual(item2, obj2); pool.capture().then((item3) => { - test.strictSame(item3, obj2); + assert.strictEqual(item3, obj2); }); pool.capture().catch((err) => { - test.strictSame(err.message, 'Pool next item timeout'); + assert.strictEqual(err.message, 'Pool next item timeout'); }); pool.release(obj2); }); -metatests.test('Pool: sync capture timeout', (test) => { +test('Pool: sync capture timeout', () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -141,20 +137,19 @@ metatests.test('Pool: sync capture timeout', (test) => { const p3 = pool.capture(); p1.then((item1) => { - test.strictSame(item1, obj1); + assert.strictEqual(item1, obj1); }); p2.then((item2) => { - test.strictSame(item2, obj2); + assert.strictEqual(item2, obj2); }); p3.catch((err) => { - test.strictSame(err.message, 'Pool next item timeout'); - test.end(); + assert.strictEqual(err.message, 'Pool next item timeout'); }); }); -metatests.test('Pool: prevent infinite loop', async (test) => { +test('Pool: prevent infinite loop', async () => { const pool = new metautil.Pool(); const obj1 = { a: 1 }; @@ -164,15 +159,13 @@ metatests.test('Pool: prevent infinite loop', async (test) => { await pool.next(); const item1 = await pool.capture(); - test.strictSame(item1, obj2); + assert.strictEqual(item1, obj2); await pool.next(); const item2 = await pool.capture(); - test.strictSame(item2, obj1); - - test.end(); + assert.strictEqual(item2, obj1); }); -metatests.test('Pool: release to queue', async (test) => { +test('Pool: release to queue', async () => { const pool = new metautil.Pool(); const obj = { a: 1 }; @@ -180,12 +173,10 @@ metatests.test('Pool: release to queue', async (test) => { const item = await pool.capture(); pool.capture().then((item) => { - test.assert(pool.available === 0); - test.assert(!pool.isFree(item)); - test.strictSame(item, obj); + assert(pool.available === 0); + assert(!pool.isFree(item)); + assert.strictEqual(item, obj); }); pool.release(item); - - test.end(); }); diff --git a/test/semaphore.js b/test/semaphore.js index 98fe6c3..e788ddd 100644 --- a/test/semaphore.js +++ b/test/semaphore.js @@ -1,6 +1,7 @@ 'use strict'; -const metatests = require('metatests'); +const test = require('node:test'); +const assert = require('node:assert'); const { Semaphore, delay } = require('..'); const concurrency = 3; @@ -8,90 +9,87 @@ const size = 4; const timeout = 1500; const options = { concurrency, size, timeout }; -metatests.test('Semaphore', async (test) => { +test('Semaphore', async () => { const semaphore = new Semaphore(options); - test.strictSame(semaphore.concurrency, concurrency); - test.strictSame(semaphore.empty, true); + assert.strictEqual(semaphore.concurrency, concurrency); + assert.strictEqual(semaphore.empty, true); await semaphore.enter(); - test.strictSame(semaphore.counter, concurrency - 1); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 1); + assert.strictEqual(semaphore.empty, false); await semaphore.enter(); - test.strictSame(semaphore.counter, concurrency - 2); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 2); + assert.strictEqual(semaphore.empty, false); await semaphore.enter(); - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.empty, false); try { await semaphore.enter(); } catch (err) { - test.assert(err); + assert(err); } - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency - 2); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 2); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency - 1); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 1); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency); - test.strictSame(semaphore.empty, true); - test.end(); + assert.strictEqual(semaphore.counter, concurrency); + assert.strictEqual(semaphore.empty, true); }); -metatests.test('Semaphore default', async (test) => { +test('Semaphore default', async () => { const semaphore = new Semaphore({ concurrency }); - test.strictSame(semaphore.concurrency, concurrency); - test.strictSame(semaphore.empty, true); + assert.strictEqual(semaphore.concurrency, concurrency); + assert.strictEqual(semaphore.empty, true); await semaphore.enter(); - test.strictSame(semaphore.counter, concurrency - 1); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 1); + assert.strictEqual(semaphore.empty, false); await semaphore.enter(); - test.strictSame(semaphore.counter, concurrency - 2); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 2); + assert.strictEqual(semaphore.empty, false); await semaphore.enter(); - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.empty, false); try { await semaphore.enter(); } catch (err) { - test.assert(err); + assert(err); } - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency - 2); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 2); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency - 1); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, concurrency - 1); + assert.strictEqual(semaphore.empty, false); semaphore.leave(); - test.strictSame(semaphore.counter, concurrency); - test.strictSame(semaphore.empty, true); - test.end(); + assert.strictEqual(semaphore.counter, concurrency); + assert.strictEqual(semaphore.empty, true); }); -metatests.test('Semaphore timeout', async (test) => { +test('Semaphore timeout', async () => { const semaphore = new Semaphore(options); await semaphore.enter(); await semaphore.enter(); await semaphore.enter(); - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.queue.length, 0); - test.strictSame(semaphore.empty, false); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.queue.length, 0); + assert.strictEqual(semaphore.empty, false); try { await semaphore.enter(); } catch (err) { - test.assert(err); + assert(err); } - test.strictSame(semaphore.counter, 0); - test.strictSame(semaphore.queue.length, 0); - test.strictSame(semaphore.empty, false); - test.end(); + assert.strictEqual(semaphore.counter, 0); + assert.strictEqual(semaphore.queue.length, 0); + assert.strictEqual(semaphore.empty, false); }); -metatests.test('Semaphore real life usage', async (test) => { +test('Semaphore real life usage', async () => { const semaphore = new Semaphore(options); const useSemaphore = async () => { @@ -114,40 +112,39 @@ metatests.test('Semaphore real life usage', async (test) => { promises.push(useSemaphore()); } await Promise.all(promises); - test.strictSame(semaphore.empty, true); - test.strictSame(semaphore.queue.length, 0); - test.strictSame(semaphore.counter, concurrency); - test.end(); + assert.strictEqual(semaphore.empty, true); + assert.strictEqual(semaphore.queue.length, 0); + assert.strictEqual(semaphore.counter, concurrency); }); -metatests.test('Semaphore detailed counter fix test', async (test) => { +test('Semaphore detailed counter fix test', async () => { const semaphore = new Semaphore(options); await semaphore.enter(); await semaphore.enter(); await semaphore.enter(); - test.strictSame(semaphore.counter, 0); + assert.strictEqual(semaphore.counter, 0); semaphore.enter().then(() => { - test.assert(true); + assert(true); }); semaphore.enter().catch((err) => { - test.strictSame(err.message, 'Semaphore timeout'); + assert.strictEqual(err.message, 'Semaphore timeout'); }); semaphore.enter().catch((err) => { - test.strictSame(err.message, 'Semaphore timeout'); + assert.strictEqual(err.message, 'Semaphore timeout'); }); semaphore.enter().catch((err) => { - test.strictSame(err.message, 'Semaphore timeout'); + assert.strictEqual(err.message, 'Semaphore timeout'); }); - test.strictSame(semaphore.queue.length, size); + assert.strictEqual(semaphore.queue.length, size); await semaphore .enter() - .catch((err) => test.strictSame(err.message, 'Semaphore queue is full')); + .catch((err) => assert.strictEqual(err.message, 'Semaphore queue is full')); semaphore.leave(); setTimeout(() => { - test.strictSame(semaphore.counter, 0); + assert.strictEqual(semaphore.counter, 0); }, timeout + 200); });