Skip to content

Commit e62384c

Browse files
Giovanni BucciGiovanni Bucci
Giovanni Bucci
and
Giovanni Bucci
authored
More automated tests (#152)
* started writing a couple of automated tests to chip in, working towards the 100% test coverage goal * added a couple more tests and eslint fixes * added all the cases for the basename * better test description * added the plan for the subtest too in the dicer-write.test.js * PR review: removed the t.end() in dicer-write.test.js --------- Co-authored-by: Giovanni Bucci <[email protected]>
1 parent 0614584 commit e62384c

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

test/basename.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const basename = require('../lib/utils/basename')
5+
6+
test('basename', (t) => {
7+
const testCases = [
8+
{ description: 'returns an empty string if the path is not a string', path: {}, expected: '' },
9+
{ description: 'returns an empty string if the path includes a \' and the char after is a .', path: 'path\\.', expected: '' },
10+
{ description: 'returns an empty string if the path includes a / and the char after is a .', path: 'path/.', expected: '' },
11+
{ description: 'returns an empty string if the path includes a \' and the chars after are a ..', path: 'path\\..', expected: '' },
12+
{ description: 'returns an empty string if the path includes a / and the chars after are a ..', path: 'path/..', expected: '' },
13+
{ description: 'returns the path if the path includes a \' and the rest is anything other than dots', path: 'path\\subpath', expected: 'subpath' },
14+
{ description: 'returns the path if the path includes a / and the rest is anything other than dots', path: 'path/subpath', expected: 'subpath' },
15+
{ description: 'returns an empty string if the path is a .', path: '.', expected: '' },
16+
{ description: 'returns an empty string if the path is a ..', path: '..', expected: '' },
17+
{ description: 'returns the path if the path is anything other than dots', path: 'subpath', expected: 'subpath' }
18+
]
19+
20+
t.plan(testCases.length)
21+
22+
testCases.forEach((testCase, index) => {
23+
t.test(testCase.description, t => {
24+
t.plan(1)
25+
t.equal(basename(testCase.path), testCase.expected, `Test case ${index + 1}`)
26+
})
27+
})
28+
})

test/busboy-emit.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
const Busboy = require('../lib/main')
4+
const { test } = require('tap')
5+
6+
test('busboy, emit', t => {
7+
t.plan(1)
8+
9+
t.test('returns undefined when the event is called a second time and the busboy was already finished', t => {
10+
const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
11+
busboy._finished = true
12+
busboy.emit('finish')
13+
14+
t.equal(busboy.emit('finish'), undefined)
15+
t.end()
16+
})
17+
})

test/dicer-write.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const { Dicer } = require('../lib/main')
5+
6+
test('dicer _write method', t => {
7+
t.plan(1)
8+
9+
t.test('calls the callback cb() when headerFirst is set and all the data have been written', t => {
10+
t.plan(1)
11+
const dicer = new Dicer({ headerFirst: true })
12+
13+
dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
14+
dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
15+
t.pass('write method called')
16+
})
17+
})
18+
})
19+
})

test/multipart-constructor.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
const Multipart = require('../lib/types/multipart')
4+
const Busboy = require('../lib/main')
5+
const { test } = require('tap')
6+
7+
test('multipart constructor', t => {
8+
t.plan(1)
9+
10+
t.test('throws if the boundary is not a string', t => {
11+
const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
12+
13+
t.throws(() => new Multipart(busboy, { boundary: 123 }), new Error('Multipart: Boundary not found'))
14+
t.end()
15+
})
16+
})

0 commit comments

Comments
 (0)