Skip to content

Commit

Permalink
Allow passing undefined opts to move() (#955)
Browse files Browse the repository at this point in the history
Fixes #947

Closes #948
  • Loading branch information
RyanZim committed Apr 16, 2022
1 parent 7bb0120 commit 5cadd76
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/__tests__/promise.test.js
Expand Up @@ -10,7 +10,6 @@ const methods = [
'ensureFile',
'ensureDir',
'mkdirs',
'move',
'readJson',
'readJSON',
'remove'
Expand Down
39 changes: 39 additions & 0 deletions lib/move/__tests__/move.test.js
Expand Up @@ -140,6 +140,17 @@ describe('+ move()', () => {
})
})

it('should support promises', async () => {
const src = path.join(TEST_DIR, 'a-file')
const dest = path.join(TEST_DIR, 'a-file-dest')

await fse.move(src, dest)

const contents = fs.readFileSync(dest, 'utf8')
const expected = /^sonic the hedgehog\r?\n$/
assert.ok(contents.match(expected))
})

it('should not move a file if source and destination are the same', done => {
const src = path.join(TEST_DIR, 'a-file')
const dest = src
Expand Down Expand Up @@ -273,6 +284,34 @@ describe('+ move()', () => {
})
})

describe('> when opts is explicit undefined', () => {
it('works with callbacks', done => {
const src = path.join(TEST_DIR, 'a-file')
const dest = path.join(TEST_DIR, 'a-file-dest')

fse.move(src, dest, undefined, err => {
assert.ifError(err)
fs.readFile(dest, 'utf8', (err, contents) => {
const expected = /^sonic the hedgehog\r?\n$/
assert.ifError(err)
assert.ok(contents.match(expected))
done()
})
})
})

it('works with promises', async () => {
const src = path.join(TEST_DIR, 'a-file')
const dest = path.join(TEST_DIR, 'a-file-dest')

await fse.move(src, dest, undefined)

const contents = fs.readFileSync(dest, 'utf8')
const expected = /^sonic the hedgehog\r?\n$/
assert.ok(contents.match(expected))
})
})

describeIfWindows('> when dest parent is root', () => {
let dest

Expand Down
2 changes: 2 additions & 0 deletions lib/move/move.js
Expand Up @@ -14,6 +14,8 @@ function move (src, dest, opts, cb) {
opts = {}
}

opts = opts || {}

const overwrite = opts.overwrite || opts.clobber || false

stat.checkPaths(src, dest, 'move', opts, (err, stats) => {
Expand Down

0 comments on commit 5cadd76

Please sign in to comment.