UNPKG

1.14 kBJavaScriptView Raw
1const { throws, equal, deepEqual } = require('zoroaster/assert')
2const context = require('../context/WroteContext')
3const read = require('../../src/read')
4
5const readTestSuite = {
6 context,
7 async 'should read a file'({
8 tempFile, createTempFileWithData, TEST_DATA,
9 }) {
10 await createTempFileWithData()
11 const res = await read(tempFile)
12 equal(res, TEST_DATA)
13 },
14 async 'should read a file in binary'({
15 tempFile, createTempFileWithData, TEST_DATA_BUFFER,
16 }) {
17 await createTempFileWithData()
18 const res = await read(tempFile, { binary: true })
19 deepEqual(res, TEST_DATA_BUFFER)
20 },
21 async 'should reject if file not found'() {
22 const filename = `${Math.floor(Math.random() * 1e5)}.data`
23 await throws({
24 fn: read,
25 args: [filename],
26 code: 'ENOENT',
27 message: new RegExp(filename),
28 })
29 },
30 async 'should reject if path is not a string'() {
31 await throws({
32 fn: read,
33 message: /path must be a string/,
34 })
35 },
36}
37
38module.exports = readTestSuite