From f82393bfbcd53209f3f88d87b4fe0f3995f2c579 Mon Sep 17 00:00:00 2001 From: nalbion Date: Tue, 13 Feb 2024 18:05:16 +1100 Subject: [PATCH] debugging test --- src/utils/fileUtils.test.ts | 22 +++++++++++----------- src/utils/fileUtils.ts | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/utils/fileUtils.test.ts b/src/utils/fileUtils.test.ts index fa2b4fa..fbaba4d 100644 --- a/src/utils/fileUtils.test.ts +++ b/src/utils/fileUtils.test.ts @@ -21,17 +21,17 @@ jest.mock('fs/promises', () => { describe('getAbsolutePathInWorkspace', () => { const testCases = [ - { workspace: '/my/workspace', file: 'file', expected: '/my/workspace/file' }, + // { workspace: '/my/workspace', file: 'file', expected: '/my/workspace/file' }, { workspace: 'C:\\my\\workspace', file: 'file', expected: '/my/workspace/file' }, - { workspace: '/my/workspace', file: '.env', expected: '/my/workspace/.env' }, - { workspace: '/my/workspace', file: './file', expected: '/my/workspace/file' }, - { workspace: '/my/workspace', file: 'path/to/file', expected: '/my/workspace/path/to/file' }, - { workspace: '/my/workspace', file: '../path/../../../to/file', expected: '/my/workspace/path/to/file' }, - { workspace: '/my/workspace', file: './path/to my/file', expected: '/my/workspace/path/to my/file' }, - { workspace: '/my/workspace', file: '~/file', expected: '/my/workspace/home/file' }, - { workspace: '/my/workspace', file: '~/path/to/file', expected: '/my/workspace/home/path/to/file' }, - { workspace: '/my/workspace', file: '/temp/path/to/file', expected: '/my/workspace/root/temp/path/to/file' }, - { workspace: '/my/workspace', file: 'C:\\temp\\path\\to\\file', expected: '/my/workspace/root/temp/path/to/file' }, + // { workspace: '/my/workspace', file: '.env', expected: '/my/workspace/.env' }, + // { workspace: '/my/workspace', file: './file', expected: '/my/workspace/file' }, + // { workspace: '/my/workspace', file: 'path/to/file', expected: '/my/workspace/path/to/file' }, + // { workspace: '/my/workspace', file: '../path/../../../to/file', expected: '/my/workspace/path/to/file' }, + // { workspace: '/my/workspace', file: './path/to my/file', expected: '/my/workspace/path/to my/file' }, + // { workspace: '/my/workspace', file: '~/file', expected: '/my/workspace/home/file' }, + // { workspace: '/my/workspace', file: '~/path/to/file', expected: '/my/workspace/home/path/to/file' }, + // { workspace: '/my/workspace', file: '/temp/path/to/file', expected: '/my/workspace/root/temp/path/to/file' }, + // { workspace: '/my/workspace', file: 'C:\\temp\\path\\to\\file', expected: '/my/workspace/root/temp/path/to/file' }, ]; testCases.forEach(({ workspace, file, expected }) => { @@ -41,7 +41,7 @@ describe('getAbsolutePathInWorkspace', () => { // Then console.info('result:', result); - expect(result.replaceAll('\\', '/').replace(/^[A-Z]:/, '')).toBe(expected); + expect(result).toBe(expected); }); }); }); diff --git a/src/utils/fileUtils.ts b/src/utils/fileUtils.ts index faece2c..4ee566f 100644 --- a/src/utils/fileUtils.ts +++ b/src/utils/fileUtils.ts @@ -23,10 +23,13 @@ export function getAbsolutePathInWorkspace(workspaceFolder: string, filePath: st } else if (filePath.startsWith('/')) { filePath = 'root' + filePath; } else { + console.info('filepath 4:', filePath); filePath = filePath.replace(/^[A-Za-z]:/, 'root'); } + console.info('resolveed path:', workspaceFolder, filePath); let absolutePath = path.resolve(workspaceFolder, filePath); + console.info('absolutePath:', absolutePath); return absolutePath; }