Skip to content

Pester describe block "Run tests" and "Debug tests" do not run #1500

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

Closed
jchris1 opened this issue Aug 29, 2018 · 14 comments · Fixed by #1615
Closed

Pester describe block "Run tests" and "Debug tests" do not run #1500

jchris1 opened this issue Aug 29, 2018 · 14 comments · Fixed by #1615
Assignees

Comments

@jchris1
Copy link

jchris1 commented Aug 29, 2018

System Details

  • Operating system name and version:
    Windows 10 Enterprise
    Version 1709 (OS Build 16299.611)

  • VS Code version:
    Version: 1.26.1
    Commit: 493869ee8e8a846b0855873886fc79d480d342de
    Date: 2018-08-16T18:38:57.434Z
    Electron: 2.0.5
    Chrome: 61.0.3163.100
    Node.js: 8.9.3
    V8: 6.1.534.41
    Architecture: x64

  • PowerShell extension version: 1.8.3

PS C:\Users\jachris1> code -v
1.26.1
493869ee8e8a846b0855873886fc79d480d342de
x64
PS C:\Users\jachris1> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      8      3      0
PS C:\Users\jachris1> code --list-extensions --show-versions
[email protected]
[email protected]
ApplicationInsights:Sender [ { Error: connect ETIMEDOUT 64.4.54.254:443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
    code: 'ETIMEDOUT',
    errno: 'ETIMEDOUT',
    syscall: 'connect',
    address: '64.4.54.254',
    port: 443 } ]
PS C:\Users\jachris1> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.611
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.611
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with...
In Powershell Pester test scripts, both "Run tests" and "Debug tests" (above a Pester Describe block) give an error:
Running the contributed command:'PowerShell.RunPesterTests' failed.

Test script:

 Describe "test" {
    if (1)
    {
        it "test" {
            1 | Should Be 1
        }
    }
}

Attached Logs

Follow the instructions in the README
about capturing and sending logs.

EditorServices.log
vscode-powershell.log

@rjmholt
Copy link
Contributor

rjmholt commented Aug 29, 2018

Hi @jchris1, thanks for opening an issue. If you remove the if condition around the It clause, do the tests work?

@jchris1
Copy link
Author

jchris1 commented Aug 30, 2018

Hi,

Yes. I have the same error with this example test block:

Describe "test" {
    It {
        1 | Should Be 1
    }
}

@rjmholt
Copy link
Contributor

rjmholt commented Aug 30, 2018

Ah I've worked it out. This Pester test isn't valid because the It block needs a name. Try:

Describe "test" {
    It "my test" {
        1 | Should -Be 1
    }
}

The Pester CodeLens will only recognise valid Pester tests, since it can't run them otherwise.

Try that and let us know how it goes. I'd also be interested to know if re-instating the if block still works.

@jchris1
Copy link
Author

jchris1 commented Aug 31, 2018

I get the same behavior whether or not the It block has a name. In both cases, the clickable text ("Run tests" and "Debug tests") appears above the Describe block. And in both cases if I click "Run tests" or "Debug Tests", I get the error.

Describe "test" {
        it  {
            1 | Should Be 1
        }
}

Describe "test" {
    it "my test" {
        1 | Should Be 1
    }
}

Side note: If I remove the Describe name, then "Run tests" and "Debug Tests" disappear, so it does seem a Describe name is required to be recognized as a Pester test, but not an It test name. If I run these two tests using Invoke-Pester, I do get a Pester error for the top case without an It test name.

@TylerLeonhardt
Copy link
Member

It looks like you're using the older style of Pester asserts. Can you do 3 things:

  1. Can you invoke them manually with Invoke-Pester from the terminal?
  2. If you update the Should to Should -Be 1
  3. What version of Pester do you have?

@rjmholt
Copy link
Contributor

rjmholt commented Sep 2, 2018

@jchris1 Can you also paste any output (e.g. error output) you get from clicking on Run Tests?

@rjmholt
Copy link
Contributor

rjmholt commented Sep 4, 2018

I've tried this out on my machine now.

If I do:

Describe "tests" {
    It " test" {
        1 | Should Be 1
    }
}

or

Describe "tests" {
    if (1)
    {
        It " test" {
            1 | Should Be 1
        }
    }
}

I get an output like:

Executing all tests in '/home/rob/Documents/Dev/sandbox/脚本/file.tests.ps1' matching test name test

Executing script /home/rob/Documents/Dev/sandbox/脚本/file.tests.ps1

  Describing test
    [+] my test 100ms
Tests completed in 100ms
Tests Passed: 1, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0

If I don't provide the name of the test like

Describe "test" {
    It {
        1 | Should Be 1
    }
}

gives

Executing all tests in '/home/rob/Documents/Dev/sandbox/脚本/file.tests.ps1' matching test name test

Executing script /home/rob/Documents/Dev/sandbox/脚本/file.tests.ps1

  Describing test
    [-] Error occurred in Describe block 92ms
      RuntimeException: No test script block is provided. (Have you put the open curly brace on the next line?)
      at ItImpl, /home/rob/.local/share/powershell/Modules/Pester/4.4.0/Functions/It.ps1: line 153
      at It, /home/rob/.local/share/powershell/Modules/Pester/4.4.0/Functions/It.ps1: line 121
      at <ScriptBlock>, /home/rob/Documents/Dev/sandbox/脚本/file.tests.ps1: line 2
      at DescribeImpl, /home/rob/.local/share/powershell/Modules/Pester/4.4.0/Functions/Describe.ps1: line 171
Tests completed in 92ms
Tests Passed: 0, Failed: 1, Skipped: 0, Pending: 0, Inconclusive: 0

The it doesn't seem to be case-sensitive, but the Describe is -- which is likely a bug.

Also, the Pester lens only appears in files that end with .tests.ps1.

But so far I've been unable to reproduce the behaviour you're seeing @jchris1.

@jchris1
Copy link
Author

jchris1 commented Sep 4, 2018

Installed Pester version is 4.4.0

Using this test block saved as file.tests.ps1

Describe "tests" {
    It "test" {
        1 | Should Be 1
    }
}

I can manually run the test in the terminal:

PS C:\Users\jachris1\documents\Pestertest> invoke-pester ./file.tests.ps1   -TestName "tests"

Describing tests
 [+] test 41ms
Tests completed in 41ms
Passed: 1 Failed: 0 Skipped: 0 Pending: 0 Inconclusive: 0
PS C:\Users\jachris1\documents\Pestertest>

And like before, when I click "Run tests" or "Debug tests" I get the error:
Running the contributed command:'PowerShell.RunPesterTests' failed.

@TylerLeonhardt
Copy link
Member

Thanks for all your effort so far! With this new version, can you please attach the logs?

Before you do that can you set the log level to "Diagnostic":

"powershell.developer.editorServicesLogLevel": "Diagnostic"

@jchris1
Copy link
Author

jchris1 commented Sep 20, 2018

I clicked "Run Tests" and "Debug Tests" and got the same error. Here are the logs:

EditorServices.log
Start-EditorServices-EditorServices.log
vscode-powershell.log

@rjmholt
Copy link
Contributor

rjmholt commented Oct 10, 2018

Relevant section from the logs:

2018-09-20 11:25:43.021 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices\Components\FeatureComponentBase.cs: In method 'InvokeProviders', line 71:
    Invocation of provider 'Microsoft.PowerShell.EditorServices.CodeLenses.PesterCodeLensProvider' completed in 2ms.

2018-09-20 11:25:43.032 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 61:
    Writing Response 'textDocument/codeLens' with id 3

2018-09-20 11:25:43.033 [DIAGNOSTIC] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: In method 'WriteMessage', line 67:
    WRITE MESSAGE:
    
    {
      "jsonrpc": "2.0",
      "id": "3",
      "result": [
        {
          "range": {
            "start": {
              "line": 2,
              "character": 0
            },
            "end": {
              "line": 9,
              "character": 1
            }
          },
          "command": {
            "title": "Run tests",
            "command": "PowerShell.RunPesterTests",
            "arguments": [
              "file:///c%3A/temp/Untitled-1.Tests.ps1",
              false,
              "tests"
            ]
          },
          "data": {
            "uri": "file:///c%3A/temp/Untitled-1.Tests.ps1",
            "providerId": "Microsoft.PowerShell.EditorServices.CodeLenses.PesterCodeLensProvider"
          }
        },
        {
          "range": {
            "start": {
              "line": 2,
              "character": 0
            },
            "end": {
              "line": 9,
              "character": 1
            }
          },
          "command": {
            "title": "Debug tests",
            "command": "PowerShell.RunPesterTests",
            "arguments": [
              "file:///c%3A/temp/Untitled-1.Tests.ps1",
              true,
              "tests"
            ]
          },
          "data": {
            "uri": "file:///c%3A/temp/Untitled-1.Tests.ps1",
            "providerId": "Microsoft.PowerShell.EditorServices.CodeLenses.PesterCodeLensProvider"
          }
        }
      ]
    }

2018-09-20 11:25:43.223 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\Server\LanguageServer.cs: In method 'DelayThenInvokeDiagnostics', line 1526:
    Analyzing script file: c:\temp\Untitled-1.Tests.ps1

2018-09-20 11:25:45.238 [DIAGNOSTIC] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs: In method 'ReadMessage', line 114:
    READ MESSAGE:
    
    {
      "jsonrpc": "2.0",
      "id": 4,
      "method": "textDocument/hover",
      "params": {
        "textDocument": {
          "uri": "file:///c%3A/temp/Untitled-1.Tests.ps1"
        },
        "position": {
          "line": 2,
          "character": 5
        }
      }
    }

2018-09-20 11:25:45.238 [VERBOSE] C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs: In method 'ReadMessage', line 123:
    Received Request 'textDocument/hover' with id 4

The logs don't reveal much other than it looks like not a whole lot is happening. I'll see if I can look into this this week.

@rjmholt rjmholt self-assigned this Oct 10, 2018
@rjmholt rjmholt removed their assignment Oct 29, 2018
@rkeithhill rkeithhill self-assigned this Nov 18, 2018
rkeithhill added a commit that referenced this issue Nov 21, 2018
* Fix Pester CodeLens not working for running/debugging tests

Fixes #1500

* Single quote/escape script path passed in -Script param in dbg pester

Use same Pester output format that tasks use for user familiarity

* Remove unnecessary string interpolation.
@DarkLite1
Copy link

I'm experiencing similar issues. When clicking on Run tests or Debug tests above a Describe clause, nothing happens. You can find the screenshots in this post at the bottom.

Another thing of note can be that starting with Pester version 5 it is possible to use the -Focus swtich on a code block. That might improve the reliability of which test to run.

@TylerLeonhardt
Copy link
Member

This issue is fixed in master... Just pending a new release

@DarkLite1
Copy link

Thank you @TylerLeonhardt , we're currently using the insiders version. So we'll see it come in when it's ready. Thanks again for your help.

Version: 1.33.0-insider (user setup)
Commit: c1d001a915fe85cac93492393ea69fdb0c49ec0d
Date: 2019-03-13T06:18:20.237Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 6.2.9200

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 a pull request may close this issue.

5 participants