| 1 |
'use strict' |
| 2 |
|
| 3 |
const CWD = process.cwd() |
| 4 |
|
| 5 |
const fs = require('graceful-fs') |
| 6 |
const os = require('os') |
| 7 |
const fse = require(CWD) |
| 8 |
const path = require('path') |
| 9 |
const assert = require('assert') |
| 10 |
const _symlinkType = require('../symlink-type') |
| 11 |
const symlinkType = _symlinkType.symlinkType |
| 12 |
const symlinkTypeSync = _symlinkType.symlinkTypeSync |
| 13 |
const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure-symlink') |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
describe('symlink-type', () => { |
| 18 |
before(() => { |
| 19 |
fse.emptyDirSync(TEST_DIR) |
| 20 |
process.chdir(TEST_DIR) |
| 21 |
}) |
| 22 |
|
| 23 |
beforeEach(() => { |
| 24 |
fs.writeFileSync('./foo.txt', 'foo\n') |
| 25 |
fse.mkdirsSync('./empty-dir') |
| 26 |
fse.mkdirsSync('./dir-foo') |
| 27 |
fs.writeFileSync('./dir-foo/foo.txt', 'dir-foo\n') |
| 28 |
fse.mkdirsSync('./dir-bar') |
| 29 |
fs.writeFileSync('./dir-bar/bar.txt', 'dir-bar\n') |
| 30 |
fse.mkdirsSync('./real-alpha/real-beta/real-gamma') |
| 31 |
}) |
| 32 |
|
| 33 |
afterEach(done => fse.emptyDir(TEST_DIR, done)) |
| 34 |
|
| 35 |
after(() => { |
| 36 |
process.chdir(CWD) |
| 37 |
fse.removeSync(TEST_DIR) |
| 38 |
}) |
| 39 |
|
| 40 |
const tests = { |
| 41 |
success: [ |
| 42 |
|
| 43 |
|
| 44 |
[['./foo.txt'], 'file'], |
| 45 |
[['./empty-dir'], 'dir'], |
| 46 |
[['./dir-foo/foo.txt'], 'file'], |
| 47 |
[['./dir-bar'], 'dir'], |
| 48 |
[['./dir-bar/bar.txt'], 'file'], |
| 49 |
[['./real-alpha/real-beta/real-gamma'], 'dir'], |
| 50 |
|
| 51 |
[['./foo.txt', 'dir'], 'dir'], |
| 52 |
[['./empty-dir', 'dir'], 'dir'], |
| 53 |
[['./dir-foo/foo.txt', 'dir'], 'dir'], |
| 54 |
[['./dir-bar', 'dir'], 'dir'], |
| 55 |
[['./dir-bar/bar.txt', 'dir'], 'dir'], |
| 56 |
[['./real-alpha/real-beta/real-gamma', 'dir'], 'dir'], |
| 57 |
|
| 58 |
[['./foo.txt', 'file'], 'file'], |
| 59 |
[['./empty-dir', 'file'], 'file'], |
| 60 |
[['./dir-foo/foo.txt', 'file'], 'file'], |
| 61 |
[['./dir-bar', 'file'], 'file'], |
| 62 |
[['./dir-bar/bar.txt', 'file'], 'file'], |
| 63 |
[['./real-alpha/real-beta/real-gamma', 'file'], 'file'], |
| 64 |
|
| 65 |
[['./missing.txt'], 'file'], |
| 66 |
[['./missing'], 'file'], |
| 67 |
[['./missing.txt'], 'file'], |
| 68 |
[['./missing'], 'file'], |
| 69 |
[['./empty-dir/missing.txt'], 'file'], |
| 70 |
[['./empty-dir/missing'], 'file'], |
| 71 |
[['./empty-dir/missing.txt'], 'file'], |
| 72 |
[['./empty-dir/missing'], 'file'], |
| 73 |
|
| 74 |
[['./missing.txt', 'file'], 'file'], |
| 75 |
[['./missing', 'file'], 'file'], |
| 76 |
[['./missing.txt', 'file'], 'file'], |
| 77 |
[['./missing', 'file'], 'file'], |
| 78 |
[['./empty-dir/missing.txt', 'file'], 'file'], |
| 79 |
[['./empty-dir/missing', 'file'], 'file'], |
| 80 |
[['./empty-dir/missing.txt', 'file'], 'file'], |
| 81 |
[['./empty-dir/missing', 'file'], 'file'], |
| 82 |
|
| 83 |
[['./missing.txt', 'dir'], 'dir'], |
| 84 |
[['./missing', 'dir'], 'dir'], |
| 85 |
[['./missing.txt', 'dir'], 'dir'], |
| 86 |
[['./missing', 'dir'], 'dir'], |
| 87 |
[['./empty-dir/missing.txt', 'dir'], 'dir'], |
| 88 |
[['./empty-dir/missing', 'dir'], 'dir'], |
| 89 |
[['./empty-dir/missing.txt', 'dir'], 'dir'], |
| 90 |
[['./empty-dir/missing', 'dir'], 'dir'] |
| 91 |
] |
| 92 |
} |
| 93 |
|
| 94 |
describe('symlinkType()', () => { |
| 95 |
tests.success.forEach(test => { |
| 96 |
const args = test[0].slice(0) |
| 97 |
const expectedType = test[1] |
| 98 |
it(`should return '${expectedType}' when src '${args[0]}'`, done => { |
| 99 |
const callback = (err, type) => { |
| 100 |
if (err) done(err) |
| 101 |
assert.strictEqual(type, expectedType) |
| 102 |
done() |
| 103 |
} |
| 104 |
args.push(callback) |
| 105 |
return symlinkType(...args) |
| 106 |
}) |
| 107 |
}) |
| 108 |
}) |
| 109 |
|
| 110 |
describe('symlinkTypeSync()', () => { |
| 111 |
tests.success.forEach(test => { |
| 112 |
const args = test[0] |
| 113 |
const expectedType = test[1] |
| 114 |
it(`should return '${expectedType}' when src '${args[0]}'`, () => { |
| 115 |
const type = symlinkTypeSync(...args) |
| 116 |
assert.strictEqual(type, expectedType) |
| 117 |
}) |
| 118 |
}) |
| 119 |
}) |
| 120 |
}) |