Skip to content

Commit

Permalink
added a couple more tests and eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Bucci committed Apr 19, 2024
1 parent 677fffe commit c0eff10
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 28 deletions.
34 changes: 17 additions & 17 deletions test/basename.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ const { test } = require('tap')
const basename = require('../lib/utils/basename')

test('basename', (t) => {
t.plan(3);
t.plan(3)

t.test('returns an empty string if the path is not a string', (t) => {
const result = basename({});
t.test('returns an empty string if the path is not a string', (t) => {
const result = basename({})

t.equal(result, '');
t.end();
});
t.equal(result, '')
t.end()
})

t.test('returns an empty string if the path includes a \' and the char after is a .', (t) => {
const result = basename('path\\.');
t.test('returns an empty string if the path includes a \' and the char after is a .', (t) => {
const result = basename('path\\.')

t.equal(result, '');
t.end();
});
t.equal(result, '')
t.end()
})

t.test('returns an empty string if the path is a .', (t) => {
const result = basename('.');
t.test('returns an empty string if the path is a .', (t) => {
const result = basename('.')

t.equal(result, '');
t.end();
});
});
t.equal(result, '')
t.end()
})
})
17 changes: 17 additions & 0 deletions test/busboy-emit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

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

test('busboy, emit', t => {
t.plan(1)

t.test('returns undefined when the event is called a second time and the busboy was already finished', t => {
const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
busboy._finished = true
busboy.emit('finish')

t.equal(busboy.emit('finish'), undefined)
t.end()
})
})
22 changes: 11 additions & 11 deletions test/dicer-write.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ const { test } = require('tap')
const { Dicer } = require('../lib/main')

test('dicer _write method', t => {
t.plan(1);
t.plan(1)

t.test('the PartStream instance is created only once if the _write method is called more than once', t => {
const dicer = new Dicer({headerFirst: true});
t.test('the PartStream instance is created only once if the _write method is called more than once', t => {
const dicer = new Dicer({ headerFirst: true })

dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
t.pass('write method called');
});
});
dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
dicer._write(Buffer.from('Content-Type: text/plain'), null, () => {
t.pass('write method called')
})
})

t.end();
});
});
t.end()
})
})
16 changes: 16 additions & 0 deletions test/multipart-constructor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

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

test('multipart constructor', t => {
t.plan(1)

t.test('throws if the boundary is not a string', t => {
const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })

t.throws(() => new Multipart(busboy, { boundary: 123 }), new Error('Multipart: Boundary not found'))
t.end()
})
})

0 comments on commit c0eff10

Please sign in to comment.