|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const assert = require('assert') |
| 4 | +const fs = require('../lib/wrapped-fs') |
| 5 | +const path = require('path') |
| 6 | +const rimraf = require('rimraf') |
| 7 | + |
| 8 | +const Filesystem = require('../lib/filesystem') |
| 9 | + |
| 10 | +describe('filesystem', function () { |
| 11 | + beforeEach(() => { rimraf.sync(path.join(__dirname, '..', 'tmp'), fs) }) |
| 12 | + |
| 13 | + it('should does not throw an error when the src path includes a symbol link', async () => { |
| 14 | + /** |
| 15 | + * Directory structure: |
| 16 | + * tmp |
| 17 | + * ├── private |
| 18 | + * │ └── var |
| 19 | + * │ ├── app |
| 20 | + * │ │ └── file.txt -> ../file.txt |
| 21 | + * │ └── file.txt |
| 22 | + * └── var -> private/var |
| 23 | + */ |
| 24 | + const tmpPath = path.join(__dirname, '..', 'tmp') |
| 25 | + const privateVarPath = path.join(tmpPath, 'private', 'var') |
| 26 | + const varPath = path.join(tmpPath, 'var') |
| 27 | + fs.mkdirSync(privateVarPath, { recursive: true }) |
| 28 | + fs.symlinkSync(path.relative(tmpPath, privateVarPath), varPath) |
| 29 | + |
| 30 | + const originFilePath = path.join(varPath, 'file.txt') |
| 31 | + fs.writeFileSync(originFilePath, 'hello world') |
| 32 | + const appPath = path.join(varPath, 'app') |
| 33 | + fs.mkdirpSync(appPath) |
| 34 | + fs.symlinkSync('../file.txt', path.join(appPath, 'file.txt')) |
| 35 | + |
| 36 | + const filesystem = new Filesystem(varPath) |
| 37 | + assert.doesNotThrow(() => { |
| 38 | + filesystem.insertLink(path.join(appPath, 'file.txt')) |
| 39 | + }) |
| 40 | + }) |
| 41 | +}) |
0 commit comments