UNPKG

1.17 kBJavaScriptView Raw
1const assert = require('assert')
2const context = require('../context/WroteContext')
3const read = require('../../src/read')
4
5const readTestSuite = {
6 context,
7 'should read a file': (ctx) => {
8 return ctx.createTempFileWithData()
9 .then(() => {
10 return read(ctx.tempFile)
11 })
12 .then((res) => {
13 assert.equal(res, ctx.TEST_DATA)
14 })
15 },
16 'should reject if file not found': () => {
17 const filename = `${Math.floor(Math.random() * 1e5)}.data`
18 return read(filename)
19 .then(() => {
20 throw new Error('should have been rejected with ENOENT')
21 }, (err) => {
22 if (/ENOENT/.test(err.message)) {
23 assert(err.message.indexOf(filename) !== -1)
24 }
25 })
26 },
27 'should reject if path is not a string': () => {
28 return read()
29 .then(() => {
30 throw new Error('should have been rejected')
31 }, (err) => {
32 assert(err.message.indexOf('path must be a string') !== -1)
33 })
34 },
35}
36
37module.exports = readTestSuite