一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
40 行
2.2 KiB
TypeScript
40 行
2.2 KiB
TypeScript
import { posix, win32 } from 'node:path';
|
|
import resolvePathWithinDir from './resolvePathWithinDir';
|
|
|
|
describe('resolvePathWithinDir', () => {
|
|
test('should return correct values for Unix-style paths', () => {
|
|
const testCases = [
|
|
// Absolute paths
|
|
{ baseDir: '/a/test/path/', path: '/a/test/path/test.txt', expected: '/a/test/path/test.txt' },
|
|
{ baseDir: '/a/test/path/', path: '/a/test/path/..test.txt', expected: '/a/test/path/..test.txt' },
|
|
{ baseDir: '/a/test/path/', path: '/a/test/path/.test.txt', expected: '/a/test/path/.test.txt' },
|
|
{ baseDir: '/a/test/path', path: '/a/test/path/.test.txt', expected: '/a/test/path/.test.txt' },
|
|
{ baseDir: '/a/test/path', path: '/a/test/path', expected: '/a/test/path' },
|
|
{ baseDir: '/a/test/path', path: '/a/', expected: null },
|
|
{ baseDir: '/a/test/path', path: '/a/test/', expected: null },
|
|
{ baseDir: '/a/test/path', path: '/a/test/pa', expected: null },
|
|
{ baseDir: '/a/test/path', path: '/a/test/path2', expected: null },
|
|
{ baseDir: '/a/test/path', path: '/a/test/path\\//subdir', expected: null },
|
|
|
|
// Relative paths
|
|
{ baseDir: '/a/test/path', path: './test', expected: '/a/test/path/test' },
|
|
{ baseDir: '/a/test/path', path: '../path/test/2', expected: '/a/test/path/test/2' },
|
|
{ baseDir: '/a/test/path', path: '../path/test/../../../2', expected: null },
|
|
{ baseDir: '/a/test/path', path: '../test', expected: null },
|
|
];
|
|
|
|
for (const testCase of testCases) {
|
|
expect(resolvePathWithinDir(testCase.baseDir, testCase.path, posix)).toBe(testCase.expected);
|
|
}
|
|
});
|
|
|
|
test('should return correct values for Windows-style paths', () => {
|
|
expect(resolvePathWithinDir('C:\\a\\test\\path', 'C:\\a\\test\\path\\2', win32)).toBe('C:\\a\\test\\path\\2');
|
|
expect(resolvePathWithinDir('C:\\\\a\\test\\path', '.\\path\\2', win32)).toBe('C:\\a\\test\\path\\path\\2');
|
|
expect(resolvePathWithinDir('C:\\a\\test\\path', '..\\path\\2', win32)).toBe('C:\\a\\test\\path\\2');
|
|
expect(resolvePathWithinDir('C:\\a\\test\\path', '..\\2', win32)).toBe(null);
|
|
expect(resolvePathWithinDir('D:\\a\\test\\path', 'C:\\a\\test\\path\\2', win32)).toBe(null);
|
|
expect(resolvePathWithinDir('\\a\\test\\path', 'D:\\a\\test\\path\\2', win32)).toBe(null);
|
|
});
|
|
});
|