Skip to content
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 'Run/Debug Pester tests' command and file tab menu #1698

Merged
merged 6 commits into from
Jan 17, 2019

Conversation

bergmeister
Copy link
Contributor

@bergmeister bergmeister commented Jan 13, 2019

PR Summary

Implements #1667 by adding a command and file tab menu to run all Pester tests on a file. The file tab menu will only appear for .tests.ps1 files (using a case insensitive comparison).
I tested this on Windows 1809 using vscode and the latest vscode-insiders when using Windows PowerShell 5.1. I also made sure that the code lens being used by PSES does not get broken, hence why new commands were added rather than trying to adapt for the different kind of uri in the launchTests function. Here is a zip of my locally built vsix for testing: PowerShell-insiders.zip

New file tab menu entries:
image
Commands:
image

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

package.json Outdated
@@ -233,6 +238,12 @@
"group": "2_powershell"
}
],
"editor/title/context": [
{
"when": "resourceExtname == .ps1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work:

"when":  "resourceFilename =~ /\.[Tt]ests\.ps1$/"

Copy link
Contributor Author

@bergmeister bergmeister Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I had to escape the backslash in JSON and then your suggestion worked: "resourceFilename =~ /\\.[Tt]ests\\.ps1$/"
The PR is now ready for review :)

@bergmeister bergmeister changed the title WIP Add 'Run Pester tests' command and file tab menu Add 'Run Pester tests' command and file tab menu Jan 14, 2019
Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thinking a bit on the case-insensitivity - maybe it would be better to use /\\.tests\\.ps1$/i?

@rkeithhill
Copy link
Contributor

rkeithhill commented Jan 14, 2019

You know, we could also add a PowerShell.DebugPesterTests or PowerShell.DebugPesterTestsFile command.

@bergmeister
Copy link
Contributor Author

@rkeithhill Thanks for the tip with the completely case insensitive comparison for the tests.ps1 file extension, I tested it and it works :)
Yes, I was thinking about adding a Debug Pester tests command/menu as well and when I was testing it again, I realised that the current implementation is actually Debug Pester tests due to the defaults in PesterTests.ts. I guess I'll have to pass in args but maybe the command should rather be split I guess? I'll therefore make it WIP again

@bergmeister bergmeister changed the title Add 'Run Pester tests' command and file tab menu WIP Add 'Run Pester tests' command and file tab menu Jan 14, 2019
@bergmeister bergmeister changed the title WIP Add 'Run Pester tests' command and file tab menu WIP Add 'Run/Debug Pester tests' command and file tab menu Jan 14, 2019
@rkeithhill
Copy link
Contributor

Just as with your original post, I was thinking that we could have two functions RunPesterTestsFile() and DebugPesterTestsFile() that internally called RunPesterTests with the appropriate arguments. Then we'd need to register those commands in the PesterTests.ps1 file.

@bergmeister
Copy link
Contributor Author

bergmeister commented Jan 14, 2019

Yes, I was even thinking of just changing to make RunPesterTests just run the tests without the debugger and create a new function DebugPesterTests (internally both would lookup the file name if it is null and use the common launchTests function), this way we can avoid creating an additional layer of wrapping that is not necessary. The downside of that is that it requires a change in PSES which calls into RunPesterTests at the moment. Give me a bit more time to play with this but having a WIP has definitely helped to discuss the issues and possible solutions together :)

@rkeithhill
Copy link
Contributor

Keep in mind that we are sharing this command with the code lens request message we get from PSES.

@bergmeister bergmeister changed the title WIP Add 'Run/Debug Pester tests' command and file tab menu Add 'Run/Debug Pester tests' command and file tab menu Jan 16, 2019
@bergmeister
Copy link
Contributor Author

bergmeister commented Jan 16, 2019

@rkeithhill Yes, after playing a bit with it, it turned out to be easier to add new commands as you suggested instead of trying to correct the uri logic inside launchTests. I also added support for Debug Pester tests and made sure that Run Pester tests does not attach the debugger any more. The PR is now ready for review again and I updated the description

this.command = vscode.commands.registerCommand(
"PowerShell.RunPesterTestsFromFile",
(uriString, runInDebugger, describeBlockName?) => {
this.launchTests(vscode.window.activeTextEditor.document.uri, false, describeBlockName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth documenting the true and false somehow? I assume it's "start debugger" or similar?

Copy link
Contributor Author

@bergmeister bergmeister Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the runInDebugger parameter, which is defined on launchTests, isn't that sufficient/self-documenting? I simplified and minimised the lambda expression, maybe it is clearer now? As far as I've seen, TypeScript does not support named parameters.

@@ -17,13 +17,13 @@ export class PesterTestsFeature implements IFeature {
constructor(private sessionManager: SessionManager) {
this.command = vscode.commands.registerCommand(
"PowerShell.RunPesterTestsFromFile",
(uriString, runInDebugger, describeBlockName?) => {
this.launchTests(vscode.window.activeTextEditor.document.uri, false, describeBlockName);
() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was just going to suggest this but see you've already done it. :-)

@rkeithhill rkeithhill merged commit 68b373f into PowerShell:master Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants