UNPKG

1.2 kBJavaScriptView Raw
1const assert = require('assert')
2const { join } = require('path')
3const assertExists = require('../../src/assert-exists')
4const context = require('../context/WroteContext')
5
6const { equal } = assert
7
8const eraseTestSuite = {
9 context,
10 async 'should throw an error for a file'({ tempFile }) {
11 try {
12 await assertExists(tempFile)
13 throw new Error('should have thrown')
14 } catch ({ message }) {
15 equal(message, `Path ${tempFile} does not exist.`)
16 }
17 },
18 async 'should pass for a file'({ tempFile, createTempFileWithData }) {
19 await createTempFileWithData()
20 await assertExists(tempFile)
21 },
22 async 'should pass for a directory'({ FIXTURES_TEST_DIR }) {
23 await assertExists(FIXTURES_TEST_DIR)
24 },
25 async 'should throw a permission denied error'({ makeNoExecutableDirectory }) {
26 const temp = await makeNoExecutableDirectory()
27 const test = join(temp, 'test/wrote.data')
28 try {
29 await assertExists(test)
30 throw new Error('should have thrown')
31 } catch ({ code }) {
32 equal(code, 'EACCES')
33 }
34 },
35}
36
37module.exports = eraseTestSuite