Repository: jprichardson/node-fs-extra (js)

Issue:
fs.move doesn't return error on moving same nonexistent folder/file
#### Issue:
When i `fs.move()` using two paths that are the same and both are invalid(nonexistent) paths, the function does not return an error, which it should since you are trying to move a nonexistent path.

#### Setup:
This is being ran inside of an electron render, which means its being ran inside of a chrome wrapper. This issue persists through fs-extra 3.0

#### Example:
`fs.move("nonexistent/path","nonexistent/path", (err) => { console.log(err)})`
`// err returns null`

#### Usage:
I use this in my personal repo:
https://github.com/zosman1/The_Archiver/blob/c65ed9dfb7ae0855b1fcb8026204c8d6876a96af/app/index.js#L25

Pull request description:
move() should error when src & dest are the same and src doesn't exist
Fixes #414; bug introduced in #378

@jprichardson What's your opinion on semver for this patch?

Patch:
diff --git a/lib/move-sync/index.js b/lib/move-sync/index.js
index 6d510d0..a5e9114 100644
--- a/lib/move-sync/index.js
+++ b/lib/move-sync/index.js
@@ -14,7 +14,7 @@ function moveSync (src, dest, options) {
   src = path.resolve(src)
   dest = path.resolve(dest)
 
-  if (src === dest) return
+  if (src === dest) return fs.accessSync(src)
 
   if (isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`)
 
diff --git a/lib/move/index.js b/lib/move/index.js
index c44e66b..e5eb2c1 100644
--- a/lib/move/index.js
+++ b/lib/move/index.js
@@ -37,7 +37,7 @@ function move (source, dest, options, callback) {
 
   function doRename () {
     if (path.resolve(source) === path.resolve(dest)) {
-      setImmediate(callback)
+      fs.access(source, callback)
     } else if (overwrite) {
       fs.rename(source, dest, err => {
         if (!err) return callback()


Test patch:
diff --git a/lib/move-sync/__tests__/move-sync.test.js b/lib/move-sync/__tests__/move-sync.test.js
index 4b943d4..48da8f1 100644
--- a/lib/move-sync/__tests__/move-sync.test.js
+++ b/lib/move-sync/__tests__/move-sync.test.js
@@ -61,6 +61,13 @@ describe('moveSync()', () => {
     assert.ok(contents.match(expected), `${contents} match ${expected}`)
   })
 
+  it('should error if src and dest are the same and src does not exist', () => {
+    const src = `${TEST_DIR}/non-existent`
+    const dest = src
+
+    assert.throws(() => fse.moveSync(src, dest))
+  })
+
   it('should rename a file on the same device', () => {
     const src = `${TEST_DIR}/a-file`
     const dest = `${TEST_DIR}/a-file-dest`
diff --git a/lib/move/__tests__/move.test.js b/lib/move/__tests__/move.test.js
index 429e79c..988a75c 100644
--- a/lib/move/__tests__/move.test.js
+++ b/lib/move/__tests__/move.test.js
@@ -79,6 +79,16 @@ describe('move', () => {
     })
   })
 
+  it('should error if source and destination are the same and source does not exist', done => {
+    const src = `${TEST_DIR}/non-existent`
+    const dest = src
+
+    fse.move(src, dest, err => {
+      assert(err)
+      done()
+    })
+  })
+
   it('should not move a directory if source and destination are the same', done => {
     const src = `${TEST_DIR}/a-folder`
     const dest = src