Skip to content

Commit be5e0b0

Browse files
Uzlopakgurgunday
andauthored
chore: replace mocha and chai with tap (#123)
* initial * transform more * move conversion * more * minor * minor * Update test/types-multipart.test.js Co-authored-by: Gürgün Dayıoğlu <[email protected]> --------- Co-authored-by: Gürgün Dayıoğlu <[email protected]>
1 parent 5f71e5f commit be5e0b0

27 files changed

+1394
-1444
lines changed

.nycrc

Lines changed: 0 additions & 21 deletions
This file was deleted.

.taprc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
files:
2+
- test/**/*.test.js
3+
4+
coverage: false

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lint:everything": "npm run lint && npm run test:types",
2727
"lint:fix": "standard --fix",
2828
"lint:standard": "standard --verbose | snazzy",
29-
"test:mocha": "mocha test",
29+
"test:mocha": "tap",
3030
"test:types": "tsd",
3131
"test:coverage": "nyc npm run test",
3232
"test": "npm run test:mocha"
@@ -37,15 +37,10 @@
3737
"devDependencies": {
3838
"@types/node": "^20.1.0",
3939
"busboy": "^1.0.0",
40-
"chai": "^4.3.6",
41-
"eslint": "^8.23.0",
42-
"eslint-config-standard": "^17.0.0",
43-
"eslint-plugin-n": "^16.0.0",
44-
"mocha": "^10.0.0",
45-
"nyc": "^15.1.0",
4640
"photofinish": "^1.8.0",
4741
"snazzy": "^9.0.0",
4842
"standard": "^17.0.0",
43+
"tap": "^16.3.8",
4944
"tsd": "^0.29.0",
5045
"typescript": "^5.0.2"
5146
},

test/busboy-constructor.spec.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

test/busboy-constructor.test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict'
2+
3+
const Busboy = require('../lib/main')
4+
const { test } = require('tap')
5+
6+
test('busboy-constructor - should throw an Error if no options are provided', t => {
7+
t.plan(1)
8+
9+
t.throws(() => new Busboy(), new Error('Busboy expected an options-Object.'))
10+
})
11+
12+
test('busboy-constructor - should throw an Error if options does not contain headers', t => {
13+
t.plan(1)
14+
15+
t.throws(() => new Busboy({}), new Error('Busboy expected an options-Object with headers-attribute.'))
16+
})
17+
18+
test('busboy-constructor - if busboy is called without new-operator, still creates a busboy instance', t => {
19+
t.plan(1)
20+
21+
const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
22+
t.type(busboyInstance, Busboy)
23+
})
24+
25+
test('busboy-constructor - should throw an Error if content-type is not set', t => {
26+
t.plan(1)
27+
28+
t.throws(() => new Busboy({ headers: {} }), new Error('Missing Content-Type-header.'))
29+
})
30+
31+
test('busboy-constructor - should throw an Error if content-type is unsupported', t => {
32+
t.plan(1)
33+
34+
t.throws(() => new Busboy({ headers: { 'content-type': 'unsupported' } }), new Error('Unsupported Content-Type.'))
35+
})
36+
37+
test('busboy-constructor - should not throw an Error if content-type is urlencoded', t => {
38+
t.plan(1)
39+
40+
t.doesNotThrow(() => new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } }))
41+
})
42+
43+
test('busboy-constructor - if busboy is called without stream options autoDestroy is set to false', t => {
44+
t.plan(1)
45+
46+
const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
47+
t.equal(busboyInstance._writableState.autoDestroy, false)
48+
})
49+
50+
test('busboy-constructor - if busboy is called with invalid value for stream option highWaterMark we should throw', t => {
51+
t.plan(1)
52+
53+
t.throws(() => Busboy({ highWaterMark: 'not_allowed_value_for_highWaterMark', headers: { 'content-type': 'application/x-www-form-urlencoded' } }), new Error('not_allowed_value_for_highWaterMark'))
54+
})
55+
56+
test('busboy-constructor - if busboy is called with stream options and autoDestroy:true, autoDestroy should be set to true', t => {
57+
t.plan(1)
58+
59+
const busboyInstance = Busboy({ autoDestroy: true, headers: { 'content-type': 'application/x-www-form-urlencoded' } })
60+
t.equal(busboyInstance._writableState.autoDestroy, true)
61+
})
62+
63+
test('busboy-constructor - busboy should be initialized with private attribute _done set as false', t => {
64+
t.plan(1)
65+
66+
const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
67+
t.equal(busboyInstance._done, false)
68+
})
69+
70+
test('busboy-constructor - busboy should be initialized with private attribute _finished set as false', t => {
71+
t.plan(1)
72+
73+
const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
74+
t.equal(busboyInstance._finished, false)
75+
})

test/decoder.spec.js renamed to test/decoder.test.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
const { assert, expect } = require('chai')
1+
'use strict'
2+
3+
const { test } = require('tap')
24
const Decoder = require('../lib/utils/Decoder')
35

4-
describe('Decoder', () => {
6+
test('Decoder', t => {
7+
const tests =
58
[
69
{
710
source: ['Hello world'],
@@ -63,8 +66,13 @@ describe('Decoder', () => {
6366
expected: '5 + 5 = 10',
6467
what: 'Spaces and encoded plus'
6568
}
66-
].forEach((v) => {
67-
it(v.what, () => {
69+
]
70+
t.plan(tests.length + 1)
71+
72+
tests.forEach((v) => {
73+
t.test(v.what, t => {
74+
t.plan(1)
75+
6876
const dec = new Decoder()
6977
let result = ''
7078
v.source.forEach(function (s) {
@@ -73,16 +81,18 @@ describe('Decoder', () => {
7381
const msg = 'Decoded string mismatch.\n' +
7482
'Saw: ' + result + '\n' +
7583
'Expected: ' + v.expected
76-
assert.deepEqual(result, v.expected, msg)
84+
t.strictSame(result, v.expected, msg)
7785
})
7886
})
7987

80-
it('reset sets internal buffer to undefined', () => {
88+
t.test('reset sets internal buffer to undefined', t => {
89+
t.plan(2)
90+
8191
const dec = new Decoder()
8292
dec.write('Hello+world%2')
8393

84-
expect(dec.buffer).to.be.not.equal(undefined)
94+
t.notSame(dec.buffer, undefined)
8595
dec.reset()
86-
expect(dec.buffer).to.be.equal(undefined)
96+
t.equal(dec.buffer, undefined)
8797
})
8898
})

test/dicer-constructor.spec.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/dicer-constructor.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const Dicer = require('../deps/dicer/lib/Dicer')
5+
6+
test('dicer-constructor', t => {
7+
t.plan(2)
8+
9+
t.test('should throw an Error when no options parameter is supplied to Dicer', t => {
10+
t.plan(1)
11+
12+
t.throws(() => new Dicer(), new Error('Boundary required'))
13+
})
14+
15+
t.test('without new operator a new dicer instance will be initialized', t => {
16+
t.plan(1)
17+
18+
t.type(Dicer({
19+
boundary: '----boundary'
20+
}), Dicer)
21+
})
22+
})

test/dicer-endfinish.spec.js renamed to test/dicer-endfinish.test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
'use strict'
2+
13
const Dicer = require('../deps/dicer/lib/Dicer')
2-
const { assert } = require('chai')
4+
const { test } = require('tap')
5+
6+
test('dicer-endfinish', t => {
7+
t.plan(1)
8+
9+
t.test('should properly handle finish', t => {
10+
t.plan(4)
311

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

@@ -39,12 +45,12 @@ describe('dicer-endfinish', () => {
3945
setImmediate(afterWrite)
4046
}
4147
function finishListener () {
42-
assert(firedEnd, 'Failed to end before finishing')
48+
t.ok(firedEnd, 'end before finishing')
4349
firedFinish = true
4450
test2()
4551
}
4652
function afterWrite () {
47-
assert(firedFinish, 'Failed to finish')
53+
t.ok(firedFinish, 'Failed to finish')
4854
}
4955

5056
let isPausePush = true
@@ -77,9 +83,8 @@ describe('dicer-endfinish', () => {
7783
setImmediate(pauseAfterEnd)
7884
}
7985
function pauseAfterEnd () {
80-
assert(firedPauseCallback, 'Failed to call callback after pause')
81-
assert(firedPauseFinish, 'Failed to finish after pause')
82-
done()
86+
t.ok(firedPauseCallback, 'Called callback after pause')
87+
t.ok(firedPauseFinish, 'Finish after pause')
8388
}
8489
function pauseFinish () {
8590
firedPauseFinish = true

test/dicer-export.spec.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)