UNPKG

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