Skip to content
Open
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"noGlobalIsNan": "error",
"noGlobalIsFinite": "error",
"noPrototypeBuiltins": "error",
"noVar": "error"
"noVar": "error",
"noExportsInTest": "off"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the tests have describe / it, biome recognises them as tests and complains about the exports

},
"style": {
"useSingleVarDeclarator": "error"
Expand Down
18 changes: 9 additions & 9 deletions test/bitset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@ 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);
return !b.get(bit);
})
.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;
Expand Down
54 changes: 20 additions & 34 deletions test/callback_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}));
Expand All @@ -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);
Expand All @@ -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();
});
Expand All @@ -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',
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since amqplib no longer supports v0.8 or earlier, we no longer have to worry about ignoring the test in earlier version

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) => {
Expand Down
Loading