Skip to content

Commit 9d4a640

Browse files
committed
test: migrate from tap to node big.test.js
1 parent 5719a8e commit 9d4a640

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

test/big.test.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const test = require('tap').test
3+
const test = require('node:test')
44
const FormData = require('form-data')
55
const Fastify = require('fastify')
66
const multipart = require('..')
@@ -12,13 +12,13 @@ const crypto = require('node:crypto')
1212
const streamToNull = require('../lib/stream-consumer')
1313

1414
// skipping on Github Actions because it takes too long
15-
test('should upload a big file in constant memory', { skip: process.env.CI }, function (t) {
15+
test('should upload a big file in constant memory', { skip: process.env.CI }, function (t, done) {
1616
t.plan(10)
1717

1818
const fastify = Fastify()
1919
const hashInput = crypto.createHash('sha256')
2020

21-
t.teardown(fastify.close.bind(fastify))
21+
t.after(() => fastify.close())
2222

2323
fastify.register(multipart, {
2424
limits: {
@@ -28,23 +28,23 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
2828
})
2929

3030
fastify.post('/', async function (req, reply) {
31-
t.ok(req.isMultipart())
31+
t.assert.ok(req.isMultipart())
3232

3333
for await (const part of req.parts()) {
3434
if (part.file) {
35-
t.equal(part.type, 'file')
36-
t.equal(part.fieldname, 'upload')
37-
t.equal(part.filename, 'random-data')
38-
t.equal(part.encoding, '7bit')
39-
t.equal(part.mimetype, 'binary/octet-stream')
35+
t.assert.strictEqual(part.type, 'file')
36+
t.assert.strictEqual(part.fieldname, 'upload')
37+
t.assert.strictEqual(part.filename, 'random-data')
38+
t.assert.strictEqual(part.encoding, '7bit')
39+
t.assert.strictEqual(part.mimetype, 'binary/octet-stream')
4040

4141
await streamToNull(part.file)
4242
}
4343
}
4444

4545
const memory = process.memoryUsage()
46-
t.ok(memory.rss < 500 * 1024 * 1024)
47-
t.ok(memory.heapTotal < 500 * 1024 * 1024)
46+
t.assert.ok(memory.rss < 500 * 1024 * 1024)
47+
t.assert.ok(memory.heapTotal < 500 * 1024 * 1024)
4848

4949
reply.send()
5050
})
@@ -66,7 +66,7 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
6666
total -= n
6767

6868
if (total === 0) {
69-
t.pass('finished generating')
69+
t.assert.ok('finished generating')
7070
hashInput.end()
7171
this.push(null)
7272
}
@@ -88,12 +88,18 @@ test('should upload a big file in constant memory', { skip: process.env.CI }, fu
8888
method: 'POST'
8989
}
9090

91-
const req = http.request(opts, () => { fastify.close(noop) })
91+
const req = http.request(opts, (res) => {
92+
res.on('data', () => {})
93+
94+
res.on('end', () => {
95+
fastify.close(() => {
96+
done()
97+
})
98+
})
99+
})
92100

93101
pump(form, req, function (err) {
94-
t.error(err, 'client pump: no err')
102+
t.assert.ifError(err, 'client pump: no err')
95103
})
96104
})
97105
})
98-
99-
function noop () { }

0 commit comments

Comments
 (0)