diff --git a/lib/fs/__tests__/rm.test.js b/lib/fs/__tests__/rm.test.js new file mode 100644 index 00000000..150cb6d6 --- /dev/null +++ b/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)) + }) + }) +}) diff --git a/lib/fs/index.js b/lib/fs/index.js index 101aae9b..9bbaea4e 100644 --- a/lib/fs/index.js +++ b/lib/fs/index.js @@ -31,6 +31,7 @@ const api = [ 'readlink', 'realpath', 'rename', + 'rm', 'rmdir', 'stat', 'symlink', @@ -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' })