diff --git a/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js b/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js index 2470b84f..3685faaf 100644 --- a/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js +++ b/lib/move-sync/__tests__/move-sync-prevent-moving-into-itself.test.js @@ -37,68 +37,81 @@ describe('+ moveSync() - prevent moving into itself', () => { afterEach(() => fs.removeSync(TEST_DIR)) describe('> when source is a file', () => { - it(`should move the file successfully even when dest is a subdir of src`, () => { - const srcFile = path.join(TEST_DIR, 'src', 'srcfile.txt') + it(`should move the file successfully even when dest parent is 'src/dest'`, () => { const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt') - fs.writeFileSync(srcFile, dat0) + return testSuccessFile(src, destFile) + }) + + it(`should move the file successfully when dest parent is 'src/src_dest'`, () => { + const destFile = path.join(TEST_DIR, 'src', 'src_dest', 'destfile.txt') + return testSuccessFile(src, destFile) + }) - fs.moveSync(srcFile, destFile) + it(`should move the file successfully when dest parent is 'src/dest_src'`, () => { + const destFile = path.join(TEST_DIR, 'src', 'dest_src', 'destfile.txt') + return testSuccessFile(src, destFile) + }) + + it(`should move the file successfully when dest parent is 'src/dest/src'`, () => { + const destFile = path.join(TEST_DIR, 'src', 'dest', 'src', 'destfile.txt') + return testSuccessFile(src, destFile) + }) - const out = fs.readFileSync(destFile, 'utf8') - assert.strictEqual(out, dat0, 'file contents matched') - assert(!fs.existsSync(srcFile)) + it(`should move the file successfully when dest parent is 'srcsrc/dest'`, () => { + const destFile = path.join(TEST_DIR, 'srcsrc', 'dest', 'destfile.txt') + return testSuccessFile(src, destFile) }) }) describe('> when source is a directory', () => { it(`should move the directory successfully when dest is 'src_dest'`, () => { dest = path.join(TEST_DIR, 'src_dest') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'src-dest'`, () => { dest = path.join(TEST_DIR, 'src-dest') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'dest_src'`, () => { dest = path.join(TEST_DIR, 'dest_src') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'src_dest/src'`, () => { dest = path.join(TEST_DIR, 'src_dest', 'src') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'src-dest/src'`, () => { dest = path.join(TEST_DIR, 'src-dest', 'src') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'dest_src/src'`, () => { dest = path.join(TEST_DIR, 'dest_src', 'src') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'src_src/dest'`, () => { dest = path.join(TEST_DIR, 'src_src', 'dest') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'src-src/dest'`, () => { dest = path.join(TEST_DIR, 'src-src', 'dest') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'srcsrc/dest'`, () => { dest = path.join(TEST_DIR, 'srcsrc', 'dest') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should move the directory successfully when dest is 'dest/src'`, () => { dest = path.join(TEST_DIR, 'dest', 'src') - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it('should move the directory successfully when dest is very nested that all its parents need to be created', () => { @@ -106,7 +119,7 @@ describe('+ moveSync() - prevent moving into itself', () => { 'grault', 'garply', 'fred', 'plugh', 'thud', 'some', 'highly', 'deeply', 'badly', 'nasty', 'crazy', 'mad', 'nested', 'dest') assert(!fs.existsSync(dest)) - return testSuccess(src, dest) + return testSuccessDir(src, dest) }) it(`should throw error when dest is 'src/dest'`, () => { @@ -131,7 +144,17 @@ describe('+ moveSync() - prevent moving into itself', () => { }) }) -function testSuccess (src, dest) { +function testSuccessFile (src, destFile) { + const srcFile = path.join(src, FILES[0]) + + fs.moveSync(srcFile, destFile) + + const o0 = fs.readFileSync(destFile, 'utf8') + assert.strictEqual(o0, dat0, 'file contents matched') + assert(!fs.existsSync(srcFile)) +} + +function testSuccessDir (src, dest) { const srclen = klawSync(src).length // assert src has contents assert(srclen > 2)