Repository: jprichardson/node-fs-extra
Pull request #861 (2021-01-19 13:39:24)

test: fix birthtime not available on tmpfs on Linux
Fixes tests being broken locally, mentioned in https://github.com/jprichardson/node-fs-extra/pull/860#pullrequestreview-571128655.

Birth time is unavailable on tmpfs:

```console
$ LANG=C stat /tmp/fs-extra/
  File: /tmp/fs-extra/
  Size: 60              Blocks: 0          IO Block: 4096   directory
Device: 31h/49d Inode: 32254       Links: 3
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ chalker)   Gid: ( 1000/ chalker)
Access: 2021-01-19 16:38:51.439969625 +0300
Modify: 2021-01-19 16:38:55.031733100 +0300
Change: 2021-01-19 16:38:55.031733100 +0300
 Birth: -
```


Patch:
diff --git a/lib/fs/index.js b/lib/fs/index.js
index 101aae9..9bbaea4 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'
 })


Test patch:
diff --git a/lib/copy-sync/__tests__/copy-sync-dir.test.js b/lib/copy-sync/__tests__/copy-sync-dir.test.js
index 7a5ecf5..78cfd87 100644
--- a/lib/copy-sync/__tests__/copy-sync-dir.test.js
+++ b/lib/copy-sync/__tests__/copy-sync-dir.test.js
@@ -182,7 +182,7 @@ describe('+ copySync() / dir', () => {
     it('should apply filter when it is applied only to dest', done => {
       const timeCond = new Date().getTime()
 
-      const filter = (s, d) => fs.statSync(d).birthtime.getTime() < timeCond
+      const filter = (s, d) => fs.statSync(d).mtime.getTime() < timeCond
 
       const dest = path.join(TEST_DIR, 'dest')
 
@@ -197,7 +197,7 @@ describe('+ copySync() / dir', () => {
 
     it('should apply filter when it is applied to both src and dest', done => {
       const timeCond = new Date().getTime()
-      const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).birthtime.getTime() > timeCond
+      const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).mtime.getTime() > timeCond
 
       const dest = path.join(TEST_DIR, 'dest')
 
diff --git a/lib/copy/__tests__/copy.test.js b/lib/copy/__tests__/copy.test.js
index ba230f3..5cc07e3 100644
--- a/lib/copy/__tests__/copy.test.js
+++ b/lib/copy/__tests__/copy.test.js
@@ -366,7 +366,7 @@ describe('fs-extra', () => {
       it('should apply filter when it is applied only to dest', done => {
         const timeCond = new Date().getTime()
 
-        const filter = (s, d) => fs.statSync(d).birthtime.getTime() < timeCond
+        const filter = (s, d) => fs.statSync(d).mtime.getTime() < timeCond
 
         const src = path.join(TEST_DIR, 'src')
         fse.mkdirsSync(src)
@@ -388,7 +388,7 @@ describe('fs-extra', () => {
 
       it('should apply filter when it is applied to both src and dest', done => {
         const timeCond = new Date().getTime()
-        const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).birthtime.getTime() > timeCond
+        const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).mtime.getTime() > timeCond
 
         const dest = path.join(TEST_DIR, 'dest')
         setTimeout(() => {
diff --git a/lib/fs/__tests__/rm.test.js b/lib/fs/__tests__/rm.test.js
new file mode 100644
index 0000000..150cb6d
--- /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))
+    })
+  })
+})