-
Notifications
You must be signed in to change notification settings - Fork 476
Modernisation 27 - Switch to mocha bdd style in preparation for moving to node test runner #831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cressie176
wants to merge
1
commit into
amqplib-modernisation-26-format-tests
Choose a base branch
from
amqplib-modernisation-27-mocha-describe
base: amqplib-modernisation-26-format-tests
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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