Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check case-insensitive paths to copySync, add tests for case-inse…
…nsitive paths
- Loading branch information
Showing
6 changed files
with
320 additions
and
54 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
lib/copy-sync/__tests__/copy-sync-case-insensitive-paths.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const os = require('os') | ||
const path = require('path') | ||
const fs = require(process.cwd()) | ||
|
||
/* global beforeEach, afterEach, describe, it */ | ||
|
||
describe('+ copySync() - case insensitive paths', () => { | ||
let TEST_DIR = '' | ||
let src = '' | ||
let dest = '' | ||
|
||
beforeEach(done => { | ||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-case-insensitive-paths') | ||
fs.emptyDir(TEST_DIR, done) | ||
}) | ||
|
||
afterEach(done => fs.remove(TEST_DIR, done)) | ||
|
||
describe('> when the source 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') | ||
|
||
try { | ||
fs.copySync(src, dest) | ||
} catch (err) { | ||
if (os === 'darwin' || os === 'win32') { | ||
assert.strictEqual(err.message, 'Source and destination must not be the same.') | ||
assert(fs.existsSync(src)) | ||
assert(!fs.existsSync(dest)) | ||
} | ||
} | ||
if (os === 'linux') { | ||
assert(fs.existsSync(dest)) | ||
assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data') | ||
} | ||
}) | ||
}) | ||
|
||
describe('> when the source 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') | ||
|
||
try { | ||
fs.copySync(src, dest) | ||
} catch (err) { | ||
if (os === 'darwin' || os === 'win32') { | ||
assert.strictEqual(err.message, 'Source and destination must not be the same.') | ||
assert(fs.existsSync(src)) | ||
assert(!fs.existsSync(dest)) | ||
} | ||
} | ||
if (os === 'linux') { | ||
assert(fs.existsSync(dest)) | ||
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data') | ||
} | ||
}) | ||
}) | ||
|
||
describe('> when the source 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') | ||
|
||
try { | ||
fs.copySync(src, dest) | ||
} catch (err) { | ||
if (os === 'darwin' || os === 'win32') { | ||
assert.strictEqual(err.message, 'Source and destination must not be the same.') | ||
assert(fs.existsSync(src)) | ||
assert(!fs.existsSync(dest)) | ||
} | ||
} | ||
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) | ||
} | ||
}) | ||
|
||
it('should behave correctly based on the OS, symlink file', () => { | ||
src = path.join(TEST_DIR, 'srcfile') | ||
fs.outputFileSync(src, 'some data') | ||
const srcLink = path.join(TEST_DIR, 'src-symlink') | ||
fs.symlinkSync(src, srcLink, 'file') | ||
dest = path.join(TEST_DIR, 'srcFile') | ||
|
||
try { | ||
fs.copySync(src, dest) | ||
} catch (err) { | ||
if (os === 'darwin' || os === 'win32') { | ||
assert.strictEqual(err.message, 'Source and destination must not be the same.') | ||
assert(fs.existsSync(src)) | ||
assert(!fs.existsSync(dest)) | ||
} | ||
} | ||
if (os === 'linux') { | ||
assert(fs.existsSync(dest)) | ||
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data') | ||
const link = fs.readlinkSync(srcLink) | ||
assert.strictEqual(link, dest) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.