Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate from tap to node:test and c8 #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
},
env: {
node: true,
mocha: true,
es6: true
}
}
3 changes: 0 additions & 3 deletions .taprc

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"lint:everything": "npm run lint && npm run test:types",
"lint:fix": "standard --fix",
"lint:standard": "standard --verbose | snazzy",
"test:mocha": "tap",
"test:unit": "c8 --statements 98 --branches 97 --functions 96 --lines 98 node --test",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot do c8 ---100 since there is not already 100% coverage being tracked here #126

"test:types": "tsd",
"test:coverage": "nyc npm run test",
"test": "npm run test:mocha"
"test": "npm run test:unit"
},
"devDependencies": {
"@types/node": "^22.0.0",
"busboy": "^1.6.0",
"c8": "^10.1.2",
"photofinish": "^1.8.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tap": "^21.0.0",
"tinybench": "^2.6.0",
"tsd": "^0.31.0",
"typescript": "~5.6.3"
Expand Down
13 changes: 7 additions & 6 deletions test/basename.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const basename = require('../lib/utils/basename')

test('basename', (t) => {
test('basename', async (t) => {
const testCases = [
{ description: 'returns an empty string if the path is not a string', path: {}, expected: '' },
{ description: 'returns an empty string if the path includes a \' and the char after is a .', path: 'path\\.', expected: '' },
Expand All @@ -19,10 +19,11 @@ test('basename', (t) => {

t.plan(testCases.length)

testCases.forEach((testCase, index) => {
t.test(testCase.description, t => {
const index = 0
for (const testCase of testCases) {
await t.test(testCase.description, t => {
t.plan(1)
t.equal(basename(testCase.path), testCase.expected, `Test case ${index + 1}`)
t.assert.strictEqual(basename(testCase.path), testCase.expected, `Test case ${index + 1}`)
})
})
}
})
27 changes: 15 additions & 12 deletions test/busboy-constructor.test.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,78 @@
'use strict'

const Busboy = require('../lib/main')
const { test } = require('tap')
const { test } = require('node:test')

test('busboy-constructor - should throw an Error if no options are provided', t => {
t.plan(1)

t.throws(() => new Busboy(), new Error('Busboy expected an options-Object.'))
t.assert.throws(() => new Busboy(), { message: 'Busboy expected an options-Object.' })
})

test('busboy-constructor - should throw an Error if options does not contain headers', t => {
t.plan(1)

t.throws(() => new Busboy({}), new Error('Busboy expected an options-Object with headers-attribute.'))
t.assert.throws(() => new Busboy({}), { message: 'Busboy expected an options-Object with headers-attribute.' })
})

test('busboy-constructor - if busboy is called without new-operator, still creates a busboy instance', t => {
t.plan(1)

const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
t.type(busboyInstance, Busboy)
t.assert.strictEqual(busboyInstance instanceof Busboy, true)
})

test('busboy-constructor - should throw an Error if content-type is not set', t => {
t.plan(1)

t.throws(() => new Busboy({ headers: {} }), new Error('Missing Content-Type-header.'))
t.assert.throws(() => new Busboy({ headers: {} }), { message: 'Missing Content-Type-header.' })
})

test('busboy-constructor - should throw an Error if content-type is unsupported', t => {
t.plan(1)

t.throws(() => new Busboy({ headers: { 'content-type': 'unsupported' } }), new Error('Unsupported Content-Type.'))
t.assert.throws(() => new Busboy({ headers: { 'content-type': 'unsupported' } }), { message: 'Unsupported Content-Type.' })
})

test('busboy-constructor - should not throw an Error if content-type is urlencoded', t => {
t.plan(1)

t.doesNotThrow(() => new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } }))
t.assert.doesNotThrow(() => new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } }))
})

test('busboy-constructor - if busboy is called without stream options autoDestroy is set to false', t => {
t.plan(1)

const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
t.equal(busboyInstance._writableState.autoDestroy, false)
t.assert.strictEqual(busboyInstance._writableState.autoDestroy, false)
})

test('busboy-constructor - if busboy is called with invalid value for stream option highWaterMark we should throw', t => {
t.plan(1)

t.throws(() => Busboy({ highWaterMark: 'not_allowed_value_for_highWaterMark', headers: { 'content-type': 'application/x-www-form-urlencoded' } }), new Error('not_allowed_value_for_highWaterMark'))
t.assert.throws(() => Busboy({ highWaterMark: 'not_allowed_value_for_highWaterMark', headers: { 'content-type': 'application/x-www-form-urlencoded' } }), {
// nmae: 'Error',
message: 'The property \'options.highWaterMark\' is invalid. Received \'not_allowed_value_for_highWaterMark\''
})
})

test('busboy-constructor - if busboy is called with stream options and autoDestroy:true, autoDestroy should be set to true', t => {
t.plan(1)

const busboyInstance = Busboy({ autoDestroy: true, headers: { 'content-type': 'application/x-www-form-urlencoded' } })
t.equal(busboyInstance._writableState.autoDestroy, true)
t.assert.strictEqual(busboyInstance._writableState.autoDestroy, true)
})

test('busboy-constructor - busboy should be initialized with private attribute _done set as false', t => {
t.plan(1)

const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
t.equal(busboyInstance._done, false)
t.assert.strictEqual(busboyInstance._done, false)
})

test('busboy-constructor - busboy should be initialized with private attribute _finished set as false', t => {
t.plan(1)

const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
t.equal(busboyInstance._finished, false)
t.assert.strictEqual(busboyInstance._finished, false)
})
5 changes: 2 additions & 3 deletions test/busboy-emit.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Busboy = require('../lib/main')
const { test } = require('tap')
const { test } = require('node:test')

test('busboy, emit', t => {
t.plan(1)
Expand All @@ -11,7 +11,6 @@ test('busboy, emit', t => {
busboy._finished = true
busboy.emit('finish')

t.equal(busboy.emit('finish'), undefined)
t.end()
t.assert.strictEqual(busboy.emit('finish'), undefined)
})
})
13 changes: 7 additions & 6 deletions test/decode-text.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const decodeText = require('../lib/utils/decodeText')

test('decodeText', t => {
test('decodeText', async t => {
const testCases = [
{ description: 'UTF-8 encoding', text: Buffer.from('Hello, World!', 'utf8'), initialCharset: 'utf8', outputCharset: 'utf8', expected: 'Hello, World!' },
{ description: 'UTF-8 encoding empty', text: Buffer.from('', 'utf8'), initialCharset: 'utf8', outputCharset: 'utf8', expected: '' },
Expand All @@ -24,10 +24,11 @@ test('decodeText', t => {

t.plan(testCases.length)

testCases.forEach((c, index) => {
t.test(c.description, t => {
const index = 0
for (const c of testCases) {
await t.test(c.description, t => {
t.plan(1)
t.equal(decodeText(c.text, c.initialCharset, c.outputCharset), c.expected, `Test case ${index + 1}`)
t.assert.strictEqual(decodeText(c.text, c.initialCharset, c.outputCharset), c.expected, `Test case ${index + 1}`)
})
})
}
})
16 changes: 8 additions & 8 deletions test/decoder.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const Decoder = require('../lib/utils/Decoder')

test('Decoder', t => {
test('Decoder', async t => {
const tests =
[
{
Expand Down Expand Up @@ -74,8 +74,8 @@ test('Decoder', t => {
]
t.plan(tests.length + 1)

tests.forEach((v) => {
t.test(v.what, t => {
for (const v of tests) {
await t.test(v.what, async t => {
t.plan(1)

const dec = new Decoder()
Expand All @@ -86,18 +86,18 @@ test('Decoder', t => {
const msg = 'Decoded string mismatch.\n' +
'Saw: ' + result + '\n' +
'Expected: ' + v.expected
t.strictSame(result, v.expected, msg)
t.assert.deepStrictEqual(result, v.expected, msg)
})
})
}

t.test('reset sets internal buffer to undefined', t => {
t.plan(2)

const dec = new Decoder()
dec.write('Hello+world%2')

t.notSame(dec.buffer, undefined)
t.assert.notStrictEqual(dec.buffer, undefined)
dec.reset()
t.equal(dec.buffer, undefined)
t.assert.strictEqual(dec.buffer, undefined)
})
})
14 changes: 7 additions & 7 deletions test/dicer-constructor.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const Dicer = require('../deps/dicer/lib/Dicer')

test('dicer-constructor', t => {
test('dicer-constructor', async t => {
t.plan(2)

t.test('should throw an Error when no options parameter is supplied to Dicer', t => {
await t.test('should throw an Error when no options parameter is supplied to Dicer', t => {
t.plan(1)

t.throws(() => new Dicer(), new Error('Boundary required'))
t.assert.throws(() => new Dicer(), { message: 'Boundary required' })
})

t.test('without new operator a new dicer instance will be initialized', t => {
await t.test('without new operator a new dicer instance will be initialized', t => {
t.plan(1)

t.type(Dicer({
t.assert.strictEqual(Dicer({
boundary: '----boundary'
}), Dicer)
}) instanceof Dicer, true)
})
})
Loading