@pbvision/fastify-firestore-service 0.0.16 → 0.0.17

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 (2) hide show
  1. package/package.json +1 -1
  2. package/test/base-test.js +10 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/fastify-firestore-service",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Web Framework using Fastify and Firestore ORM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/test/base-test.js CHANGED
@@ -24,6 +24,11 @@ class BaseAppTest extends BaseTest {
24
24
  return func
25
25
  }
26
26
 
27
+ beforeEach () {
28
+ this.fetchMock = fetchWrapper.__mock
29
+ fetchWrapper.__mock.mockClear()
30
+ }
31
+
27
32
  async beforeAll () {
28
33
  const makeService = await this.getMakeServiceFunc()
29
34
  this.fastify = FASTIFY_CACHE ?? await makeService()
@@ -56,10 +61,6 @@ class BaseAppTest extends BaseTest {
56
61
  }
57
62
  })
58
63
  }
59
-
60
- afterEach () {
61
- fetchWrapper.__mock.mockReset()
62
- }
63
64
  }
64
65
 
65
66
  function makeHeadersObj (headers) {
@@ -92,8 +93,8 @@ function makeNodeFetchMockValueFromPromise (promise) {
92
93
  function makeNodeFetchMockValue (body, status, callback) {
93
94
  const mockValue = new Promise(resolve => {
94
95
  // setTimeout is used so that this promise does not synchronously resolve
95
- // because unmocked got will NEVER return synchronously. This ensures
96
- // functions which call got() never resolve synchronously (which can
96
+ // because unmocked fetch will NEVER return synchronously. This ensures
97
+ // functions which call fetch() never resolve synchronously (which can
97
98
  // change their behavior... e.g., allow them to throw when called,
98
99
  // instead of only rejecting later when await'ed).
99
100
  // https://github.com/facebook/jest/issues/6028 (since jest 21.x)
@@ -136,12 +137,11 @@ function mockNodeFetch () {
136
137
  */
137
138
  nodeFetchMock.mockRespWithCallback = (...callbacks) => {
138
139
  nodeFetchMock.mockImplementation(request => {
139
- const { url, ...options } = request
140
140
  for (const callback of callbacks) {
141
141
  const desiredHTTPResponse = callback(request)
142
142
  if (desiredHTTPResponse === true) {
143
- const unmockedFetch = jest.requireActual('../src/got')
144
- return unmockedFetch(url, options)
143
+ const unmockedFetch = jest.requireActual('../src/fetch-wrapper.js')
144
+ return unmockedFetch(request)
145
145
  }
146
146
  if (desiredHTTPResponse) {
147
147
  if (desiredHTTPResponse.then) {
@@ -153,7 +153,7 @@ function mockNodeFetch () {
153
153
  desiredHTTPResponse.status || 200)
154
154
  }
155
155
  }
156
- throw new Error(`un-mocked got() request: ${JSON.stringify(request)}`)
156
+ throw new Error(`un-mocked fetchWrapper() request: ${JSON.stringify(request)}`)
157
157
  })
158
158
  }
159
159