2020-11-07 17:59:37 +02:00
|
|
|
import FsDriverNode from '@joplin/lib/fs-driver-node';
|
|
|
|
import shim from '@joplin/lib/shim';
|
2020-11-05 18:58:23 +02:00
|
|
|
const { expectThrow } = require('./test-utils.js');
|
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() {
|
|
|
|
|
|
|
|
it('should resolveRelativePathWithinDir', () => {
|
|
|
|
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
|
|
|
|
|
|
|
expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', '../myfile.txt'));
|
|
|
|
expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', './mydir/../../test.txt'));
|
|
|
|
expectThrow(() => fsDriver.resolveRelativePathWithinDir('/test/temp', '/var/local/no.txt'));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|