Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit dbe7089

Browse files
committed
fix: flush should error on non-existent entries
License: MIT Signed-off-by: achingbrain <[email protected]>
1 parent 346e185 commit dbe7089

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/core/flush.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict'
22

3+
const waterfall = require('async/waterfall')
4+
const stat = require('./stat')
5+
36
const {
47
FILE_SEPARATOR
58
} = require('./utils')
@@ -25,6 +28,9 @@ module.exports = (context) => {
2528

2629
options = Object.assign({}, defaultOptions, options)
2730

28-
callback()
31+
waterfall([
32+
(cb) => stat(context)(path, options, cb),
33+
(stats, cb) => cb()
34+
], callback)
2935
}
3036
}

test/flush.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
const chai = require('chai')
5+
chai.use(require('dirty-chai'))
6+
const expect = chai.expect
47
const {
58
createMfs
69
} = require('./helpers')
@@ -18,4 +21,13 @@ describe('flush', function () {
1821
it('flushes the root node', () => {
1922
return mfs.flush()
2023
})
24+
25+
it('throws a error when trying to flush non-existent directories', async () => {
26+
try {
27+
await mfs.flush(`/some-dir-${Math.random()}`)
28+
throw new Error('No error was thrown')
29+
} catch (err) {
30+
expect(err.message).to.include('does not exist')
31+
}
32+
})
2133
})

0 commit comments

Comments
 (0)