Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promise support for fs.rm() #860

Merged
merged 1 commit into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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