UNPKG

1.82 kBJavaScriptView Raw
1const { deepEqual } = require('assert-diff')
2const readDir = require('../../src/read-dir')
3const context = require('../context/WroteContext')
4const expected = require('../fixtures/expected/read-dir')
5
6const readDirTestSuite = {
7 context,
8 'should read a directory': (ctx) => {
9 return readDir(ctx.FIXTURES_TEST_DIR)
10 .then((res) => {
11 deepEqual(res, expected.normal)
12 })
13 },
14 'should read a directory recursively': (ctx) => {
15 return readDir(ctx.FIXTURES_TEST_DIR, true)
16 .then((res) => {
17 deepEqual(res, expected.recursive)
18 })
19 },
20 'should reject promise if directory is not found': () => {
21 const dirname = `${Math.floor(Math.random() * 1e5)}.data`
22 return readDir(dirname)
23 .then(() => {
24 throw new Error('should have thrown an error')
25 }, (err) => {
26 if (!/ENOENT/.test(err.message)) {
27 throw err
28 }
29 })
30 },
31 'should reject promise if not a directory': (ctx) => {
32 return ctx.createTempFileWithData()
33 .then(() => {
34 return readDir(ctx.tempFile)
35 })
36 .then(() => {
37 throw new Error('should have thrown an error')
38 }, (err) => {
39 if (!/ENOTDIR/.test(err.message)) {
40 throw err
41 }
42 })
43 },
44 'should throw if path is not a string': () => {
45 return readDir()
46 .then(() => {
47 throw new Error('should have thrown an error')
48 }, (err) => {
49 if (!/path must be a string/.test(err.message)) {
50 throw err
51 }
52 })
53 },
54}
55
56module.exports = readDirTestSuite