Skip to content

Commit 5cadd76

Browse files
authored
Allow passing undefined opts to move() (#955)
Fixes #947 Closes #948
1 parent 7bb0120 commit 5cadd76

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/__tests__/promise.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const methods = [
1010
'ensureFile',
1111
'ensureDir',
1212
'mkdirs',
13-
'move',
1413
'readJson',
1514
'readJSON',
1615
'remove'

lib/move/__tests__/move.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ describe('+ move()', () => {
140140
})
141141
})
142142

143+
it('should support promises', async () => {
144+
const src = path.join(TEST_DIR, 'a-file')
145+
const dest = path.join(TEST_DIR, 'a-file-dest')
146+
147+
await fse.move(src, dest)
148+
149+
const contents = fs.readFileSync(dest, 'utf8')
150+
const expected = /^sonic the hedgehog\r?\n$/
151+
assert.ok(contents.match(expected))
152+
})
153+
143154
it('should not move a file if source and destination are the same', done => {
144155
const src = path.join(TEST_DIR, 'a-file')
145156
const dest = src
@@ -273,6 +284,34 @@ describe('+ move()', () => {
273284
})
274285
})
275286

287+
describe('> when opts is explicit undefined', () => {
288+
it('works with callbacks', done => {
289+
const src = path.join(TEST_DIR, 'a-file')
290+
const dest = path.join(TEST_DIR, 'a-file-dest')
291+
292+
fse.move(src, dest, undefined, err => {
293+
assert.ifError(err)
294+
fs.readFile(dest, 'utf8', (err, contents) => {
295+
const expected = /^sonic the hedgehog\r?\n$/
296+
assert.ifError(err)
297+
assert.ok(contents.match(expected))
298+
done()
299+
})
300+
})
301+
})
302+
303+
it('works with promises', async () => {
304+
const src = path.join(TEST_DIR, 'a-file')
305+
const dest = path.join(TEST_DIR, 'a-file-dest')
306+
307+
await fse.move(src, dest, undefined)
308+
309+
const contents = fs.readFileSync(dest, 'utf8')
310+
const expected = /^sonic the hedgehog\r?\n$/
311+
assert.ok(contents.match(expected))
312+
})
313+
})
314+
276315
describeIfWindows('> when dest parent is root', () => {
277316
let dest
278317

lib/move/move.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function move (src, dest, opts, cb) {
1414
opts = {}
1515
}
1616

17+
opts = opts || {}
18+
1719
const overwrite = opts.overwrite || opts.clobber || false
1820

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

0 commit comments

Comments
 (0)