Skip to content

Commit

Permalink
Merge c9994cb into efdf206
Browse files Browse the repository at this point in the history
  • Loading branch information
timarandras committed Dec 29, 2017
2 parents efdf206 + c9994cb commit 18371d2
Show file tree
Hide file tree
Showing 10 changed files with 6,934 additions and 25 deletions.
12 changes: 7 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"presets": [ "node6" ],
"plugins": [
"babel-plugin-transform-async-to-generator",
"babel-plugin-transform-object-rest-spread"
],
"presets": [
["@babel/preset-env", {
"targets": {
"node": "current"
}
}]
],
"env": {
"test": {
"plugins": [ "istanbul" ]
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ src/
.babelrc
.eslintignore
.eslintrc.yml
.vscode
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"-r",
"${workspaceFolder}/test/helpers/",
"${workspaceFolder}/src"
],
"internalConsoleOptions": "openOnSessionStart"
}
]
}
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,64 @@ const server = proxyquire( "./app", { amqplib } );
server.listen();
```

## Example
### app.js
```javascript
'use strict';

const Amqp = require('amqplib');

const url = 'amqp://localhost';
const ex = 'exchange';
const binding_key = '#';

const service = async() => {
const amqpConn = await Amqp.connect(url);
const amqpChannel = await amqpConn.createChannel();

await amqpChannel.assertExchange(ex, 'topic');

const { queue } = await amqpChannel.assertQueue('', { exclusive: true });
await amqpChannel.bindQueue(queue, ex, binding_key);

amqpChannel.publish(ex, binding_key, Buffer.from('hello amqp'));
amqpChannel.publish(ex, binding_key, Buffer.from('qwerty'));
amqpChannel.publish(ex, binding_key, Buffer.from('asdf'));
};

module.exports = service;
```

### app.spec.js
```javascript
/* eslint-env node, mocha */
"use strict";
const chai = require('chai');
const expect = chai.expect;

const amqplib = require( "amqplib-mocks" );
const proxyquire = require( "proxyquire" );

const service = proxyquire( "./app", { amqplib } );

const url = 'amqp://localhost';

describe('amqp mock', function () {

it('receives message', async () => {
await service();
const amqpConn = amqplib.getConnection(url);

const published = amqpConn.getPublished( { bodyTransform: buf => buf.toString() });

expect( published[0].body ).to.equal('hello amqp');
expect( published[1].body ).to.equal('qwerty');
expect( published[2].body ).to.equal('asdf');
});

});
```

[npm-image]: https://badge.fury.io/js/amqplib-mocks.svg
[npm-url]: https://npmjs.org/package/amqplib-mocks
[ci-image]: https://travis-ci.org/Bunk/amqplib-mocks.svg?branch=master
Expand Down

0 comments on commit 18371d2

Please sign in to comment.