-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.test.js
62 lines (52 loc) · 1.52 KB
/
utils.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fsp = require('fs').promises
const os = require('os')
const path = require('path')
const uuidv4 = require('uuid').v4
const { _bundle } = require('./utils')
describe('bundler', () => {
test('does not throw on empty js file & returns string', async () => {
const tmpd = await fsp.mkdtemp(path.join(os.tmpdir(), 'bundle-'))
const inpath = path.join(tmpd, 'index.js')
const filecontents = ' '
await fsp.writeFile(inpath, filecontents)
let err;
let res
try {
res = await _bundle(inpath)
} catch (e) {
console.log(e)
err = e
}
expect(err).not.toBeDefined()
expect(typeof res === 'string').toBe(true)
})
test('does not throw on js file & returns string', async () => {
const tmpd = await fsp.mkdtemp(path.join(os.tmpdir(), 'bundle-'))
const code = 'module.exports.inc = (x) => x + 1'
const inpath = path.join(tmpd, 'index.js')
await fsp.writeFile(inpath, code)
let err;
let res
try {
res = await _bundle(inpath)
} catch (e) {
console.log(e)
err = e
}
expect(err).not.toBeDefined()
expect(typeof res === 'string').toBe(true)
})
test('throws on invalid input path', async () => {
const code = 'module.exports.inc = (x) => x + 1'
const invalidinpath = path.join(os.tmpdir(), `surely-this-path-does-not-exist-${uuidv4()}`)
let err;
let res
try {
res = await _bundle(invalidinpath)
console.log(res)
} catch (e) {
err = e
}
expect(err).toBeDefined()
})
})