UNPKG

1.44 kBJavaScriptView Raw
1const assert = require('assert')
2const path = require('path')
3const ensurePath = require('../../src/ensure-path')
4const context = require('../context/WroteContext')
5
6const ensurePathTestSuite = {
7 context,
8 'should create a path to the file': (ctx) => {
9 const tempPath = path.join(ctx.TEMP_TEST_DIR, 'path/to/temp/file.data')
10 return ensurePath(tempPath)
11 .then((res) => {
12 assert.equal(res, tempPath)
13 return ctx.assertCanWriteFile(tempPath)
14 })
15 },
16 'should reject when trying to create a path where cannot': (ctx) => {
17 return ctx.makeNoExecutableDirectory()
18 .then(() => {
19 const tempPath = path.join(ctx.TEMP_NOX_DIR, 'path/to/temp/file.data')
20 return ensurePath(tempPath)
21 })
22 .then(() => {
23 throw new Error('should have thrown an error')
24 })
25 .catch((err) => {
26 if(!/EACCES/.test(err.message)) {
27 throw err
28 }
29 })
30 },
31 'should not throw an error when dir already exists': (ctx) => {
32 const tempPath = path.join(ctx.TEMP_TEST_DIR, 'file.data')
33 return ensurePath(tempPath)
34 .then((res) => {
35 assert.equal(res, tempPath)
36 return ctx.assertCanWriteFile(tempPath)
37 })
38 },
39}
40
41module.exports = ensurePathTestSuite