-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest.js
38 lines (31 loc) · 920 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-env mocha */
const md5File = require('./')
const assert = require('assert')
const filename = 'LICENSE.md'
const preCheckedSum = 'ad1faf9381e43c471dc381c17a4ee4b6'
describe('md5File', () => {
it('works asynchronously', async () => {
const hash = await md5File(filename)
assert.strictEqual(hash, preCheckedSum)
})
it('works synchronously', () => {
assert.strictEqual(md5File.sync(filename), preCheckedSum)
})
it('has proper error handling', async () => {
await assert.rejects(md5File('does not exist'), (err) => err.code === 'ENOENT')
})
it('only accepts strings and buffers', async () => {
var invalidValues = [
[],
{},
123,
null,
undefined,
Symbol('test')
]
for (const value of invalidValues) {
assert.throws(() => { md5File.sync(value) }, TypeError)
await assert.rejects(md5File(value), TypeError)
}
})
})