@onify/fake-amqplib 3.1.0 → 3.3.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.
package/README.md CHANGED
@@ -42,7 +42,7 @@ You might want to override `amqplib` with `@onify/fake-amqplib` in tests. This c
42
42
 
43
43
  Example on how to mock amqplib when working with commonjs.
44
44
 
45
- ```javascript
45
+ ```js
46
46
  const amqplib = require('amqplib');
47
47
  const fakeAmqp = require('@onify/fake-amqplib');
48
48
 
@@ -51,7 +51,7 @@ amqplib.connect = fakeAmqp.connect;
51
51
 
52
52
  or:
53
53
 
54
- ```javascript
54
+ ```js
55
55
  const mock = require('mock-require');
56
56
  const fakeAmqp = require('@onify/fake-amqplib');
57
57
 
@@ -60,7 +60,7 @@ mock('amqplib/callback_api', fakeAmqp);
60
60
 
61
61
  or just mock the entire amqplib with:
62
62
 
63
- ```javascript
63
+ ```js
64
64
  const mock = require('mock-require');
65
65
  const fakeAmqp = require('@onify/fake-amqplib');
66
66
 
@@ -77,14 +77,13 @@ Both amqplib and fake-amqplib have to be quibbled if reset mock is used during t
77
77
 
78
78
  _test/setup.js_
79
79
 
80
- ```js
80
+ ```javascript
81
81
  import * as fakeAmqpLib from '@onify/fake-amqplib';
82
82
  import { connect as fakeConnect } from '@onify/fake-amqplib';
83
83
  import quibble from 'quibble';
84
84
 
85
85
  (async () => {
86
86
  await quibble.esm('amqplib', { connect: fakeConnect });
87
- await quibble.esm('amqplib/callback_api', { connect: fakeConnect });
88
87
  await quibble.esm('@onify/fake-amqplib', { ...fakeAmqpLib });
89
88
  })();
90
89
  ```
@@ -101,10 +100,10 @@ _.mocharc.json_ (true for node version < 20)
101
100
 
102
101
  _test/amqplib-connection-test.js_
103
102
 
104
- ```js
103
+ ```javascript
105
104
  import assert from 'node:assert';
106
105
  import { connect } from 'amqplib';
107
- import { connect as connectCb } from 'amqplib/callback_api';
106
+ import { connect as connectCb } from 'amqplib';
108
107
 
109
108
  import { resetMock } from '@onify/fake-amqplib';
110
109
 
package/index.d.ts CHANGED
@@ -1,56 +1,59 @@
1
1
  /// <reference types="amqplib" />
2
2
  /// <reference types="node" />
3
3
 
4
- import { Options, Connection, Channel } from 'amqplib';
5
- import { Broker } from 'smqp';
4
+ declare module '@onify/fake-amqplib' {
5
+ import { Options, Connection, Channel, ChannelModel } from 'amqplib';
6
+ import { Broker } from 'smqp';
6
7
 
7
- export interface FakeAmqplibChannel extends Channel {
8
- /** Channel name and identifier, for faking purposes */
9
- _channelName: string;
10
- _broker: Broker;
11
- _version: number;
12
- new (broker: Broker, connection: FakeAmqplibConnection): FakeAmqplibChannel;
13
- get _closed(): boolean;
14
- }
8
+ export interface FakeAmqplibChannel extends Channel {
9
+ /** Channel name and identifier, for faking purposes */
10
+ _channelName: string;
11
+ _broker: Broker;
12
+ _version: number;
13
+ new (broker: Broker, connection: FakeAmqplibConnection): FakeAmqplibChannel;
14
+ get _closed(): boolean;
15
+ }
15
16
 
16
- export interface FakeAmqplibConnection extends Connection {
17
- _channels: FakeAmqplibChannel[];
18
- _url: URL;
19
- /** Connection identifier, for faking purposes */
20
- _id: string;
21
- _broker: Broker;
22
- _version: number;
23
- new (broker: Broker, version: number, amqpUrl: string, options?: any): FakeAmqplibConnection;
24
- get _closed(): boolean;
25
- }
17
+ export interface FakeAmqplibConnection extends Connection, ChannelModel {
18
+ _channels: FakeAmqplibChannel[];
19
+ _url: URL;
20
+ /** Connection identifier, for faking purposes */
21
+ _id: string;
22
+ _broker: Broker;
23
+ _version: number;
24
+ new (broker: Broker, version: number, amqpUrl: string, options?: any): FakeAmqplibConnection;
25
+ get _closed(): boolean;
26
+ }
26
27
 
27
- interface SocketOptions {
28
- host?: string;
29
- keepAlive?: boolean;
30
- keepAliveDelay?: number;
31
- noDelay?: boolean;
32
- port?: number;
33
- serverName?: string;
34
- timeout?: number;
35
- [x: string]: any;
36
- }
28
+ interface SocketOptions {
29
+ host?: string;
30
+ keepAlive?: boolean;
31
+ keepAliveDelay?: number;
32
+ noDelay?: boolean;
33
+ port?: number;
34
+ serverName?: string;
35
+ timeout?: number;
36
+ [x: string]: any;
37
+ }
37
38
 
38
- type connectCallback = (err: Error, connection: FakeAmqplibConnection) => void;
39
+ type connectCallback = (err: Error, connection: FakeAmqplibConnection) => void;
39
40
 
40
- export class FakeAmqplib {
41
- connections: FakeAmqplibConnection[];
42
- constructor(version?: number);
43
- connect(url: string | Options.Connect, socketOptions?: SocketOptions): Promise<FakeAmqplibConnection>;
44
- connect(url: string | Options.Connect, socketOptions: SocketOptions, callback: connectCallback): void;
45
- connect(url: string | Options.Connect, callback: (err: Error, connection: FakeAmqplibConnection) => void): void;
46
- connectSync(url: string | Options.Connect, socketOptions?: SocketOptions): FakeAmqplibConnection;
47
- resetMock(): void;
48
- setVersion(minorVersion: number): void;
49
- }
41
+ export class FakeAmqplib {
42
+ version: number;
43
+ connections: FakeAmqplibConnection[];
44
+ constructor(version?: number);
45
+ connect(url: string | Options.Connect, socketOptions?: SocketOptions): Promise<FakeAmqplibConnection>;
46
+ connect(url: string | Options.Connect, socketOptions: SocketOptions, callback: connectCallback): void;
47
+ connect(url: string | Options.Connect, callback: (err: Error, connection: FakeAmqplibConnection) => void): void;
48
+ connectSync(url: string | Options.Connect, socketOptions?: SocketOptions): FakeAmqplibConnection;
49
+ resetMock(): void;
50
+ setVersion(minorVersion: number): void;
51
+ }
50
52
 
51
- export function connect(url: string | Options.Connect, socketOptions?: SocketOptions): Promise<FakeAmqplibConnection>;
52
- export function connect(url: string | Options.Connect, socketOptions: SocketOptions, callback: connectCallback): void;
53
- export function connect(url: string | Options.Connect, callback: connectCallback): void;
54
- export function connectSync(url: string | Options.Connect, socketOptions?: SocketOptions): FakeAmqplibConnection;
55
- export function resetMock(): void;
56
- export function setVersion(minorVersion: number): void;
53
+ export function connect(url: string | Options.Connect, socketOptions?: SocketOptions): Promise<FakeAmqplibConnection>;
54
+ export function connect(url: string | Options.Connect, socketOptions: SocketOptions, callback: connectCallback): void;
55
+ export function connect(url: string | Options.Connect, callback: connectCallback): void;
56
+ export function connectSync(url: string | Options.Connect, socketOptions?: SocketOptions): FakeAmqplibConnection;
57
+ export function resetMock(): void;
58
+ export function setVersion(minorVersion: number): void;
59
+ }
package/index.js CHANGED
@@ -40,7 +40,7 @@ class FakeAmqpNotFoundError extends FakeAmqpError {
40
40
  `Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no ${type} '${name}' in vhost '${vhost || '/'}'`,
41
41
  404,
42
42
  true,
43
- killConnection,
43
+ killConnection
44
44
  );
45
45
  }
46
46
  }
@@ -51,7 +51,7 @@ class FakeAmqpUnknownDeliveryTag extends FakeAmqpError {
51
51
  `Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - unknown delivery tag ${deliveryTag}`,
52
52
  406,
53
53
  true,
54
- false,
54
+ false
55
55
  );
56
56
  }
57
57
  get _emit() {
@@ -284,7 +284,7 @@ export class FakeAmqplibChannel extends EventEmitter {
284
284
  `Channel closed by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - queue '${queue}' in vhost '${connUrl.pathname}' in exclusive use"`,
285
285
  403,
286
286
  true,
287
- true,
287
+ true
288
288
  );
289
289
  }
290
290
 
@@ -680,7 +680,7 @@ function normalizeAmqpUrl(url) {
680
680
  pathname: vhost,
681
681
  slashes: true,
682
682
  auth,
683
- }),
683
+ })
684
684
  );
685
685
 
686
686
  for (const k in rest) {
@@ -717,7 +717,7 @@ function addConfirmCallback(broker, options, callback) {
717
717
  }
718
718
 
719
719
  function confirmCallback() {
720
- broker.off('message.*', consumerTag);
720
+ broker.off('message.*', { consumerTag });
721
721
  switch (undelivered) {
722
722
  case 'message.nack':
723
723
  return callback(new Error('message nacked'));
@@ -743,7 +743,7 @@ function allUpToDeliveryTag(q, deliveryTag, op, ...args) {
743
743
  brokerMessages.push(cmsg.content[kSmqp]);
744
744
  cmsg[op](...args);
745
745
  },
746
- { prefetch: Infinity },
746
+ { prefetch: Infinity }
747
747
  );
748
748
 
749
749
  consumer.cancel();
package/main.cjs CHANGED
@@ -42,7 +42,7 @@ class FakeAmqpNotFoundError extends FakeAmqpError {
42
42
  `Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no ${type} '${name}' in vhost '${vhost || '/'}'`,
43
43
  404,
44
44
  true,
45
- killConnection,
45
+ killConnection
46
46
  );
47
47
  }
48
48
  }
@@ -53,7 +53,7 @@ class FakeAmqpUnknownDeliveryTag extends FakeAmqpError {
53
53
  `Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - unknown delivery tag ${deliveryTag}`,
54
54
  406,
55
55
  true,
56
- false,
56
+ false
57
57
  );
58
58
  }
59
59
  get _emit() {
@@ -286,7 +286,7 @@ class FakeAmqplibChannel extends events.EventEmitter {
286
286
  `Channel closed by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - queue '${queue}' in vhost '${connUrl.pathname}' in exclusive use"`,
287
287
  403,
288
288
  true,
289
- true,
289
+ true
290
290
  );
291
291
  }
292
292
 
@@ -682,7 +682,7 @@ function normalizeAmqpUrl(url$1) {
682
682
  pathname: vhost,
683
683
  slashes: true,
684
684
  auth,
685
- }),
685
+ })
686
686
  );
687
687
 
688
688
  for (const k in rest) {
@@ -719,7 +719,7 @@ function addConfirmCallback(broker, options, callback) {
719
719
  }
720
720
 
721
721
  function confirmCallback() {
722
- broker.off('message.*', consumerTag);
722
+ broker.off('message.*', { consumerTag });
723
723
  switch (undelivered) {
724
724
  case 'message.nack':
725
725
  return callback(new Error('message nacked'));
@@ -745,7 +745,7 @@ function allUpToDeliveryTag(q, deliveryTag, op, ...args) {
745
745
  brokerMessages.push(cmsg.content[kSmqp]);
746
746
  cmsg[op](...args);
747
747
  },
748
- { prefetch: Infinity },
748
+ { prefetch: Infinity }
749
749
  );
750
750
 
751
751
  consumer.cancel();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onify/fake-amqplib",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "Fake amqplib",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,18 +33,21 @@
33
33
  },
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "smqp": "^8.2.4"
36
+ "smqp": "^10.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@rollup/plugin-commonjs": "^25.0.5",
39
+ "@rollup/plugin-commonjs": "^29.0.0",
40
40
  "@types/amqplib": "^0.10.2",
41
- "c8": "^9.1.0",
42
- "chai": "^5.1.0",
41
+ "amqplib": "^0.10.4",
42
+ "c8": "^10.1.2",
43
+ "chai": "^6.2.1",
43
44
  "eslint": "^9.0.0",
44
- "globals": "^15.0.0",
45
- "mocha": "^10.2.0",
45
+ "globals": "^16.0.0",
46
+ "mocha": "^11.0.1",
46
47
  "prettier": "^3.2.5",
47
- "rollup": "^4.0.2"
48
+ "quibble": "^0.9.2",
49
+ "rollup": "^4.0.2",
50
+ "texample": "^0.1.0"
48
51
  },
49
52
  "keywords": [
50
53
  "fake",