Skip to content

Commit

Permalink
chore: replace mocha and chai with tap (#123)
Browse files Browse the repository at this point in the history
* initial

* transform more

* move conversion

* more

* minor

* minor

* Update test/types-multipart.test.js

Co-authored-by: Gürgün Dayıoğlu <gurgun.dayioglu@icloud.com>

---------

Co-authored-by: Gürgün Dayıoğlu <gurgun.dayioglu@icloud.com>
  • Loading branch information
Uzlopak and gurgunday authored Sep 28, 2023
1 parent 5f71e5f commit be5e0b0
Show file tree
Hide file tree
Showing 27 changed files with 1,394 additions and 1,444 deletions.
21 changes: 0 additions & 21 deletions .nycrc

This file was deleted.

4 changes: 4 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files:
- test/**/*.test.js

coverage: false
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint:everything": "npm run lint && npm run test:types",
"lint:fix": "standard --fix",
"lint:standard": "standard --verbose | snazzy",
"test:mocha": "mocha test",
"test:mocha": "tap",
"test:types": "tsd",
"test:coverage": "nyc npm run test",
"test": "npm run test:mocha"
Expand All @@ -37,15 +37,10 @@
"devDependencies": {
"@types/node": "^20.1.0",
"busboy": "^1.0.0",
"chai": "^4.3.6",
"eslint": "^8.23.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-n": "^16.0.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"photofinish": "^1.8.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.3.8",
"tsd": "^0.29.0",
"typescript": "^5.0.2"
},
Expand Down
46 changes: 0 additions & 46 deletions test/busboy-constructor.spec.js

This file was deleted.

75 changes: 75 additions & 0 deletions test/busboy-constructor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict'

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

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.'))
})

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.'))
})

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)
})

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.'))
})

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.'))
})

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' } }))
})

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)
})

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'))
})

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)
})

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)
})

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)
})
26 changes: 18 additions & 8 deletions test/decoder.spec.js → test/decoder.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const { assert, expect } = require('chai')
'use strict'

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

describe('Decoder', () => {
test('Decoder', t => {
const tests =
[
{
source: ['Hello world'],
Expand Down Expand Up @@ -63,8 +66,13 @@ describe('Decoder', () => {
expected: '5 + 5 = 10',
what: 'Spaces and encoded plus'
}
].forEach((v) => {
it(v.what, () => {
]
t.plan(tests.length + 1)

tests.forEach((v) => {
t.test(v.what, t => {
t.plan(1)

const dec = new Decoder()
let result = ''
v.source.forEach(function (s) {
Expand All @@ -73,16 +81,18 @@ describe('Decoder', () => {
const msg = 'Decoded string mismatch.\n' +
'Saw: ' + result + '\n' +
'Expected: ' + v.expected
assert.deepEqual(result, v.expected, msg)
t.strictSame(result, v.expected, msg)
})
})

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

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

expect(dec.buffer).to.be.not.equal(undefined)
t.notSame(dec.buffer, undefined)
dec.reset()
expect(dec.buffer).to.be.equal(undefined)
t.equal(dec.buffer, undefined)
})
})
14 changes: 0 additions & 14 deletions test/dicer-constructor.spec.js

This file was deleted.

22 changes: 22 additions & 0 deletions test/dicer-constructor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

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

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

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.test('without new operator a new dicer instance will be initialized', t => {
t.plan(1)

t.type(Dicer({
boundary: '----boundary'
}), Dicer)
})
})
21 changes: 13 additions & 8 deletions test/dicer-endfinish.spec.js → test/dicer-endfinish.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict'

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

test('dicer-endfinish', t => {
t.plan(1)

t.test('should properly handle finish', t => {
t.plan(4)

describe('dicer-endfinish', () => {
it('should properly handle finish', (done) => {
const CRLF = '\r\n'
const boundary = 'boundary'

Expand Down Expand Up @@ -39,12 +45,12 @@ describe('dicer-endfinish', () => {
setImmediate(afterWrite)
}
function finishListener () {
assert(firedEnd, 'Failed to end before finishing')
t.ok(firedEnd, 'end before finishing')
firedFinish = true
test2()
}
function afterWrite () {
assert(firedFinish, 'Failed to finish')
t.ok(firedFinish, 'Failed to finish')
}

let isPausePush = true
Expand Down Expand Up @@ -77,9 +83,8 @@ describe('dicer-endfinish', () => {
setImmediate(pauseAfterEnd)
}
function pauseAfterEnd () {
assert(firedPauseCallback, 'Failed to call callback after pause')
assert(firedPauseFinish, 'Failed to finish after pause')
done()
t.ok(firedPauseCallback, 'Called callback after pause')
t.ok(firedPauseFinish, 'Finish after pause')
}
function pauseFinish () {
firedPauseFinish = true
Expand Down
16 changes: 0 additions & 16 deletions test/dicer-export.spec.js

This file was deleted.

24 changes: 24 additions & 0 deletions test/dicer-export.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const { test } = require('tap')
const { Dicer } = require('../lib/main')

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

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

t.type(Dicer({
boundary: '----boundary'
}), Dicer)
})

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

t.type(new Dicer({
boundary: '----boundary'
}), Dicer)
})
})
Loading

0 comments on commit be5e0b0

Please sign in to comment.