Skip to content

Commit

Permalink
make sure copySync throws error on osx and windows
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Apr 18, 2018
1 parent 662f139 commit cf64041
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
22 changes: 19 additions & 3 deletions lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js
Expand Up @@ -19,11 +19,12 @@ describe('+ copySync() - case insensitive paths', () => {

afterEach(done => fs.remove(TEST_DIR, done))

describe('> when the source is a directory', () => {
describe('> when src is a directory', () => {
it('should behave correctly based on the OS', () => {
src = path.join(TEST_DIR, 'srcdir')
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
dest = path.join(TEST_DIR, 'srcDir')
let errThrown = false

try {
fs.copySync(src, dest)
Expand All @@ -32,20 +33,24 @@ describe('+ copySync() - case insensitive paths', () => {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
assert(!errThrown)
}
})
})

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
it('should behave correctly based on the OS', () => {
src = path.join(TEST_DIR, 'srcfile')
fs.outputFileSync(src, 'some data')
dest = path.join(TEST_DIR, 'srcFile')
let errThrown = false

try {
fs.copySync(src, dest)
Expand All @@ -54,22 +59,26 @@ describe('+ copySync() - case insensitive paths', () => {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
assert(!errThrown)
}
})
})

describe('> when the source is a symlink', () => {
describe('> when src is a symlink', () => {
it('should behave correctly based on the OS, symlink dir', () => {
src = path.join(TEST_DIR, 'srcdir')
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
const srcLink = path.join(TEST_DIR, 'src-symlink')
fs.symlinkSync(src, srcLink, 'dir')
dest = path.join(TEST_DIR, 'srcDir')
let errThrown = false

try {
fs.copySync(src, dest)
Expand All @@ -78,13 +87,16 @@ describe('+ copySync() - case insensitive paths', () => {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')
const link = fs.readlinkSync(srcLink)
assert.strictEqual(link, dest)
assert(!errThrown)
}
})

Expand All @@ -94,6 +106,7 @@ describe('+ copySync() - case insensitive paths', () => {
const srcLink = path.join(TEST_DIR, 'src-symlink')
fs.symlinkSync(src, srcLink, 'file')
dest = path.join(TEST_DIR, 'srcFile')
let errThrown = false

try {
fs.copySync(src, dest)
Expand All @@ -102,13 +115,16 @@ describe('+ copySync() - case insensitive paths', () => {
assert.strictEqual(err.message, 'Source and destination must not be the same.')
assert(fs.existsSync(src))
assert(!fs.existsSync(dest))
errThrown = true
}
}
if (os === 'darwin' || os === 'win32') assert(errThrown)
if (os === 'linux') {
assert(fs.existsSync(dest))
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')
const link = fs.readlinkSync(srcLink)
assert.strictEqual(link, dest)
assert(!errThrown)
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion lib/copy-sync/__tests__/copy-sync-dir.test.js
Expand Up @@ -20,7 +20,7 @@ describe('+ copySync()', () => {
fs.emptyDir(TEST_DIR, done)
})

describe('> when the source is a directory', () => {
describe('> when src is a directory', () => {
describe('> when dest exists and is a file', () => {
it('should throw error', () => {
const src = path.join(TEST_DIR, 'src')
Expand Down
4 changes: 2 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-file.test.js
Expand Up @@ -20,7 +20,7 @@ describe('+ copySync()', () => {

afterEach(done => fs.remove(TEST_DIR, done))

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
it('should copy the file synchronously', () => {
const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')
const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('+ copySync()', () => {
})
})

describe('> when the source file does not have write permissions', () => {
describe('> when src file does not have write permissions', () => {
it('should be able to copy contents of file', () => {
const fileSrc = path.join(TEST_DIR, 'file.txt')
const fileDest = path.join(TEST_DIR, 'file-copy.txt')
Expand Down
Expand Up @@ -35,7 +35,7 @@ describe('+ copySync() - prevent copying identical files and dirs', () => {
// src is symlink, dest is regular
// src is symlink, dest is symlink

describe('> when the source is a directory', () => {
describe('> when src is a directory', () => {
describe(`>> when src is regular and dest is a symlink that points to src`, () => {
it('should error', () => {
src = path.join(TEST_DIR, 'src')
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('+ copySync() - prevent copying identical files and dirs', () => {
// src is symlink, dest is regular
// src is symlink, dest is symlink

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
describe(`>> when src is regular and dest is a symlink that points to src`, () => {
it('should error', () => {
src = path.join(TEST_DIR, 'src', 'somefile.txt')
Expand Down
6 changes: 3 additions & 3 deletions lib/copy/__tests__/copy-case-insensitive-paths.test.js
Expand Up @@ -19,7 +19,7 @@ describe('+ copy() - case insensitive paths', () => {

afterEach(done => fs.remove(TEST_DIR, done))

describe('> when the source is a directory', () => {
describe('> when src is a directory', () => {
it('should behave correctly based on the OS', done => {
src = path.join(TEST_DIR, 'srcdir')
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
Expand All @@ -41,7 +41,7 @@ describe('+ copy() - case insensitive paths', () => {
})
})

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
it('should behave correctly based on the OS', done => {
src = path.join(TEST_DIR, 'srcfile')
fs.outputFileSync(src, 'some data')
Expand All @@ -63,7 +63,7 @@ describe('+ copy() - case insensitive paths', () => {
})
})

describe('> when the source is a symlink', () => {
describe('> when src is a symlink', () => {
it('should behave correctly based on the OS, symlink dir', done => {
src = path.join(TEST_DIR, 'srcdir')
fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')
Expand Down
4 changes: 2 additions & 2 deletions lib/copy/__tests__/copy-prevent-copying-identical.test.js
Expand Up @@ -35,7 +35,7 @@ describe('+ copy() - prevent copying identical files and dirs', () => {
// src is symlink, dest is regular
// src is symlink, dest is symlink

describe('> when the source is a directory', () => {
describe('> when src is a directory', () => {
describe(`>> when src is regular and dest is a symlink that points to src`, () => {
it('should error', done => {
src = path.join(TEST_DIR, 'src')
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('+ copy() - prevent copying identical files and dirs', () => {
// src is symlink, dest is regular
// src is symlink, dest is symlink

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
describe(`>> when src is regular and dest is a symlink that points to src`, () => {
it('should error', done => {
src = path.join(TEST_DIR, 'src', 'somefile.txt')
Expand Down
8 changes: 4 additions & 4 deletions lib/copy/__tests__/copy.test.js
Expand Up @@ -54,7 +54,7 @@ describe('fs-extra', () => {
})
})

describe('> when the source is a file', () => {
describe('> when src is a file', () => {
it('should copy the file asynchronously', done => {
const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')
const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')
Expand All @@ -70,7 +70,7 @@ describe('fs-extra', () => {
})
})

it('should return an error if the source file does not exist', done => {
it('should return an error if src file does not exist', done => {
const fileSrc = 'we-simply-assume-this-file-does-not-exist.bin'
const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')

Expand Down Expand Up @@ -110,8 +110,8 @@ describe('fs-extra', () => {
})
})

describe('> when the source is a directory', () => {
describe('> when the source directory does not exist', () => {
describe('> when src is a directory', () => {
describe('> when src directory does not exist', () => {
it('should return an error', done => {
const ts = path.join(TEST_DIR, 'this_dir_does_not_exist')
const td = path.join(TEST_DIR, 'this_dir_really_does_not_matter')
Expand Down

0 comments on commit cf64041

Please sign in to comment.