@onify/fake-amqplib 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +10 -10
  2. package/index.d.ts +8 -12
  3. package/index.js +309 -117
  4. package/main.cjs +309 -117
  5. package/package.json +9 -7
package/README.md CHANGED
@@ -14,9 +14,10 @@ Mocked version of https://www.npmjs.com/package/amqplib.
14
14
 
15
15
  ## RabbitMQ versions
16
16
 
17
- Some behaviour differs between versions. To specify your version of RabbitMQ you can call `setVersion(minorVersionFloatOrString)`. Default version is 3.5.
17
+ RabbitMQ behaviour differs between versions. To specify your version of RabbitMQ you can call `setVersion(minorVersionFloatOrString)`. Default version is 3.5.
18
18
 
19
19
  Example:
20
+
20
21
  ```js
21
22
  var fakeAmqp = require('@onify/fake-amqplib');
22
23
 
@@ -26,16 +27,16 @@ var fakeAmqp = require('@onify/fake-amqplib');
26
27
  const conn2 = await fakeAmqp.connect('amqp://rabbit2-2');
27
28
 
28
29
  fakeAmqp.setVersion('3.2');
29
- const conn3 = await fakeAmqp.connect('amqp://rabbit3-1');
30
+ const conn3 = await fakeAmqp.connect('amqp://rabbit3-2');
30
31
 
31
32
  fakeAmqp.setVersion('3.7');
32
33
  const conn37 = await fakeAmqp.connect('amqp://rabbit3-7');
33
- })()
34
+ })();
34
35
  ```
35
36
 
36
37
  ## Mocking amqplib
37
38
 
38
- You might want to override `amqplib` with `@onify/fake-amqplib` in tests. This can be done this way:
39
+ You might want to override `amqplib` with `@onify/fake-amqplib` in tests. This can be done in a number of ways.
39
40
 
40
41
  ### CommonJS
41
42
 
@@ -72,9 +73,10 @@ Example on how to mock amqplib import when working with modules.
72
73
 
73
74
  **[Quibble](https://www.npmjs.com/package/quibble) mocha example**
74
75
 
75
- Both amqplib and fake-amqplib have to be mocked if reset mock is used during testing.
76
+ Both amqplib and fake-amqplib have to be quibbled if reset mock is used during testing.
76
77
 
77
78
  _test/setup.js_
79
+
78
80
  ```js
79
81
  import * as fakeAmqpLib from '@onify/fake-amqplib';
80
82
  import { connect as fakeConnect } from '@onify/fake-amqplib';
@@ -88,19 +90,17 @@ import quibble from 'quibble';
88
90
  ```
89
91
 
90
92
  _.mocharc.json_ (true for node version < 20)
93
+
91
94
  ```json
92
95
  {
93
96
  "recursive": true,
94
97
  "require": ["test/setup.js"],
95
- "node-option": [
96
- "experimental-specifier-resolution=node",
97
- "no-warnings",
98
- "loader=quibble"
99
- ]
98
+ "node-option": ["experimental-specifier-resolution=node", "no-warnings", "loader=quibble"]
100
99
  }
101
100
  ```
102
101
 
103
102
  _test/amqplib-connection-test.js_
103
+
104
104
  ```js
105
105
  import assert from 'node:assert';
106
106
  import { connect } from 'amqplib';
package/index.d.ts CHANGED
@@ -1,28 +1,27 @@
1
1
  /// <reference types="amqplib" />
2
2
  /// <reference types="node" />
3
3
 
4
- import { Options, Connection, Channel, credentials } from "amqplib";
5
- import { EventEmitter } from "events";
4
+ import { Options, Connection, Channel } from 'amqplib';
6
5
  import { Broker } from 'smqp';
7
6
 
8
7
  export interface FakeAmqplibChannel extends Channel {
8
+ /** Channel name and identifier, for faking purposes */
9
9
  _channelName: string;
10
- _version: number;
11
10
  _broker: Broker;
12
- new(broker: Broker, connection: FakeAmqplibConnection): FakeAmqplibChannel;
11
+ _version: number;
12
+ new (broker: Broker, connection: FakeAmqplibConnection): FakeAmqplibChannel;
13
13
  get _closed(): boolean;
14
- get _emitter(): EventEmitter;
15
14
  }
16
15
 
17
16
  export interface FakeAmqplibConnection extends Connection {
18
17
  _channels: FakeAmqplibChannel[];
19
18
  _url: URL;
19
+ /** Connection identifier, for faking purposes */
20
20
  _id: string;
21
21
  _broker: Broker;
22
22
  _version: number;
23
- new(broker: Broker, version: number, amqpUrl: string, options?: any): FakeAmqplibConnection;
23
+ new (broker: Broker, version: number, amqpUrl: string, options?: any): FakeAmqplibConnection;
24
24
  get _closed(): boolean;
25
- get _emitter(): EventEmitter;
26
25
  }
27
26
 
28
27
  interface SocketOptions {
@@ -36,14 +35,11 @@ interface SocketOptions {
36
35
  [x: string]: any;
37
36
  }
38
37
 
39
- type connectCallback = (
40
- err: Error,
41
- connection: FakeAmqplibConnection
42
- ) => void;
38
+ type connectCallback = (err: Error, connection: FakeAmqplibConnection) => void;
43
39
 
44
40
  export class FakeAmqplib {
45
41
  connections: FakeAmqplibConnection[];
46
- constructor(version?: number)
42
+ constructor(version?: number);
47
43
  connect(url: string | Options.Connect, socketOptions?: SocketOptions): Promise<FakeAmqplibConnection>;
48
44
  connect(url: string | Options.Connect, socketOptions: SocketOptions, callback: connectCallback): void;
49
45
  connect(url: string | Options.Connect, callback: (err: Error, connection: FakeAmqplibConnection) => void): void;