Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbion committed Feb 13, 2024
1 parent f82393b commit bcff482
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
23 changes: 11 additions & 12 deletions src/utils/fileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ jest.mock('fs/promises', () => {

describe('getAbsolutePathInWorkspace', () => {
const testCases = [
// { 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: 'file', expected: '/my/workspace/file' },
{ workspace: 'C:\\my\\workspace', file: 'file', expected: 'C:\\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' },
];

testCases.forEach(({ workspace, file, expected }) => {
Expand All @@ -40,7 +40,6 @@ describe('getAbsolutePathInWorkspace', () => {
const result = getAbsolutePathInWorkspace(workspace, file);

// Then
console.info('result:', result);
expect(result).toBe(expected);
});
});
Expand Down
3 changes: 0 additions & 3 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ 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;
}
Expand Down

0 comments on commit bcff482

Please sign in to comment.