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

Allow passing undefined opts to move() #955

Merged
merged 1 commit into from Apr 16, 2022
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
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