This repository was archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (42 loc) · 1.35 KB
/
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
39
40
41
42
43
44
45
46
47
48
'use strict'
// Setup
import test from 'ava'
import any2buffer from './../index'
import fs from 'fs'
import path from 'path'
const assets = path.resolve(__dirname, 'assets')
const hello = path.join(assets, 'hello.json')
const helloOut = path.join(assets, 'helloOut.json')
test('file path returns buffer', async (assert) => {
let buf = await any2buffer(hello)
assert.true(!!buf)
assert.true(buf instanceof Buffer)
fs.writeFileSync(helloOut, buf)
let helloOutJson = require(helloOut).hello
assert.is(helloOutJson, 'world')
fs.unlinkSync(helloOut)
})
test('utf8 string returns buffer', async (assert) => {
let buf = await any2buffer('hello')
assert.true(!!buf)
assert.true(buf instanceof Buffer)
assert.is(buf.toString('utf8'), 'hello')
})
test('base64 string returns buffer', async (assert) => {
let buf = await any2buffer('aGVsbG8=')
assert.true(!!buf)
assert.true(buf instanceof Buffer)
assert.is(buf.toString('utf8'), 'hello')
})
test('hex string returns buffer', async (assert) => {
let buf = await any2buffer('68656c6c6f')
assert.true(!!buf)
assert.true(buf instanceof Buffer)
assert.is(buf.toString('utf8'), 'hello')
})
test('buffer returns buffer', async (assert) => {
let buf = await any2buffer(Buffer.from('hello', 'utf8'))
assert.true(!!buf)
assert.true(buf instanceof Buffer)
assert.is(buf.toString('utf8'), 'hello')
})