From 40735cd1069e718dcaa5022fcec99587d3939436 Mon Sep 17 00:00:00 2001 From: Stephen Cresswell <229672+cressie176@users.noreply.github.com> Date: Sun, 7 Sep 2025 20:03:07 +0100 Subject: [PATCH] Switch to mocha bdd style in preparation for moving to node test runner --- Makefile | 6 +- biome.json | 3 +- test/bitset.js | 18 +++--- test/callback_api.js | 54 ++++++---------- test/channel.js | 150 +++++++++++++++++++++---------------------- test/channel_api.js | 18 +++--- test/codec.js | 16 ++--- test/connect.js | 42 ++++++------ test/connection.js | 48 +++++++------- test/data.js | 4 +- test/frame.js | 20 +++--- test/mux.js | 12 ++-- test/util.js | 10 ++- 13 files changed, 190 insertions(+), 211 deletions(-) diff --git a/Makefile b/Makefile index b8a7a464..f7f9c13a 100644 --- a/Makefile +++ b/Makefile @@ -16,16 +16,16 @@ error: @exit 1 test: - $(MOCHA) --check-leaks -u tdd --exit test/ + $(MOCHA) --check-leaks --exit test/ test-all-nodejs: for v in $(NODEJS_VERSIONS); \ do echo "-- Node version $$v --"; \ - nave use $$v $(MOCHA) -u tdd --exit -R progress test; \ + nave use $$v $(MOCHA) --exit -R progress test; \ done coverage: $(NYC) - $(NYC) --clean --reporter=lcov --reporter=text $(_MOCHA) -u tdd --exit -R progress test/ + $(NYC) --clean --reporter=lcov --reporter=text $(_MOCHA) --exit -R progress test/ @echo "HTML report at file://$$(pwd)/coverage/lcov-report/index.html" lib/defs.js: clean bin/generate-defs test diff --git a/biome.json b/biome.json index e0bbd0d1..28c6ac60 100644 --- a/biome.json +++ b/biome.json @@ -26,7 +26,8 @@ "noGlobalIsNan": "error", "noGlobalIsFinite": "error", "noPrototypeBuiltins": "error", - "noVar": "error" + "noVar": "error", + "noExportsInTest": "off" }, "style": { "useSingleVarDeclarator": "error" diff --git a/test/bitset.js b/test/bitset.js index aa811b93..8c6ae1b2 100644 --- a/test/bitset.js +++ b/test/bitset.js @@ -6,15 +6,15 @@ const { forAll, data: arb, label, choice, transform } = claire; const PosInt = transform(Math.floor, arb.Positive); const EmptyBitSet = label('bitset', transform((size) => new BitSet(size), choice(arb.Nothing, PosInt))); -suite('BitSet', () => { - test('get bit', forAll(EmptyBitSet, PosInt) +describe('BitSet', () => { + it('get bit', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); return b.get(bit); }) .asTest()); - test('clear bit', forAll(EmptyBitSet, PosInt) + it('clear bit', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); b.clear(bit); @@ -22,40 +22,40 @@ suite('BitSet', () => { }) .asTest()); - test('next set of empty', forAll(EmptyBitSet) + it('next set of empty', forAll(EmptyBitSet) .satisfy((b) => { return b.nextSetBit(0) === -1; }) .asTest()); - test('next set of one bit', forAll(EmptyBitSet, PosInt) + it('next set of one bit', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); return b.nextSetBit(0) === bit; }) .asTest()); - test('next set same bit', forAll(EmptyBitSet, PosInt) + it('next set same bit', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); return b.nextSetBit(bit) === bit; }) .asTest()); - test('next set following bit', forAll(EmptyBitSet, PosInt) + it('next set following bit', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); return b.nextSetBit(bit + 1) === -1; }) .asTest()); - test('next clear of empty', forAll(EmptyBitSet, PosInt) + it('next clear of empty', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { return b.nextClearBit(bit) === bit; }) .asTest()); - test('next clear of one set', forAll(EmptyBitSet, PosInt) + it('next clear of one set', forAll(EmptyBitSet, PosInt) .satisfy((b, bit) => { b.set(bit); return b.nextClearBit(bit) === bit + 1; diff --git a/test/callback_api.js b/test/callback_api.js index 6266b6a2..a1ddbc6e 100644 --- a/test/callback_api.js +++ b/test/callback_api.js @@ -63,14 +63,14 @@ function waitForMessages(ch, q, k) { }); } -suite('connect', () => { - test('at all', (done) => { +describe('connect', () => { + it('at all', (done) => { connect(doneCallback(done)); }); }); -suite('updateSecret', () => { - test('updateSecret', (done) => { +describe('updateSecret', () => { + it('updateSecret', (done) => { connect(kCallback((c) => { c.updateSecret(Buffer.from('new secret'), 'no reason', doneCallback(done)); })); @@ -83,7 +83,7 @@ const channel_test_fn = (method) => { chfun = options; options = {}; } - test(name, (done) => { + it(name, (done) => { connect(kCallback((c) => { c[method](options, kCallback((ch) => { chfun(ch, done); @@ -95,7 +95,7 @@ const channel_test_fn = (method) => { const channel_test = channel_test_fn('createChannel'); const confirm_channel_test = channel_test_fn('createConfirmChannel'); -suite('channel open', () => { +describe('channel open', () => { channel_test('at all', (_ch, done) => { done(); }); @@ -105,7 +105,7 @@ suite('channel open', () => { }); }); -suite('assert, check, delete', () => { +describe('assert, check, delete', () => { channel_test('assert, check, delete queue', (ch, done) => { ch.assertQueue( 'test.cb.queue', @@ -139,7 +139,7 @@ suite('assert, check, delete', () => { }); }); -suite('bindings', () => { +describe('bindings', () => { channel_test('bind queue', (ch, done) => { ch.assertQueue('test.cb.bindq', {}, kCallback((q) => { ch.assertExchange('test.cb.bindex', 'fanout', {}, kCallback((ex) => { @@ -157,7 +157,7 @@ suite('bindings', () => { }); }); -suite('sending messages', () => { +describe('sending messages', () => { channel_test('send to queue and consume noAck', (ch, done) => { const msg = randomString(); ch.assertQueue('', { exclusive: true }, (e, q) => { @@ -230,7 +230,7 @@ suite('sending messages', () => { }); }); -suite('ConfirmChannel', () => { +describe('ConfirmChannel', () => { confirm_channel_test('Receive confirmation', (ch, done) => { // An unroutable message, on the basis that you're not allowed a // queue with an empty name, and you can't make bindings to the @@ -274,33 +274,19 @@ suite('ConfirmChannel', () => { }); }); -suite('Error handling', () => { - /* - I don't like having to do this, but there appears to be something - broken about domains in Node.JS v0.8 and mocha. Apparently it has to - do with how mocha and domains hook into error propogation: - https://github.com/visionmedia/mocha/issues/513 (summary: domains in - Node.JS v0.8 don't prevent uncaughtException from firing, and that's - what mocha uses to detect .. an uncaught exception). - - Using domains with amqplib *does* work in practice in Node.JS v0.8: - that is, it's possible to throw an exception in a callback and deal - with it in the active domain, and thereby avoid it crashing the - program. - */ - if (util.versionGreaterThan(process.versions.node, '0.8')) { - test('Throw error in connection open callback', (done) => { - const dom = domain.createDomain(); - dom.on('error', failCallback(done)); - connect(dom.bind((_err, _conn) => { - throw new Error('Spurious connection open callback error'); - })); - }); - } +describe('Error handling', () => { + + it('Throw error in connection open callback', (done) => { + const dom = domain.createDomain(); + dom.on('error', failCallback(done)); + connect(dom.bind((_err, _conn) => { + throw new Error('Spurious connection open callback error'); + })); + }); // TODO: refactor {error_test, channel_test} function error_test(name, fun) { - test(name, (done) => { + it(name, (done) => { const dom = domain.createDomain(); dom.run(() => { connect(kCallback((c) => { diff --git a/test/channel.js b/test/channel.js index ee353e8b..9f15185d 100644 --- a/test/channel.js +++ b/test/channel.js @@ -77,8 +77,8 @@ function open(ch) { })(); } -suite('channel open and close', () => { - test('open', channelTest( +describe('channel open and close', () => { + it('open', channelTest( (ch, done) => { open(ch).then(succeed(done), fail(done)); }, @@ -87,18 +87,18 @@ suite('channel open and close', () => { } )); - test('bad server', baseChannelTest((c, done) => { - const ch = new Channel(c); - open(ch).then(fail(done), succeed(done)); - }, (send, wait, done) => - wait(defs.ChannelOpen)() - .then((open) => { - send(defs.ChannelCloseOk, {}, open.channel); - }) - .then(succeed(done), fail(done))) + it('bad server', baseChannelTest((c, done) => { + const ch = new Channel(c); + open(ch).then(fail(done), succeed(done)); + }, (send, wait, done) => + wait(defs.ChannelOpen)() + .then((open) => { + send(defs.ChannelCloseOk, {}, open.channel); + }) + .then(succeed(done), fail(done))) ); - test('open, close', channelTest((ch, done) => { + it('open, close', channelTest((ch, done) => { open(ch) .then(() => new Promise((resolve) => { ch.closeBecause('Bye', defs.constants.REPLY_SUCCESS, resolve); @@ -112,7 +112,7 @@ suite('channel open and close', () => { .then(succeed(done), fail(done))) ); - test('server close', channelTest((ch, done) => { + it('server close', channelTest((ch, done) => { ch.on('error', (error) => { assert.strictEqual(504, error.code); assert.strictEqual(0, error.classId); @@ -130,7 +130,7 @@ suite('channel open and close', () => { wait(defs.ChannelCloseOk)().then(succeed(done), fail(done)); })); - test('overlapping channel/server close', channelTest( + it('overlapping channel/server close', channelTest( (ch, done, conn) => { const both = latch(2, done); conn.on('error', succeed(both)); @@ -152,7 +152,7 @@ suite('channel open and close', () => { .then(succeed(done), fail(done)); })); - test('double close', channelTest((ch, done) => { + it('double close', channelTest((ch, done) => { open(ch) .then(() => { ch.closeBecause('First close', defs.constants.REPLY_SUCCESS); @@ -170,8 +170,8 @@ suite('channel open and close', () => { })); }); -suite('channel machinery', () => { - test('RPC', channelTest((ch, done) => { +describe('channel machinery', () => { + it('RPC', channelTest((ch, done) => { const rpcLatch = latch(3, done); open(ch) .then(() => { @@ -205,7 +205,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)); })); - test('Bad RPC', channelTest( + it('Bad RPC', channelTest( (ch, done) => { // We want to see the RPC rejected and the channel closed (with an // error) @@ -236,7 +236,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)), )); - test('RPC on closed channel', channelTest( + it('RPC on closed channel', channelTest( (ch, done) => { open(ch); @@ -282,7 +282,7 @@ suite('channel machinery', () => { }, )); - test('publish all < single chunk threshold', channelTest( + it('publish all < single chunk threshold', channelTest( (ch, done) => { open(ch) .then(() => { @@ -307,37 +307,34 @@ suite('channel machinery', () => { }, )); - test( - 'publish content > single chunk threshold', - channelTest( - (ch, done) => { - open(ch); - completes(() => { - ch.sendMessage( - { - exchange: 'foo', - routingKey: 'bar', - mandatory: false, - immediate: false, - ticket: 0, - }, - {}, - Buffer.alloc(3000), - ); - }, done); - }, (_send, wait, done, _ch) => { - wait(defs.BasicPublish)() - .then(wait(defs.BasicProperties)) - .then(wait(undefined)) // content frame - .then((f) => { - assert.equal(3000, f.content.length); - }) - .then(succeed(done), fail(done)); - } - ) - ); + it('publish content > single chunk threshold', channelTest( + (ch, done) => { + open(ch); + completes(() => { + ch.sendMessage( + { + exchange: 'foo', + routingKey: 'bar', + mandatory: false, + immediate: false, + ticket: 0, + }, + {}, + Buffer.alloc(3000), + ); + }, done); + }, (_send, wait, done, _ch) => { + wait(defs.BasicPublish)() + .then(wait(defs.BasicProperties)) + .then(wait(undefined)) // content frame + .then((f) => { + assert.equal(3000, f.content.length); + }) + .then(succeed(done), fail(done)); + } + )); - test('publish method & headers > threshold', channelTest( + it('publish method & headers > threshold', channelTest( (ch, done) => { open(ch); completes(() => { @@ -362,7 +359,7 @@ suite('channel machinery', () => { } )); - test('publish zero-length message', channelTest((ch, done) => { + it('publish zero-length message', channelTest((ch, done) => { open(ch); completes(() => { ch.sendMessage({ @@ -388,7 +385,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)); })); - test('delivery', channelTest((ch, done) => { + it('delivery', channelTest((ch, done) => { open(ch); ch.on('delivery', (m) => { completes(() => { @@ -401,26 +398,23 @@ suite('channel machinery', () => { }, done); })); - test( - 'zero byte msg', - channelTest( - (ch, done) => { - open(ch); - ch.on('delivery', (m) => { - completes(() => { - assert.deepEqual(Buffer.alloc(0), m.content); - }, done); - }); - }, - (send, _wait, done, ch) => { + it('zero byte msg', channelTest( + (ch, done) => { + open(ch); + ch.on('delivery', (m) => { completes(() => { - send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('')); + assert.deepEqual(Buffer.alloc(0), m.content); }, done); - }, - ), - ); + }); + }, + (send, _wait, done, ch) => { + completes(() => { + send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('')); + }, done); + } + )); - test('bad delivery', channelTest((ch, done) => { + it('bad delivery', channelTest((ch, done) => { const errorAndClose = latch(2, done); ch.on('error', (error) => { assert.strictEqual(505, error.code); @@ -441,7 +435,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)); })); - test('bad content send', channelTest((ch, done) => { + it('bad content send', channelTest((ch, done) => { completes(() => { open(ch); assert.throws(() => { @@ -452,7 +446,7 @@ suite('channel machinery', () => { done(); })); - test('bad properties send', channelTest( + it('bad properties send', channelTest( (ch, done) => { completes(() => { open(ch); @@ -467,7 +461,7 @@ suite('channel machinery', () => { ), ); - test('bad consumer', channelTest((ch, done) => { + it('bad consumer', channelTest((ch, done) => { const errorAndClose = latch(2, done); ch.on('delivery', () => { throw new Error('I am a bad consumer'); @@ -489,7 +483,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)); })); - test('bad send in consumer', channelTest((ch, done) => { + it('bad send in consumer', channelTest((ch, done) => { const errorAndClose = latch(2, done); ch.on('close', succeed(errorAndClose)); ch.on('error', (error) => { @@ -515,7 +509,7 @@ suite('channel machinery', () => { .then(succeed(done), fail(done)); })); - test('return', channelTest((ch, done) => { + it('return', channelTest((ch, done) => { ch.on('return', (m) => { completes(() => { assert.equal('barfoo', m.content.toString()); @@ -528,7 +522,7 @@ suite('channel machinery', () => { }, done); })); - test('cancel', channelTest((ch, done) => { + it('cancel', channelTest((ch, done) => { ch.on('cancel', (f) => { completes(() => { assert.equal('product of society', f.consumerTag); @@ -545,7 +539,7 @@ suite('channel machinery', () => { })); function confirmTest(variety, Method) { - return test(`confirm ${variety}`, channelTest((ch, done) => { + return it(`confirm ${variety}`, channelTest((ch, done) => { ch.on(variety, (f) => { completes(() => { assert.equal(1, f.deliveryTag); @@ -565,7 +559,7 @@ suite('channel machinery', () => { confirmTest('ack', defs.BasicAck); confirmTest('nack', defs.BasicNack); - test('out-of-order acks', channelTest((ch, done) => { + it('out-of-order acks', channelTest((ch, done) => { const allConfirms = latch(3, () => { completes(() => { assert.equal(0, ch.unconfirmed.length); @@ -584,7 +578,7 @@ suite('channel machinery', () => { }, done); })); - test('not all out-of-order acks', channelTest((ch, done) => { + it('not all out-of-order acks', channelTest((ch, done) => { const allConfirms = latch(2, () => { completes(() => { assert.equal(1, ch.unconfirmed.length); diff --git a/test/channel_api.js b/test/channel_api.js index 2746fb70..eea8867b 100644 --- a/test/channel_api.js +++ b/test/channel_api.js @@ -34,7 +34,7 @@ function logErrors(c) { // channel, and returns a promise that is resolved on test success or // rejected on test failure. function channel_test(chmethod, name, chfun) { - test(name, (done) => { + it(name, (done) => { connect(URL) .then(logErrors) .then((c) => { @@ -52,8 +52,8 @@ function channel_test(chmethod, name, chfun) { const chtest = channel_test.bind(null, 'createChannel'); -suite('connect', () => { - test('at all', (done) => { +describe('connect', () => { + it('at all', (done) => { connect(URL) .then((c) => c.close()) .then(succeed(done), fail(done)); @@ -62,8 +62,8 @@ suite('connect', () => { chtest('create channel', ignore); // i.e., just don't bork }); -suite('updateSecret', () => { - test('updateSecret', (done) => { +describe('updateSecret', () => { + it('updateSecret', (done) => { connect().then((c) => { c.updateSecret(Buffer.from('new secret'), 'no reason') .then(succeed(done), fail(done)) @@ -77,7 +77,7 @@ suite('updateSecret', () => { const QUEUE_OPTS = { durable: false }; const EX_OPTS = { durable: false }; -suite('assert, check, delete', () => { +describe('assert, check, delete', () => { chtest('assert and check queue', (ch) => ch.assertQueue('test.check-queue', QUEUE_OPTS).then((_qok) => ch.checkQueue('test.check-queue')), ); @@ -154,7 +154,7 @@ function waitForMessages(q, num) { return waitForQueue(q, (qok) => qok.messageCount >= min); } -suite('sendMessage', () => { +describe('sendMessage', () => { // publish different size messages chtest('send to queue and get from queue', (ch) => { const q = 'test.send-to-q'; @@ -187,7 +187,7 @@ suite('sendMessage', () => { }); }); -suite('binding, consuming', () => { +describe('binding, consuming', () => { // bind, publish, get chtest('route message', (ch) => { const ex = 'test.route-message'; @@ -498,7 +498,7 @@ suite('binding, consuming', () => { const confirmtest = channel_test.bind(null, 'createConfirmChannel'); -suite('confirms', () => { +describe('confirms', () => { confirmtest('message is confirmed', (ch) => { const q = 'test.confirm-message'; return Promise.all([ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)]).then(() => ch.sendToQueue(q, Buffer.from('bleep'))); diff --git a/test/codec.js b/test/codec.js index 48bf45ec..0dd5d82e 100644 --- a/test/codec.js +++ b/test/codec.js @@ -81,12 +81,12 @@ function bufferToArray(b) { return Array.prototype.slice.call(b); } -suite('Implicit encodings', () => { +describe('Implicit encodings', () => { testCases.forEach((tc) => { const name = tc[0]; const val = tc[1]; const expect = tc[2]; - test(name, () => { + it(name, () => { const buffer = Buffer.alloc(1000); const size = codec.encodeTable(buffer, val, 0); const result = buffer.subarray(4, size); @@ -115,7 +115,7 @@ function roundtrips(T) { return forAll(T).satisfy((v) => roundtrip_table({ value: v })); } -suite('Roundtrip values', () => { +describe('Roundtrip values', () => { [ amqp.Octet, amqp.ShortStr, @@ -137,7 +137,7 @@ suite('Roundtrip values', () => { amqp.FieldArray, amqp.FieldTable, ].forEach((T) => { - test(`${T.toString()} roundtrip`, roundtrips(T).asTest()); + it(`${T.toString()} roundtrip`, roundtrips(T).asTest()); }); }); @@ -240,14 +240,14 @@ function roundtripProperties(Properties) { }); } -suite('Roundtrip methods', () => { +describe('Roundtrip methods', () => { amqp.methods.forEach((Method) => { - test(`${Method.toString()} roundtrip`, roundtripMethod(Method).asTest()); + it(`${Method.toString()} roundtrip`, roundtripMethod(Method).asTest()); }); }); -suite('Roundtrip properties', () => { +describe('Roundtrip properties', () => { amqp.properties.forEach((Properties) => { - test(`${Properties.toString()} roundtrip`, roundtripProperties(Properties).asTest()); + it(`${Properties.toString()} roundtrip`, roundtripProperties(Properties).asTest()); }); }); diff --git a/test/connect.js b/test/connect.js index 0a5ac677..6ece8642 100644 --- a/test/connect.js +++ b/test/connect.js @@ -15,7 +15,7 @@ const URL = process.env.URL || 'amqp://localhost'; const urlparse = require('url-parse'); -suite('Credentials', () => { +describe('Credentials', () => { function checkCreds(creds, user, pass, done) { if (creds.mechanism !== 'PLAIN') { return done('expected mechanism PLAIN'); @@ -26,50 +26,50 @@ suite('Credentials', () => { done(); } - test('no creds', (done) => { + it('no creds', (done) => { const parts = urlparse('amqp://localhost'); const creds = credentialsFromUrl(parts); checkCreds(creds, 'guest', 'guest', done); }); - test('usual user:pass', (done) => { + it('usual user:pass', (done) => { const parts = urlparse('amqp://user:pass@localhost'); const creds = credentialsFromUrl(parts); checkCreds(creds, 'user', 'pass', done); }); - test('missing user', (done) => { + it('missing user', (done) => { const parts = urlparse('amqps://:password@localhost'); const creds = credentialsFromUrl(parts); checkCreds(creds, '', 'password', done); }); - test('missing password', (done) => { + it('missing password', (done) => { const parts = urlparse('amqps://username:@localhost'); const creds = credentialsFromUrl(parts); checkCreds(creds, 'username', '', done); }); - test('escaped colons', (done) => { + it('escaped colons', (done) => { const parts = urlparse('amqp://user%3Aname:pass%3Aword@localhost'); const creds = credentialsFromUrl(parts); checkCreds(creds, 'user:name', 'pass:word', done); }); }); -suite('Connect API', () => { - test('Connection refused', (done) => { +describe('Connect API', () => { + it('Connection refused', (done) => { connect('amqp://localhost:23450', {}, kCallback(fail(done), succeed(done))); }); // %% this ought to fail the promise, rather than throwing an error - test('bad URL', () => { + it('bad URL', () => { assert.throws(() => { connect('blurble'); }); }); - test('wrongly typed open option', (done) => { + it('wrongly typed open option', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); const q = parts.query || {}; @@ -79,7 +79,7 @@ suite('Connect API', () => { connect(u, {}, kCallback(fail(done), succeed(done))); }); - test('serverProperties', (done) => { + it('serverProperties', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); const config = parts.query || {}; @@ -92,7 +92,7 @@ suite('Connect API', () => { }); }); - test('using custom heartbeat option', (done) => { + it('using custom heartbeat option', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); const config = parts.query || {}; @@ -100,7 +100,7 @@ suite('Connect API', () => { connect(config, {}, kCallback(succeedIfAttributeEquals('heartbeat', 20, done), fail(done))); }); - test('wrongly typed heartbeat option', (done) => { + it('wrongly typed heartbeat option', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); const config = parts.query || {}; @@ -108,7 +108,7 @@ suite('Connect API', () => { connect(config, {}, kCallback(fail(done), succeed(done))); }); - test('using plain credentials', (done) => { + it('using plain credentials', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); let u = 'guest'; @@ -121,7 +121,7 @@ suite('Connect API', () => { connect(URL, { credentials: require('../lib/credentials').plain(u, p) }, kCallback(succeed(done), fail(done))); }); - test('using amqplain credentials', (done) => { + it('using amqplain credentials', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); let u = 'guest'; @@ -134,7 +134,7 @@ suite('Connect API', () => { connect(URL, { credentials: require('../lib/credentials').amqplain(u, p) }, kCallback(succeed(done), fail(done))); }); - test('ipv6', (done) => { + it('ipv6', (done) => { connect('amqp://[::1]', {}, (err, _connection) => { if (err) { return done(err); @@ -143,7 +143,7 @@ suite('Connect API', () => { }); }); - test('using unsupported mechanism', (done) => { + it('using unsupported mechanism', (done) => { const creds = { mechanism: 'UNSUPPORTED', response: () => Buffer.from(''), @@ -151,7 +151,7 @@ suite('Connect API', () => { connect(URL, { credentials: creds }, kCallback(fail(done), succeed(done))); }); - test('with a given connection timeout', (done) => { + it('with a given connection timeout', (done) => { const timeoutServer = net.createServer(() => {}).listen(31991); connect('amqp://localhost:31991', { timeout: 50 }, (_err, val) => { @@ -162,15 +162,15 @@ suite('Connect API', () => { }); }); -suite('Errors on connect', () => { +describe('Errors on connect', () => { let server; - teardown(() => { + afterEach(() => { if (server) { server.close(); } }); - test('closes underlying connection on authentication error', (done) => { + it('closes underlying connection on authentication error', (done) => { const bothDone = latch(2, done); server = net .createServer((socket) => { diff --git a/test/connection.js b/test/connection.js index a36e0489..774e7532 100644 --- a/test/connection.js +++ b/test/connection.js @@ -70,8 +70,8 @@ function connectionTest(client, server) { }; } -suite('Connection errors', () => { - test('socket close during open', (done) => { +describe('Connection errors', () => { + it('socket close during open', (done) => { // RabbitMQ itself will take at least 3 seconds to close the socket // in the event of a handshake problem. Instead of using a live // connection, I'm just going to pretend. @@ -83,7 +83,7 @@ suite('Connection errors', () => { conn.open({}, kCallback(fail(done), succeed(done))); }); - test('bad frame during open', (done) => { + it('bad frame during open', (done) => { const ss = util.socketPair(); const conn = new (require('../lib/connection').Connection)(ss.client); ss.server.on('readable', () => { @@ -93,14 +93,14 @@ suite('Connection errors', () => { }); }); -suite('Connection open', () => { - test('happy', connectionTest((c, done) => { +describe('Connection open', () => { + it('happy', connectionTest((c, done) => { c.open(OPEN_OPTS, kCallback(succeed(done), fail(done))); }, (send, wait, done) => { happy_open(send, wait).then(succeed(done), fail(done)); })); - test('wrong first frame', connectionTest((c, done) => { + it('wrong first frame', connectionTest((c, done) => { c.open(OPEN_OPTS, kCallback(fail(done), succeed(done))); }, (send, _wait, done) => { // bad server! bad! whatever were you thinking? @@ -109,7 +109,7 @@ suite('Connection open', () => { }, done); })); - test('unexpected socket close', connectionTest((c, done) => { + it('unexpected socket close', connectionTest((c, done) => { c.open(OPEN_OPTS, kCallback(fail(done), succeed(done))); }, (send, wait, done, socket) => { send(defs.ConnectionStart, { @@ -127,8 +127,8 @@ suite('Connection open', () => { })); }); -suite('Connection running', () => { - test('wrong frame on channel 0', connectionTest((c, done) => { +describe('Connection running', () => { + it('wrong frame on channel 0', connectionTest((c, done) => { c.on('error', succeed(done)); c.open(OPEN_OPTS); }, (send, wait, done) => { @@ -146,7 +146,7 @@ suite('Connection running', () => { .then(succeed(done), fail(done)); })); - test('unopened channel', connectionTest((c, done) => { + it('unopened channel', connectionTest((c, done) => { c.on('error', succeed(done)); c.open(OPEN_OPTS); }, (send, wait, done) => { @@ -164,7 +164,7 @@ suite('Connection running', () => { .then(succeed(done), fail(done)); })); - test('unexpected socket close', connectionTest((c, done) => { + it('unexpected socket close', connectionTest((c, done) => { const errorAndClosed = latch(2, done); c.on('error', succeed(errorAndClosed)); c.on('close', succeed(errorAndClosed)); @@ -180,7 +180,7 @@ suite('Connection running', () => { .then(succeed(done)); })); - test('connection.blocked', connectionTest((c, done) => { + it('connection.blocked', connectionTest((c, done) => { c.on('blocked', succeed(done)); c.open(OPEN_OPTS); }, (send, wait, done, _socket) => { @@ -191,7 +191,7 @@ suite('Connection running', () => { .then(succeed(done)); })); - test('connection.unblocked', connectionTest((c, done) => { + it('connection.unblocked', connectionTest((c, done) => { c.on('unblocked', succeed(done)); c.open(OPEN_OPTS); }, (send, wait, done, _socket) => { @@ -203,8 +203,8 @@ suite('Connection running', () => { })); }); -suite('Connection close', () => { - test('happy', connectionTest((c, done0) => { +describe('Connection close', () => { + it('happy', connectionTest((c, done0) => { const done = latch(2, done0); c.on('close', done); c.open(OPEN_OPTS, kCallback((_ok) => { @@ -219,7 +219,7 @@ suite('Connection close', () => { .then(succeed(done), fail(done)); })); - test('interleaved close frames', connectionTest((c, done0) => { + it('interleaved close frames', connectionTest((c, done0) => { const done = latch(2, done0); c.on('close', done); c.open(OPEN_OPTS, kCallback((_ok) => { @@ -243,7 +243,7 @@ suite('Connection close', () => { .then(succeed(done), fail(done)); })); - test('server error close', connectionTest((c, done0) => { + it('server error close', connectionTest((c, done0) => { const done = latch(2, done0); c.on('close', succeed(done)); c.on('error', succeed(done)); @@ -262,7 +262,7 @@ suite('Connection close', () => { .then(succeed(done), fail(done)); })); - test('operator-intiated close', connectionTest((c, done) => { + it('operator-intiated close', connectionTest((c, done) => { c.on('close', succeed(done)); c.on('error', fail(done)); c.open(OPEN_OPTS); @@ -280,7 +280,7 @@ suite('Connection close', () => { .then(succeed(done), fail(done)); })); - test('double close', connectionTest((c, done) => { + it('double close', connectionTest((c, done) => { c.open(OPEN_OPTS, kCallback(() => { c.close(); // NB no synchronisation, we do this straight away @@ -299,18 +299,18 @@ suite('Connection close', () => { })); }); -suite('heartbeats', () => { +describe('heartbeats', () => { const heartbeat = require('../lib/heartbeat'); - setup(() => { + beforeEach(() => { heartbeat.UNITS_TO_MS = 20; }); - teardown(() => { + afterEach(() => { heartbeat.UNITS_TO_MS = 1000; }); - test('send heartbeat after open', connectionTest((c, done) => { + it('send heartbeat after open', connectionTest((c, done) => { completes(() => { const opts = Object.create(OPEN_OPTS); opts.heartbeat = 1; @@ -335,7 +335,7 @@ suite('heartbeats', () => { }); })); - test('detect lack of heartbeats', connectionTest((c, done) => { + it('detect lack of heartbeats', connectionTest((c, done) => { const opts = Object.create(OPEN_OPTS); opts.heartbeat = 1; c.on('error', succeed(done)); diff --git a/test/data.js b/test/data.js index fd9df0bd..1f6cc05c 100644 --- a/test/data.js +++ b/test/data.js @@ -200,9 +200,9 @@ const domainProps = [ [FieldArray, (a) => Array.isArray(a)], ]; -suite('Domains', () => { +describe('Domains', () => { domainProps.forEach((p) => { - test(`${p[0]} domain`, forAll(p[0]).satisfy(p[1]).asTest({ times: 500 })); + it(`${p[0]} domain`, forAll(p[0]).satisfy(p[1]).asTest({ times: 500 })); }); }); diff --git a/test/frame.js b/test/frame.js index cc555779..d988a47b 100644 --- a/test/frame.js +++ b/test/frame.js @@ -26,8 +26,8 @@ const HB = Buffer.from([ defs.constants.FRAME_END, ]); -suite('Explicit parsing', () => { - test('Parse heartbeat', () => { +describe('Explicit parsing', () => { + it('Parse heartbeat', () => { const input = inputs(); const frames = new Frames(input); input.write(HB); @@ -35,7 +35,7 @@ suite('Explicit parsing', () => { assert(!frames.recvFrame()); }); - test('Parse partitioned', () => { + it('Parse partitioned', () => { const input = inputs(); const frames = new Frames(input); input.write(HB.subarray(0, 3)); @@ -46,7 +46,7 @@ suite('Explicit parsing', () => { }); function testBogusFrame(name, bytes) { - test(name, (done) => { + it(name, (done) => { const input = inputs(); const frames = new Frames(input); frames.frameMax = 5; //for the max frame test @@ -102,7 +102,7 @@ const assertEqualModuloDefaults = require('./codec').assertEqualModuloDefaults; const Trace = label('frame trace', repeat(choice.apply(choice, amqp.methods))); -suite('Parsing', () => { +describe('Parsing', () => { function testPartitioning(partition) { return forAll(Trace) .satisfy((t) => { @@ -138,11 +138,11 @@ suite('Parsing', () => { .asTest({ times: 20 }); } - test('Parse trace of methods', testPartitioning((bufs) => bufs)); + it('Parse trace of methods', testPartitioning((bufs) => bufs)); - test("Parse concat'd methods", testPartitioning((bufs) => [Buffer.concat(bufs)])); + it("Parse concat'd methods", testPartitioning((bufs) => [Buffer.concat(bufs)])); - test('Parse partitioned methods', testPartitioning((bufs) => { + it('Parse partitioned methods', testPartitioning((bufs) => { const full = Buffer.concat(bufs); const onethird = Math.floor(full.length / 3); const twothirds = 2 * onethird; @@ -166,8 +166,8 @@ const Content = transform( sequence(amqp.methods['BasicDeliver'], amqp.properties['BasicProperties'], Body), ); -suite('Content framing', () => { - test('Adhere to frame max', forAll(Content, FrameMax) +describe('Content framing', () => { + it('Adhere to frame max', forAll(Content, FrameMax) .satisfy((content, max) => { const input = inputs(); const frames = new Frames(input); diff --git a/test/mux.js b/test/mux.js index fefe7a32..f154bc4d 100644 --- a/test/mux.js +++ b/test/mux.js @@ -28,7 +28,7 @@ function readAllObjects(s, cb) { read(); } -test('single input', (done) => { +it('single input', (done) => { const input = stream(); const output = stream(); input.on('end', () => { @@ -54,7 +54,7 @@ test('single input', (done) => { input.end(); }); -test('single input, resuming stream', (done) => { +it('single input, resuming stream', (done) => { const input = stream(); const output = stream(); input.on('end', () => { @@ -92,7 +92,7 @@ test('single input, resuming stream', (done) => { input.end(); }); -test('two sequential inputs', (done) => { +it('two sequential inputs', (done) => { const input1 = stream(); const input2 = stream(); const output = stream(); @@ -122,7 +122,7 @@ test('two sequential inputs', (done) => { }); }); -test('two interleaved inputs', (done) => { +it('two interleaved inputs', (done) => { const input1 = stream(); const input2 = stream(); const output = stream(); @@ -153,7 +153,7 @@ test('two interleaved inputs', (done) => { }); }); -test('unpipe', (done) => { +it('unpipe', (done) => { const input = stream(); const output = stream(); const mux = new Mux(output); @@ -201,7 +201,7 @@ test('unpipe', (done) => { }); }); -test('roundrobin', (done) => { +it('roundrobin', (done) => { const input1 = stream(); const input2 = stream(); const output = stream(); diff --git a/test/util.js b/test/util.js index 7cd9298e..57c70a6b 100644 --- a/test/util.js +++ b/test/util.js @@ -173,23 +173,21 @@ function versionGreaterThan(actual, spec) { return false; } -suite('versionGreaterThan', () => { - test('full spec', () => { +describe('versionGreaterThan', () => { + it('full spec', () => { assert(versionGreaterThan('0.8.26', '0.6.12')); assert(versionGreaterThan('0.8.26', '0.8.21')); }); - test('partial spec', () => { + it('partial spec', () => { assert(versionGreaterThan('0.9.12', '0.8')); }); - test('not greater', () => { + it('not greater', () => { assert(!versionGreaterThan('0.8.12', '0.8.26')); assert(!versionGreaterThan('0.6.2', '0.6.12')); assert(!versionGreaterThan('0.8.29', '0.8')); }); - - test; }); module.exports = {