{"id":18777495,"url":"https://github.com/onify/fake-amqplib","last_synced_at":"2025-07-17T17:41:43.521Z","repository":{"id":57133240,"uuid":"239981472","full_name":"onify/fake-amqplib","owner":"onify","description":"fake nodejs amqplib","archived":false,"fork":false,"pushed_at":"2024-05-08T03:27:01.000Z","size":166,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"default","last_synced_at":"2024-10-13T18:57:56.675Z","etag":null,"topics":["amqplib","fake","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-02-12T10:09:08.000Z","updated_at":"2024-05-21T21:43:23.000Z","dependencies_parsed_at":"2023-01-21T17:47:41.097Z","dependency_job_id":"ff940c6a-522a-4e46-8dcf-b29ba4d4c6f3","html_url":"https://github.com/onify/fake-amqplib","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.032258064516129004","last_synced_commit":"8b31f68f13a55abb8e1e8d4fbb0beb472a02a613"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Ffake-amqplib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Ffake-amqplib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Ffake-amqplib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Ffake-amqplib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onify","download_url":"https://codeload.github.com/onify/fake-amqplib/tar.gz/refs/heads/default","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223581918,"owners_count":17168655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqplib","fake","nodejs"],"created_at":"2024-11-07T20:11:21.115Z","updated_at":"2025-04-13T10:32:21.381Z","avatar_url":"https://github.com/onify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Onify fake-amqplib\n\n[![Built latest](https://github.com/onify/fake-amqplib/actions/workflows/build-latest.yaml/badge.svg)](https://github.com/onify/fake-amqplib/actions/workflows/build-latest.yaml)[![Coverage Status](https://coveralls.io/repos/github/onify/fake-amqplib/badge.svg?branch=default)](https://coveralls.io/github/onify/fake-amqplib?branch=default)\n\nMocked version of https://www.npmjs.com/package/amqplib.\n\n## Fake api\n\n- `async connect(amqpurl[, ...otherOptions, callback])`: wait for a fake connection or expect one in the callback\n- `connectSync(amqpurl[, ...otherOptions])`: utility method to create a connection without waiting for promise to resolve - synchronous\n- `resetMock()`: reset all connections and brokers\n- `setVersion(minor)`: next connection will be to a amqp of a specific version\n- `connections`: list of faked connections\n\n## RabbitMQ versions\n\nRabbitMQ behaviour differs between versions. To specify your version of RabbitMQ you can call `setVersion(minorVersionFloatOrString)`. Default version is 3.5.\n\nExample:\n\n```js\nvar fakeAmqp = require('@onify/fake-amqplib');\n\n// prepare your connections\n(async () =\u003e {\n  fakeAmqp.setVersion('2.2');\n  const conn2 = await fakeAmqp.connect('amqp://rabbit2-2');\n\n  fakeAmqp.setVersion('3.2');\n  const conn3 = await fakeAmqp.connect('amqp://rabbit3-2');\n\n  fakeAmqp.setVersion('3.7');\n  const conn37 = await fakeAmqp.connect('amqp://rabbit3-7');\n})();\n```\n\n## Mocking amqplib\n\nYou might want to override `amqplib` with `@onify/fake-amqplib` in tests. This can be done in a number of ways.\n\n### CommonJS\n\nExample on how to mock amqplib when working with commonjs.\n\n```js\nconst amqplib = require('amqplib');\nconst fakeAmqp = require('@onify/fake-amqplib');\n\namqplib.connect = fakeAmqp.connect;\n```\n\nor:\n\n```js\nconst mock = require('mock-require');\nconst fakeAmqp = require('@onify/fake-amqplib');\n\nmock('amqplib/callback_api', fakeAmqp);\n```\n\nor just mock the entire amqplib with:\n\n```js\nconst mock = require('mock-require');\nconst fakeAmqp = require('@onify/fake-amqplib');\n\nmock('amqplib', fakeAmqp);\n```\n\n### ESM\n\nExample on how to mock amqplib import when working with modules.\n\n**[Quibble](https://www.npmjs.com/package/quibble) mocha example**\n\nBoth amqplib and fake-amqplib have to be quibbled if reset mock is used during testing.\n\n_test/setup.js_\n\n```javascript\nimport * as fakeAmqpLib from '@onify/fake-amqplib';\nimport { connect as fakeConnect } from '@onify/fake-amqplib';\nimport quibble from 'quibble';\n\n(async () =\u003e {\n  await quibble.esm('amqplib', { connect: fakeConnect });\n  await quibble.esm('@onify/fake-amqplib', { ...fakeAmqpLib });\n})();\n```\n\n_.mocharc.json_ (true for node version \u003c 20)\n\n```json\n{\n  \"recursive\": true,\n  \"require\": [\"test/setup.js\"],\n  \"node-option\": [\"experimental-specifier-resolution=node\", \"no-warnings\", \"loader=quibble\"]\n}\n```\n\n_test/amqplib-connection-test.js_\n\n```javascript\nimport assert from 'node:assert';\nimport { connect } from 'amqplib';\nimport { connect as connectCb } from 'amqplib';\n\nimport { resetMock } from '@onify/fake-amqplib';\n\ndescribe('connection', () =\u003e {\n  afterEach(resetMock);\n\n  it('connect promise', async () =\u003e {\n    const connection = await connect('amqp://host');\n    assert.equal(connection.connection.serverProperties.version, '3.5.0');\n  });\n\n  it('connect callback', (done) =\u003e {\n    connectCb('amqp://host', (err, connection) =\u003e {\n      if (err) return done(err);\n      assert.equal(connection.connection.serverProperties.version, '3.5.0');\n      done();\n    });\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonify%2Ffake-amqplib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonify%2Ffake-amqplib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonify%2Ffake-amqplib/lists"}