@algolia/requester-fetch 5.3.2 → 5.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/requester-fetch",
3
- "version": "5.3.2",
3
+ "version": "5.4.1",
4
4
  "description": "Promise-based request library using Fetch.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,10 +21,15 @@
21
21
  "module": "./dist/requester.fetch.node.js",
22
22
  "require": "./dist/requester.fetch.node.cjs"
23
23
  },
24
+ "worker": {
25
+ "types": "./dist/requester.fetch.node.d.ts",
26
+ "default": "./dist/requester.fetch.node.js"
27
+ },
24
28
  "default": {
25
29
  "types": "./dist/requester.fetch.browser.d.ts",
26
30
  "module": "./dist/requester.fetch.browser.js",
27
- "import": "./dist/requester.fetch.browser.js"
31
+ "import": "./dist/requester.fetch.browser.js",
32
+ "default": "./dist/requester.fetch.browser.js"
28
33
  }
29
34
  },
30
35
  "./src/*": "./src/*.ts"
@@ -37,25 +42,21 @@
37
42
  "scripts": {
38
43
  "build": "yarn clean && yarn tsup",
39
44
  "clean": "rm -rf ./dist || true",
40
- "test": "jest",
45
+ "test": "vitest --run",
41
46
  "test:bundle": "publint . && attw --pack ."
42
47
  },
43
48
  "dependencies": {
44
- "@algolia/client-common": "5.3.2"
49
+ "@algolia/client-common": "5.4.1"
45
50
  },
46
51
  "devDependencies": {
47
52
  "@arethetypeswrong/cli": "0.16.1",
48
- "@babel/preset-env": "7.25.4",
49
- "@babel/preset-typescript": "7.24.7",
50
- "@types/jest": "29.5.12",
51
53
  "@types/node": "22.5.1",
52
54
  "cross-fetch": "4.0.0",
53
- "jest": "29.7.0",
54
55
  "nock": "13.5.5",
55
56
  "publint": "0.2.10",
56
- "ts-jest": "29.2.5",
57
57
  "tsup": "8.2.4",
58
- "typescript": "5.5.4"
58
+ "typescript": "5.5.4",
59
+ "vitest": "2.0.5"
59
60
  },
60
61
  "engines": {
61
62
  "node": ">= 14.0.0"
@@ -4,6 +4,7 @@ import { Readable } from 'stream';
4
4
  import type { EndRequest } from '@algolia/client-common';
5
5
  import crossFetch from 'cross-fetch';
6
6
  import nock from 'nock';
7
+ import { describe, test, beforeAll, afterAll, beforeEach, afterEach, expect } from 'vitest';
7
8
 
8
9
  import { createFetchRequester } from '../..';
9
10
  import {
@@ -29,7 +30,7 @@ afterEach(() => {
29
30
  const requester = createFetchRequester();
30
31
 
31
32
  describe('status code handling', () => {
32
- it('sends requests', async () => {
33
+ test('sends requests', async () => {
33
34
  const body = getStringifiedBody();
34
35
 
35
36
  nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(200, body);
@@ -39,7 +40,7 @@ describe('status code handling', () => {
39
40
  expect(response.content).toEqual(body);
40
41
  });
41
42
 
42
- it('resolves status 200', async () => {
43
+ test('resolves status 200', async () => {
43
44
  const body = getStringifiedBody();
44
45
 
45
46
  nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(200, body);
@@ -51,7 +52,7 @@ describe('status code handling', () => {
51
52
  expect(response.isTimedOut).toBe(false);
52
53
  });
53
54
 
54
- it('resolves status 300', async () => {
55
+ test('resolves status 300', async () => {
55
56
  const reason = 'Multiple Choices';
56
57
 
57
58
  nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(300, reason);
@@ -63,7 +64,7 @@ describe('status code handling', () => {
63
64
  expect(response.isTimedOut).toBe(false);
64
65
  });
65
66
 
66
- it('resolves status 400', async () => {
67
+ test('resolves status 400', async () => {
67
68
  const body = getStringifiedBody({
68
69
  message: 'Invalid Application-Id or API-Key',
69
70
  });
@@ -77,7 +78,7 @@ describe('status code handling', () => {
77
78
  expect(response.isTimedOut).toBe(false);
78
79
  });
79
80
 
80
- it('handles chunked responses inside unicode character boundaries', async () => {
81
+ test('handles chunked responses inside unicode character boundaries', async () => {
81
82
  const data = Buffer.from('äöü');
82
83
 
83
84
  // create a test response stream that is chunked inside a unicode character
@@ -106,11 +107,14 @@ describe('timeout handling', () => {
106
107
  server.listen('1113');
107
108
  });
108
109
 
109
- afterAll((done) => {
110
- server.close(() => done());
111
- });
110
+ afterAll(
111
+ () =>
112
+ new Promise((done) => {
113
+ done();
114
+ }),
115
+ );
112
116
 
113
- it('timeouts with the given 1 seconds connection timeout', async () => {
117
+ test('timeouts with the given 1 seconds connection timeout', async () => {
114
118
  const before = Date.now();
115
119
  const response = await requester.send({
116
120
  ...timeoutRequest,
@@ -125,7 +129,7 @@ describe('timeout handling', () => {
125
129
  expect(now - before).toBeLessThanOrEqual(1200);
126
130
  });
127
131
 
128
- it('connection timeouts with the given 2 seconds connection timeout', async () => {
132
+ test('connection timeouts with the given 2 seconds connection timeout', async () => {
129
133
  const before = Date.now();
130
134
  const response = await requester.send({
131
135
  ...timeoutRequest,
@@ -140,7 +144,7 @@ describe('timeout handling', () => {
140
144
  expect(now - before).toBeLessThanOrEqual(2200);
141
145
  });
142
146
 
143
- it("socket timeouts if response don't appears before the timeout with 2 seconds timeout", async () => {
147
+ test("socket timeouts if response don't appears before the timeout with 2 seconds timeout", async () => {
144
148
  const before = Date.now();
145
149
 
146
150
  const response = await requester.send({
@@ -156,7 +160,7 @@ describe('timeout handling', () => {
156
160
  expect(now - before).toBeLessThanOrEqual(2200);
157
161
  });
158
162
 
159
- it("socket timeouts if response don't appears before the timeout with 3 seconds timeout", async () => {
163
+ test("socket timeouts if response don't appears before the timeout with 3 seconds timeout", async () => {
160
164
  const before = Date.now();
161
165
  const response = await requester.send({
162
166
  ...timeoutRequest,
@@ -171,7 +175,7 @@ describe('timeout handling', () => {
171
175
  expect(now - before).toBeLessThanOrEqual(3200);
172
176
  });
173
177
 
174
- it('do not timeouts if response appears before the timeout', async () => {
178
+ test('do not timeouts if response appears before the timeout', async () => {
175
179
  const before = Date.now();
176
180
  const response = await requester.send({
177
181
  ...requestStub,
@@ -190,7 +194,7 @@ describe('timeout handling', () => {
190
194
  });
191
195
 
192
196
  describe('error handling', (): void => {
193
- it('resolves dns not found', async () => {
197
+ test('resolves dns not found', async () => {
194
198
  const request: EndRequest = {
195
199
  url: 'https://this-dont-exist.algolia.com',
196
200
  method: 'POST',
@@ -207,7 +211,7 @@ describe('error handling', (): void => {
207
211
  expect(response.isTimedOut).toBe(false);
208
212
  });
209
213
 
210
- it('resolves general network errors', async () => {
214
+ test('resolves general network errors', async () => {
211
215
  nock(testQueryBaseUrl, { reqheaders: headers })
212
216
  .post('/foo')
213
217
  .query(testQueryHeader)
@@ -224,7 +228,7 @@ describe('error handling', (): void => {
224
228
  });
225
229
 
226
230
  describe('requesterOptions', () => {
227
- it('allows to pass requesterOptions', async () => {
231
+ test('allows to pass requesterOptions', async () => {
228
232
  const body = getStringifiedBody();
229
233
  const requesterTmp = createFetchRequester({
230
234
  requesterOptions: {
@@ -248,7 +252,7 @@ describe('requesterOptions', () => {
248
252
  expect(response.content).toBe(body);
249
253
  });
250
254
 
251
- it('allows overriding default requesterOptions', async () => {
255
+ test('allows overriding default requesterOptions', async () => {
252
256
  const body = getStringifiedBody();
253
257
  const requesterTmp = createFetchRequester({
254
258
  requesterOptions: {