Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Aug 23, 2023
1 parent 9261ecb commit 54d2a24
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 200 deletions.
2 changes: 2 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
files:
- test/**/*.test.js
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 @@ -40,15 +40,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.28.0",
"typescript": "^5.0.2"
},
Expand Down
46 changes: 0 additions & 46 deletions test/busboy-constructor.spec.js

This file was deleted.

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

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

test('busboy-constructor', t => {
t.plan(11)

t.test('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.test('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.test('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.test('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.test('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.test('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.test('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.test('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.test('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.test('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.test('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)
})
})
26 changes: 17 additions & 9 deletions test/parse-params.spec.js → test/parse-params.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

const { inspect } = require('util')
const { assert } = require('chai')
const { test } = require('tap')
const parseParams = require('../lib/utils/parseParams')

describe('parse-params', () => {
[
test('parse-params', t => {
const tests = [
{
source: 'video/ogg',
expected: ['video/ogg'],
Expand Down Expand Up @@ -104,13 +106,19 @@ describe('parse-params', () => {
expected: ['multipart/form-data', ['charset', 'utf-8'], ['boundary', '0xKhTmLbOuNdArY']],
what: 'Multiple non-quoted parameters'
}
].forEach((v) => {
it(v.what, () => {
]

t.plan(tests.length)

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

const result = parseParams(v.source)
const msg = 'parsed parameters mismatch.\n' +
'Saw: ' + inspect(result) + '\n' +
'Expected: ' + inspect(v.expected)
assert.deepEqual(result, v.expected, msg)
t.strictSame(
result,
v.expected,
`parsed parameters match.\nSaw: ${inspect(result)}\nExpected: ${inspect(v.expected)}`)
})
})
})
Loading

0 comments on commit 54d2a24

Please sign in to comment.