Skip to content

Commit

Permalink
Add promise support for fs.rm() (#860)
Browse files Browse the repository at this point in the history
Fixes #841
  • Loading branch information
RyanZim committed Jan 19, 2021
1 parent 6bffcd8 commit d409cf8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/fs/__tests__/rm.test.js
@@ -0,0 +1,30 @@
'use strict'

const fse = require('../..')
const os = require('os')
const path = require('path')
const assert = require('assert')
const atLeastNode = require('at-least-node')

/* eslint-env mocha */

// Used for tests on Node 14.14.0+ only
const describeNode14 = atLeastNode('14.14.0') ? describe : describe.skip

describeNode14('fs.rm', () => {
let TEST_FILE

beforeEach(done => {
TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'fs-rm')
fse.remove(TEST_FILE, done)
})

afterEach(done => fse.remove(TEST_FILE, done))

it('supports promises', () => {
fse.writeFileSync(TEST_FILE, 'hello')
return fse.rm(TEST_FILE).then(() => {
assert(!fse.pathExistsSync(TEST_FILE))
})
})
})
2 changes: 2 additions & 0 deletions lib/fs/index.js
Expand Up @@ -31,6 +31,7 @@ const api = [
'readlink',
'realpath',
'rename',
'rm',
'rmdir',
'stat',
'symlink',
Expand All @@ -41,6 +42,7 @@ const api = [
].filter(key => {
// Some commands are not available on some systems. Ex:
// fs.opendir was added in Node.js v12.12.0
// fs.rm was added in Node.js v14.14.0
// fs.lchown is not available on at least some Linux
return typeof fs[key] === 'function'
})
Expand Down

0 comments on commit d409cf8

Please sign in to comment.