2021-05-21 15:17:21 +02:00
|
|
|
import FsDriverNode from './fs-driver-node';
|
|
|
|
import shim from './shim';
|
2021-08-12 17:54:10 +02:00
|
|
|
import { expectThrow } from './testing/test-utils';
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2020-10-23 14:21:37 +02:00
|
|
|
// On Windows, path.resolve is going to convert a path such as
|
|
|
|
// /tmp/file.txt to c:\tmp\file.txt
|
2020-11-12 21:13:28 +02:00
|
|
|
function platformPath(path: string) {
|
2020-10-23 14:21:37 +02:00
|
|
|
if (shim.isWindows()) {
|
2020-11-05 18:58:23 +02:00
|
|
|
return `c:${path.replace(/\//g, '\\')}`;
|
2020-10-23 14:21:37 +02:00
|
|
|
} else {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
describe('fsDriver', function() {
|
|
|
|
|
2021-08-12 17:54:10 +02:00
|
|
|
it('should resolveRelativePathWithinDir', async () => {
|
2020-10-21 01:23:55 +02:00
|
|
|
const fsDriver = new FsDriverNode();
|
2020-11-05 18:58:23 +02:00
|
|
|
expect(fsDriver.resolveRelativePathWithinDir('/test/temp', './my/file.txt').toLowerCase()).toBe(platformPath('/test/temp/my/file.txt'));
|
|
|
|
expect(fsDriver.resolveRelativePathWithinDir('/', './test').toLowerCase()).toBe(platformPath('/test'));
|
|
|
|
expect(fsDriver.resolveRelativePathWithinDir('/test', 'myfile.txt').toLowerCase()).toBe(platformPath('/test/myfile.txt'));
|
|
|
|
expect(fsDriver.resolveRelativePathWithinDir('/test/temp', './mydir/../test.txt').toLowerCase()).toBe(platformPath('/test/temp/test.txt'));
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2021-08-12 17:54:10 +02:00
|
|
|
await expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', '../myfile.txt'));
|
|
|
|
await expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', './mydir/../../test.txt'));
|
|
|
|
await expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', '/var/local/no.txt'));
|
2020-10-21 01:23:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|