-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests for terminal suggest widget, fix some bugs #234445
base: main
Are you sure you want to change the base?
Conversation
meganrogge
commented
Nov 22, 2024
•
edited
Loading
edited
Actually wip realized something |
}); | ||
}); | ||
|
||
function createTestCase(name: string, commandLineWithCursor: string, expectedSpecs: string[], resourcesRequested: 'files' | 'folders' | 'both' | 'neither', availableSpecs: Fig.Spec[], availableCommands: Set<string>): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you move this inside suite
you'll be able to access variables you declare in that block. This lets you do things like this:
let commands: string[]
setup(() => {
commands = ['default', 'set', ...];
});
function assertCompletions() {
// references commands
}
test(() => {
commands = ['custom test commands'];
});
}); | ||
|
||
suite('prefix: c', () => { | ||
createTestCase(`No available commands:`, 'c|', [], 'neither', availableSpecs, new Set()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd only generate tests inside a function like this if they originate from some array of specifications which is sometimes useful. Pulling the test
call out will make integration with IDEs better and make them easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there will be quite a bit of duplication if I do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not sure what you mean about integration with other IDEs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do want to keep it this way though, you should put all the test specifics into an array and create them that way:
Instead of:
createTestCase('|', availableCommands, 'neither', availableSpecs);
createTestCase('c|', availableCommands, 'neither', availableSpecs);
...
Do:
const testSpecs: [my, type, ...] = [
['|', availableCommands, 'neither', availableSpecs]
];
// or
const testSpecs = [
{ input: '|', expectedCompletionLabels: 'files' | 'folders' | 'both' | 'neither', resourcesRequested: 'neither', availableSpecs }
];
for (const spec of testSpecs) {
test(testSpecs.name, () => {
// use spec to implement the test
});
}
This saves more of the repetitive writing. This is similar to terminal link tests:
vscode/src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts
Lines 163 to 172 in 6070da4
suite('removeLinkSuffix', () => { | |
for (const testLink of testLinks) { | |
test('`' + testLink.link + '`', () => { | |
deepStrictEqual( | |
removeLinkSuffix(testLink.link), | |
testLink.suffix === undefined ? testLink.link : testLink.link.replace(testLink.suffix, '') | |
); | |
}); | |
} | |
}); |
createTestCase('code-insiders --locale | && ls', ['bg', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pt-br', 'ru', 'tr', 'zh-CN', 'zh-TW'], 'neither', availableSpecs); | ||
}); | ||
|
||
function createTestCase(commandLineWithCursor: string, expectedCompletionLabels: string[], resourcesRequested: 'files' | 'folders' | 'both' | 'neither', availableSpecs: Fig.Spec[]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best to stick expected as the last arg