Skip to content

Commit

Permalink
test(formatPathLabel): improve workspace folder handling tests
Browse files Browse the repository at this point in the history
- Refactored existing tests to enhance clarity and specificity in naming.
- Added tests for handling single workspace folders, no workspace folders, and toggling workspace folder visibility in file paths.
- Improved assertions for paths outside workspace folders and multiple workspace folders, ensuring accurate behavior of the formatPathLabel function.
- These changes enhance the robustness and maintainability of the test suite for path formatting functionality.
  • Loading branch information
joshmu committed Dec 26, 2024
1 parent 7db7c4d commit eda0efc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/test/suite/formatPathLabel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ suite('formatPathLabel Tests', () => {
});

suite('Workspace Folder Handling', () => {
test('returns original path when no workspace folders exist', () => {
workspaceFoldersStub.get(() => undefined);
const testPath = '/some/test/path/file.ts';
assert.strictEqual(formatPathLabel(testPath), testPath);
});

test('includes workspace folder name when showWorkspaceFolderInFilePath is true', () => {
test('handles single workspace folder', () => {
const testPath = '/test/workspace/src/utils/file.ts';
const expected = path.join('workspace', 'src', 'utils', 'file.ts');
assert.strictEqual(formatPathLabel(testPath), expected);
});

test('excludes workspace folder name when showWorkspaceFolderInFilePath is false', () => {
test('handles no workspace folder', () => {
workspaceFoldersStub.get(() => undefined);
const testPath = '/some/test/path/file.ts';
assert.strictEqual(formatPathLabel(testPath), testPath);
});

test('handles workspace folder name toggle', () => {
getConfigStub.returns({ ...defaultConfig, showWorkspaceFolderInFilePath: false });
const testPath = '/test/workspace/src/utils/file.ts';
const expected = path.join('workspace', 'src', 'utils', 'file.ts');
assert.strictEqual(formatPathLabel(testPath), expected);
});

test('handles paths outside workspace folder by using first workspace as fallback', () => {
test('handles file outside workspace folder', () => {
const testPath = '/different/workspace/src/file.ts';
const expected = path.join('workspace', '...', 'different', 'workspace', 'src', 'file.ts');
assert.strictEqual(formatPathLabel(testPath), expected);
});

test('handles multiple workspace folders by using correct workspace', () => {
test('handles multiple workspace folders', () => {
workspaceFoldersStub.get(
() =>
[
Expand Down

0 comments on commit eda0efc

Please sign in to comment.