@tryghost/webhook-mock-receiver 2.3.17 → 2.3.19

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.
@@ -6,6 +6,9 @@ const pWaitFor = require('p-wait-for').default;
6
6
  class WebhookMockReceiver {
7
7
  constructor({ snapshotManager }) {
8
8
  this.snapshotManager = snapshotManager;
9
+ // Bumped by mock() and reset() so reply callbacks from a superseded
10
+ // mock can't record into the current one
11
+ this._mockGeneration = 0;
9
12
  this.recordRequest = this.recordRequest.bind(this);
10
13
  }
11
14
 
@@ -16,7 +19,9 @@ class WebhookMockReceiver {
16
19
 
17
20
  async receivedRequest() {
18
21
  // @NOTE: figure out a better waiting mechanism here, don't allow it to hang forever
19
- await pWaitFor(() => this._receiver.isDone());
22
+ // Nock marks the interceptor done when the request matches, before the
23
+ // async reply callback records it, so wait for both
24
+ await pWaitFor(() => this._receiver.isDone() && this.headers !== undefined);
20
25
  }
21
26
 
22
27
  /**
@@ -26,7 +31,14 @@ class WebhookMockReceiver {
26
31
  */
27
32
  mock(url) {
28
33
  const parsedURL = new URL(url);
29
- const recordRequest = this.recordRequest;
34
+ const mockGeneration = ++this._mockGeneration;
35
+ const recordRequest = (...args) => {
36
+ if (mockGeneration === this._mockGeneration) {
37
+ this.recordRequest(...args);
38
+ }
39
+ };
40
+ this.body = undefined;
41
+ this.headers = undefined;
30
42
 
31
43
  this._receiver = nock(parsedURL.origin)
32
44
  .post(parsedURL.pathname)
@@ -62,6 +74,7 @@ class WebhookMockReceiver {
62
74
 
63
75
  reset() {
64
76
  nock.cleanAll();
77
+ this._mockGeneration += 1;
65
78
  this._receiver = undefined;
66
79
  this.body = undefined;
67
80
  this.headers = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/webhook-mock-receiver",
3
- "version": "2.3.17",
3
+ "version": "2.3.19",
4
4
  "license": "MIT",
5
5
  "author": "Ghost Foundation",
6
6
  "repository": {
@@ -17,11 +17,11 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "p-wait-for": "^6.0.0"
20
+ "p-wait-for": "^7.0.0"
21
21
  },
22
22
  "devDependencies": {
23
- "got": "16.0.0",
24
- "nock": "15.0.1",
23
+ "got": "16.2.0",
24
+ "nock": "15.0.5",
25
25
  "sinon": "22.1.0"
26
26
  },
27
27
  "peerDependencies": {