diff --git a/test/filesystem-spec.js b/test/filesystem-spec.js index 316e6b5..a2b4c7a 100644 --- a/test/filesystem-spec.js +++ b/test/filesystem-spec.js @@ -1,16 +1,42 @@ 'use strict' const assert = require('assert') +const fs = require('../lib/wrapped-fs') const path = require('path') +const rimraf = require('rimraf') const Filesystem = require('../lib/filesystem') describe('filesystem', function () { + beforeEach(() => { rimraf.sync(path.join(__dirname, '..', 'tmp'), fs) }) + it('should does not throw error when src path include symbol link', async () => { - const src = path.join(__dirname, 'input', 'srcpath-include-symlink', 'var', 'app') - const filesystem = new Filesystem(src) + /* eslint-disable no-irregular-whitespace */ + /** + * Directory structure: + * tmp + * ├── private + * │   └── var + * │   ├── app + * │   │   └── file.txt -> ../file.txt + * │   └── file.txt + * └── var -> private/var + */ + const tmpPath = path.join(__dirname, '..', 'tmp') + const privateVarPath = path.join(tmpPath, 'private', 'var') + const varPath = path.join(tmpPath, 'var') + fs.mkdirSync(privateVarPath, { recursive: true }) + fs.symlinkSync(path.relative(tmpPath, privateVarPath), varPath) + + const originFilePath = path.join(varPath, 'file.txt') + fs.writeFileSync(originFilePath, 'hello world') + const appPath = path.join(varPath, 'app') + fs.mkdirpSync(appPath) + fs.symlinkSync('../file.txt', path.join(appPath, 'file.txt')) + + const filesystem = new Filesystem(varPath) assert.doesNotThrow(() => { - filesystem.insertLink(path.join(src, 'symbol', 'real.txt')) + filesystem.insertLink(path.join(appPath, 'file.txt')) }) }) }) diff --git a/test/input/srcpath-include-symlink/private/var/app/real.txt b/test/input/srcpath-include-symlink/private/var/app/real.txt deleted file mode 100644 index e69de29..0000000 diff --git a/test/input/srcpath-include-symlink/private/var/app/symbol/real.txt b/test/input/srcpath-include-symlink/private/var/app/symbol/real.txt deleted file mode 120000 index 5099602..0000000 --- a/test/input/srcpath-include-symlink/private/var/app/symbol/real.txt +++ /dev/null @@ -1 +0,0 @@ -../real.txt \ No newline at end of file diff --git a/test/input/srcpath-include-symlink/var b/test/input/srcpath-include-symlink/var deleted file mode 120000 index 3ec7299..0000000 --- a/test/input/srcpath-include-symlink/var +++ /dev/null @@ -1 +0,0 @@ -private/var \ No newline at end of file