@fastify/compress 8.0.0-pre.fv5.1 → 8.0.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.
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
3
+ const { test, describe } = require('node:test')
4
4
  const { createReadStream } = require('node:fs')
5
5
  const path = require('node:path')
6
6
  const zlib = require('node:zlib')
@@ -18,9 +18,10 @@ function createPayload (compressor) {
18
18
  return payload
19
19
  }
20
20
 
21
- test('When using routes `decompress` settings :', async (t) => {
22
- t.test('it should decompress data using the route custom provided `createInflate` method', async (t) => {
21
+ describe('When using routes `decompress` settings :', async (suite) => {
22
+ test('it should decompress data using the route custom provided `createInflate` method', async (t) => {
23
23
  t.plan(8)
24
+ const equal = t.assert.equal
24
25
 
25
26
  let usedCustomGlobal = false
26
27
  let usedCustom = false
@@ -51,11 +52,11 @@ test('When using routes `decompress` settings :', async (t) => {
51
52
  },
52
53
  payload: createPayload(zlib.createDeflate)
53
54
  }).then((response) => {
54
- t.equal(usedCustom, false)
55
- t.equal(usedCustomGlobal, true)
55
+ equal(usedCustom, false)
56
+ equal(usedCustomGlobal, true)
56
57
 
57
- t.equal(response.statusCode, 200)
58
- t.equal(response.body, '@fastify/compress')
58
+ equal(response.statusCode, 200)
59
+ equal(response.body, '@fastify/compress')
59
60
 
60
61
  usedCustom = false
61
62
  usedCustomGlobal = false
@@ -69,15 +70,16 @@ test('When using routes `decompress` settings :', async (t) => {
69
70
  },
70
71
  payload: createPayload(zlib.createDeflate)
71
72
  })
72
- t.equal(usedCustom, true)
73
- t.equal(usedCustomGlobal, false)
73
+ equal(usedCustom, true)
74
+ equal(usedCustomGlobal, false)
74
75
 
75
- t.equal(response.statusCode, 200)
76
- t.equal(response.body, '@fastify/compress')
76
+ equal(response.statusCode, 200)
77
+ equal(response.body, '@fastify/compress')
77
78
  })
78
79
 
79
- t.test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
80
+ test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
80
81
  t.plan(8)
82
+ const equal = t.assert.equal
81
83
 
82
84
  let usedCustomGlobal = false
83
85
  let usedCustom = false
@@ -108,11 +110,11 @@ test('When using routes `decompress` settings :', async (t) => {
108
110
  },
109
111
  payload: createPayload(zlib.createGzip)
110
112
  }).then((response) => {
111
- t.equal(usedCustom, false)
112
- t.equal(usedCustomGlobal, true)
113
+ equal(usedCustom, false)
114
+ equal(usedCustomGlobal, true)
113
115
 
114
- t.equal(response.statusCode, 200)
115
- t.equal(response.body, '@fastify/compress')
116
+ equal(response.statusCode, 200)
117
+ equal(response.body, '@fastify/compress')
116
118
 
117
119
  usedCustom = false
118
120
  usedCustomGlobal = false
@@ -127,15 +129,16 @@ test('When using routes `decompress` settings :', async (t) => {
127
129
  },
128
130
  payload: createPayload(zlib.createGzip)
129
131
  })
130
- t.equal(usedCustom, true)
131
- t.equal(usedCustomGlobal, false)
132
+ equal(usedCustom, true)
133
+ equal(usedCustomGlobal, false)
132
134
 
133
- t.equal(response.statusCode, 200)
134
- t.equal(response.body, '@fastify/compress')
135
+ equal(response.statusCode, 200)
136
+ equal(response.body, '@fastify/compress')
135
137
  })
136
138
 
137
- t.test('it should not decompress data when route `decompress` option is set to `false`', async (t) => {
139
+ test('it should not decompress data when route `decompress` option is set to `false`', async (t) => {
138
140
  t.plan(6)
141
+ const equal = t.assert.equal
139
142
 
140
143
  let usedCustomGlobal = false
141
144
  const customZlibGlobal = { createGunzip: () => (usedCustomGlobal = true) && zlib.createGunzip() }
@@ -160,10 +163,10 @@ test('When using routes `decompress` settings :', async (t) => {
160
163
  },
161
164
  payload: createPayload(zlib.createGzip)
162
165
  }).then((response) => {
163
- t.equal(usedCustomGlobal, true)
166
+ equal(usedCustomGlobal, true)
164
167
 
165
- t.equal(response.statusCode, 200)
166
- t.equal(response.body, '@fastify/compress')
168
+ equal(response.statusCode, 200)
169
+ equal(response.body, '@fastify/compress')
167
170
 
168
171
  usedCustomGlobal = false
169
172
  })
@@ -177,10 +180,10 @@ test('When using routes `decompress` settings :', async (t) => {
177
180
  },
178
181
  payload: createPayload(zlib.createGzip)
179
182
  })
180
- t.equal(usedCustomGlobal, false)
183
+ equal(usedCustomGlobal, false)
181
184
 
182
- t.equal(response.statusCode, 400)
183
- t.strictSame(response.json(), {
185
+ equal(response.statusCode, 400)
186
+ t.assert.deepEqual(response.json(), {
184
187
  statusCode: 400,
185
188
  code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
186
189
  error: 'Bad Request',
@@ -188,7 +191,7 @@ test('When using routes `decompress` settings :', async (t) => {
188
191
  })
189
192
  })
190
193
 
191
- t.test('it should throw an error on invalid route `decompress` settings', async (t) => {
194
+ test('it should throw an error on invalid route `decompress` settings', async (t) => {
192
195
  t.plan(1)
193
196
 
194
197
  const fastify = Fastify()
@@ -199,14 +202,15 @@ test('When using routes `decompress` settings :', async (t) => {
199
202
  reply.send(request.body.name)
200
203
  })
201
204
  } catch (err) {
202
- t.equal(err.message, 'Unknown value for route decompress configuration')
205
+ t.assert.equal(err.message, 'Unknown value for route decompress configuration')
203
206
  }
204
207
  })
205
208
  })
206
209
 
207
- test('When using the old routes `{ config: decompress }` option :', async (t) => {
208
- t.test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
210
+ describe('When using the old routes `{ config: decompress }` option :', async () => {
211
+ test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
209
212
  t.plan(8)
213
+ const equal = t.assert.equal
210
214
 
211
215
  let usedCustomGlobal = false
212
216
  let usedCustom = false
@@ -239,11 +243,11 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
239
243
  },
240
244
  payload: createPayload(zlib.createGzip)
241
245
  }).then((response) => {
242
- t.equal(usedCustom, false)
243
- t.equal(usedCustomGlobal, true)
246
+ equal(usedCustom, false)
247
+ equal(usedCustomGlobal, true)
244
248
 
245
- t.equal(response.statusCode, 200)
246
- t.equal(response.body, '@fastify/compress')
249
+ equal(response.statusCode, 200)
250
+ equal(response.body, '@fastify/compress')
247
251
 
248
252
  usedCustom = false
249
253
  usedCustomGlobal = false
@@ -258,14 +262,14 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
258
262
  },
259
263
  payload: createPayload(zlib.createGzip)
260
264
  })
261
- t.equal(usedCustom, true)
262
- t.equal(usedCustomGlobal, false)
265
+ equal(usedCustom, true)
266
+ equal(usedCustomGlobal, false)
263
267
 
264
- t.equal(response.statusCode, 200)
265
- t.equal(response.body, '@fastify/compress')
268
+ equal(response.statusCode, 200)
269
+ equal(response.body, '@fastify/compress')
266
270
  })
267
271
 
268
- t.test('it should use the old routes `{ config: decompress }` options over routes `decompress` options', async (t) => {
272
+ test('it should use the old routes `{ config: decompress }` options over routes `decompress` options', async (t) => {
269
273
  t.plan(1)
270
274
 
271
275
  const fastify = Fastify()
@@ -283,7 +287,7 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
283
287
  reply.send(request.body.name)
284
288
  })
285
289
  } catch (err) {
286
- t.equal(err.message, 'Unknown value for route decompress configuration')
290
+ t.assert.equal(err.message, 'Unknown value for route decompress configuration')
287
291
  }
288
292
  })
289
293
  })
@@ -3,67 +3,71 @@
3
3
  const { createReadStream } = require('node:fs')
4
4
  const { Socket } = require('node:net')
5
5
  const { Duplex, PassThrough, Readable, Stream, Transform, Writable } = require('node:stream')
6
- const { test } = require('tap')
6
+ const { test } = require('node:test')
7
7
  const { isStream, isDeflate, isGzip, intoAsyncIterator } = require('../lib/utils')
8
8
 
9
9
  test('isStream() utility should be able to detect Streams', async (t) => {
10
10
  t.plan(12)
11
+ const equal = t.assert.equal
11
12
 
12
- t.equal(isStream(new Stream()), true)
13
- t.equal(isStream(new Readable()), true)
14
- t.equal(isStream(new Writable()), true)
15
- t.equal(isStream(new Duplex()), true)
16
- t.equal(isStream(new Transform()), true)
17
- t.equal(isStream(new PassThrough()), true)
13
+ equal(isStream(new Stream()), true)
14
+ equal(isStream(new Readable()), true)
15
+ equal(isStream(new Writable()), true)
16
+ equal(isStream(new Duplex()), true)
17
+ equal(isStream(new Transform()), true)
18
+ equal(isStream(new PassThrough()), true)
18
19
 
19
- t.equal(isStream(createReadStream('package.json')), true)
20
+ equal(isStream(createReadStream('package.json')), true)
20
21
 
21
- t.equal(isStream(new Socket()), true)
22
+ equal(isStream(new Socket()), true)
22
23
 
23
- t.equal(isStream({}), false)
24
- t.equal(isStream(null), false)
25
- t.equal(isStream(undefined), false)
26
- t.equal(isStream(''), false)
24
+ equal(isStream({}), false)
25
+ equal(isStream(null), false)
26
+ equal(isStream(undefined), false)
27
+ equal(isStream(''), false)
27
28
  })
28
29
 
29
30
  test('isDeflate() utility should be able to detect deflate compressed Buffer', async (t) => {
30
31
  t.plan(14)
31
-
32
- t.equal(isDeflate(Buffer.alloc(0)), false)
33
- t.equal(isDeflate(Buffer.alloc(0)), false)
34
- t.equal(isDeflate(Buffer.from([0x78])), false)
35
- t.equal(isDeflate(Buffer.from([0x78, 0x00])), false)
36
- t.equal(isDeflate(Buffer.from([0x7a, 0x01])), false)
37
- t.equal(isDeflate(Buffer.from([0x88, 0x01])), false)
38
- t.equal(isDeflate(Buffer.from([0x78, 0x11])), false)
39
- t.equal(isDeflate(Buffer.from([0x78, 0x01])), true)
40
- t.equal(isDeflate(Buffer.from([0x78, 0x9c])), true)
41
- t.equal(isDeflate(Buffer.from([0x78, 0xda])), true)
42
-
43
- t.equal(isDeflate({}), false)
44
- t.equal(isDeflate(null), false)
45
- t.equal(isDeflate(undefined), false)
46
- t.equal(isDeflate(''), false)
32
+ const equal = t.assert.equal
33
+
34
+ equal(isDeflate(Buffer.alloc(0)), false)
35
+ equal(isDeflate(Buffer.alloc(0)), false)
36
+ equal(isDeflate(Buffer.from([0x78])), false)
37
+ equal(isDeflate(Buffer.from([0x78, 0x00])), false)
38
+ equal(isDeflate(Buffer.from([0x7a, 0x01])), false)
39
+ equal(isDeflate(Buffer.from([0x88, 0x01])), false)
40
+ equal(isDeflate(Buffer.from([0x78, 0x11])), false)
41
+ equal(isDeflate(Buffer.from([0x78, 0x01])), true)
42
+ equal(isDeflate(Buffer.from([0x78, 0x9c])), true)
43
+ equal(isDeflate(Buffer.from([0x78, 0xda])), true)
44
+
45
+ equal(isDeflate({}), false)
46
+ equal(isDeflate(null), false)
47
+ equal(isDeflate(undefined), false)
48
+ equal(isDeflate(''), false)
47
49
  })
48
50
 
49
51
  test('isGzip() utility should be able to detect gzip compressed Buffer', async (t) => {
50
52
  t.plan(10)
51
-
52
- t.equal(isGzip(Buffer.alloc(0)), false)
53
- t.equal(isGzip(Buffer.alloc(1)), false)
54
- t.equal(isGzip(Buffer.alloc(2)), false)
55
- t.equal(isGzip(Buffer.from([0x1f, 0x8b])), false)
56
- t.equal(isGzip(Buffer.from([0x1f, 0x8b, 0x00])), false)
57
- t.equal(isGzip(Buffer.from([0x1f, 0x8b, 0x08])), true)
58
-
59
- t.equal(isGzip({}), false)
60
- t.equal(isGzip(null), false)
61
- t.equal(isGzip(undefined), false)
62
- t.equal(isGzip(''), false)
53
+ const equal = t.assert.equal
54
+
55
+ equal(isGzip(Buffer.alloc(0)), false)
56
+ equal(isGzip(Buffer.alloc(1)), false)
57
+ equal(isGzip(Buffer.alloc(2)), false)
58
+ equal(isGzip(Buffer.from([0x1f, 0x8b])), false)
59
+ equal(isGzip(Buffer.from([0x1f, 0x8b, 0x00])), false)
60
+ equal(isGzip(Buffer.from([0x1f, 0x8b, 0x08])), true)
61
+
62
+ equal(isGzip({}), false)
63
+ equal(isGzip(null), false)
64
+ equal(isGzip(undefined), false)
65
+ equal(isGzip(''), false)
63
66
  })
64
67
 
65
68
  test('intoAsyncIterator() utility should handle different data', async (t) => {
66
69
  t.plan(8)
70
+ const equal = t.assert.equal
67
71
 
68
72
  const buf = Buffer.from('foo')
69
73
  const str = 'foo'
@@ -76,30 +80,30 @@ test('intoAsyncIterator() utility should handle different data', async (t) => {
76
80
  const obj = {}
77
81
 
78
82
  for await (const buffer of intoAsyncIterator(buf)) {
79
- t.equal(buffer, buf)
83
+ equal(buffer, buf)
80
84
  }
81
85
 
82
86
  for await (const string of intoAsyncIterator(str)) {
83
- t.equal(string, str)
87
+ equal(string, str)
84
88
  }
85
89
 
86
90
  for await (const chunk of intoAsyncIterator(arr)) {
87
- t.equal(chunk, str)
91
+ equal(chunk, str)
88
92
  }
89
93
 
90
94
  for await (const chunk of intoAsyncIterator(arrayBuffer)) {
91
- t.equal(chunk.toString(), Buffer.from(arrayBuffer).toString())
95
+ equal(chunk.toString(), Buffer.from(arrayBuffer).toString())
92
96
  }
93
97
 
94
98
  for await (const chunk of intoAsyncIterator(typedArray)) {
95
- t.equal(chunk.toString(), Buffer.from(typedArray).toString())
99
+ equal(chunk.toString(), Buffer.from(typedArray).toString())
96
100
  }
97
101
 
98
102
  for await (const chunk of intoAsyncIterator(asyncIterator)) {
99
- t.equal(chunk, str)
103
+ equal(chunk, str)
100
104
  }
101
105
 
102
106
  for await (const chunk of intoAsyncIterator(obj)) {
103
- t.equal(chunk, obj)
107
+ equal(chunk, obj)
104
108
  }
105
109
  })
package/.taprc DELETED
@@ -1,3 +0,0 @@
1
- disable-coverage: true
2
- files:
3
- - test/**/*.test.js