-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support path auto-completion
- Loading branch information
Showing
15 changed files
with
564 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,8 @@ | |
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]", | ||
"@clack/[email protected]": "patches/@[email protected]" | ||
"@clack/[email protected]": "patches/@[email protected]", | ||
"@clack/[email protected]": "patches/@[email protected]" | ||
} | ||
}, | ||
"resolutions": { | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { expect, it } from 'vitest' | ||
import { pathCompletion } from '../src/path' | ||
|
||
const baseDir = __dirname | ||
|
||
interface CustomMatchers<R = unknown> { | ||
toBeSamePath(expected: R): R | ||
} | ||
|
||
declare module 'vitest' { | ||
interface Assertion<T = any> extends CustomMatchers<T> {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} | ||
} | ||
|
||
expect.extend({ | ||
// Check if the path is the same with automatic path separator conversion | ||
toBeSamePath: (received, expected) => { | ||
const receivedPath = received.replace(/\\/g, '/') | ||
const expectedPath = expected.replace(/\\/g, '/') | ||
const pass = receivedPath === expectedPath | ||
return { | ||
pass, | ||
message: () => `Expected ${receivedPath} ${pass ? 'not ' : ''}to be same path as ${expectedPath}`, | ||
actual: receivedPath, | ||
expected: expectedPath, | ||
} | ||
}, | ||
}) | ||
|
||
it('pathCompletion', () => { | ||
// expect(pathCompletion({ input: '', baseDir })).toBe('./folder/') | ||
expect(pathCompletion({ input: 'f', baseDir })).toBeSamePath('./folder/') | ||
expect(pathCompletion({ input: 'fold', baseDir })).toBeSamePath('./folder/') | ||
expect(pathCompletion({ input: 'folder', baseDir })).toBeSamePath('./folder/') | ||
expect(pathCompletion({ input: 'folder/', baseDir })).toBeSamePath('./folder/') | ||
expect(pathCompletion({ input: './folder', baseDir })).toBeSamePath('./folder/') | ||
expect(pathCompletion({ input: './folder/', baseDir })).toBeSamePath('./folder/') | ||
|
||
expect(pathCompletion({ input: 'folder/f', baseDir })).toBeSamePath('./folder/file1.js') | ||
expect(pathCompletion({ input: 'folder/file1', baseDir })).toBeSamePath('./folder/file1.js') | ||
expect(pathCompletion({ input: 'folder/file1.js', baseDir })).toBeSamePath('./folder/file1.js') | ||
expect(pathCompletion({ input: './folder/file1', baseDir })).toBeSamePath('./folder/file1.js') | ||
|
||
expect(pathCompletion({ input: 'folder/file12', baseDir })).toBeSamePath('./folder/file12.js') | ||
expect(pathCompletion({ input: 'folder/file12.js', baseDir })).toBeSamePath('./folder/file12.js') | ||
|
||
expect(pathCompletion({ input: 'folder/file123', baseDir })).toBeSamePath('./folder/file123.js') | ||
|
||
expect(pathCompletion({ input: 'folder/nested', baseDir })).toBeSamePath('./folder/nested/') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src" | ||
"src", | ||
"__tests__" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.