UNPKG

1.23 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 async 'should create a path to the file'(ctx) {
9 const tempPath = path.join(ctx.TEMP_TEST_DIR, 'path/to/temp/file.data')
10 const res = await ensurePath(tempPath)
11 assert.equal(res, tempPath)
12 await ctx.assertCanWriteFile(tempPath)
13 },
14 async 'should reject when trying to create a path where cannot'(ctx) {
15 await ctx.makeNoExecutableDirectory()
16 const tempPath = path.join(ctx.TEMP_NOX_DIR, 'path/to/temp/file.data')
17 try {
18 await ensurePath(tempPath)
19 throw new Error('should have thrown an error')
20 } catch (err) {
21 if(!/EACCES/.test(err.message)) {
22 throw err
23 }
24 }
25 },
26 async 'should not throw an error when dir already exists'(ctx) {
27 const tempPath = path.join(ctx.TEMP_TEST_DIR, 'file.data')
28 const res = await ensurePath(tempPath)
29 assert.equal(res, tempPath)
30 await ctx.assertCanWriteFile(tempPath)
31 },
32}
33
34module.exports = ensurePathTestSuite