1 | const assert = require('assert')
|
2 | const { deepEqual } = require('assert-diff')
|
3 | const readDirStructure = require('../../src/read-dir-structure')
|
4 | const context = require('../context/WroteContext')
|
5 |
|
6 | const readDirStructureTestSuite = {
|
7 | context,
|
8 | 'should read directory structure': (ctx) => {
|
9 | return readDirStructure(ctx.FIXTURES_TEST_DIR)
|
10 | .then((res) => {
|
11 | deepEqual(res, ctx.expectedFixturesStructure)
|
12 | })
|
13 | },
|
14 | 'should not work when directory is not passed': () => {
|
15 | return readDirStructure()
|
16 | .then(() => {
|
17 | throw new Error('should have been rejected')
|
18 | }, (err) => {
|
19 | assert.equal(err.message, 'Please specify a path to the directory')
|
20 | })
|
21 | },
|
22 | 'should not work when directory does not exist': () => {
|
23 | return readDirStructure('fake-directory')
|
24 | .then(() => {
|
25 | throw new Error('should have been rejected')
|
26 | }, (err) => {
|
27 | assert.equal(err.code, 'ENOENT')
|
28 | })
|
29 | },
|
30 | 'should not work when passing a path to file': (ctx) => {
|
31 | return ctx.createTempFileWithData()
|
32 | .then(() => {
|
33 | return readDirStructure(ctx.tempFile)
|
34 | })
|
35 | .then(() => {
|
36 | throw new Error('should have been rejected')
|
37 | }, (err) => {
|
38 | assert.equal(err.code, 'ENOTDIR')
|
39 | })
|
40 | },
|
41 | 'should not work when passing a path to soft link': (ctx) => {
|
42 | return readDirStructure(ctx.FIXTURES_TEST_DIR_SOFT_LINK)
|
43 | .then(() => {
|
44 | throw new Error('should have been rejected')
|
45 | }, (err) => {
|
46 | assert.equal(err.message, 'Path is not a directory')
|
47 | assert.equal(err.code, 'ENOTDIR')
|
48 | })
|
49 | },
|
50 | }
|
51 |
|
52 | module.exports = readDirStructureTestSuite
|