1

I would like to run all Pester Unit tests locally for a project before pushing my changes back up to GitHub and initializing a Pull Request.

So far I've cloned a project, xFailOverCluster, and installed Pester and all dependent modules (found using the build-script).

  • Pester 5.3.1
  • .\build.ps1 -Tasks build
    • Sampler.GitHubTasks
    • Saved DscResources.Common to \output\RequiredModules
  • .\build.ps1
    • DscResource.Test
      • DscResource.Analyzer
      • DscxDSCResourceDesigner
      • PSPKI
  • DscResources.Common

I can successfully build the module, using the provided .\build.ps1 script. But the provided Pester Unit tests will all fail.

And when using the more generic Pester Test Explorer extension in VS Code, I get the same kind of failures:

Starting discovery in 7 files.
[-] Discovery in D:\UsbRepos\One\xFailOverCluster.GitHub\tests\Unit\MSFT_xCluster.Tests.ps1 failed with: System.IO.FileNotFoundException: The specified module 'xFailOverCluster' was not loaded because no valid module file was found in any module directory.
...
Discovery found 0 tests in 643ms.
...

Dennis
  • 871
  • 9
  • 29
  • Ok, so I got to thinking the `DscResources.Common` is also a module and installed that and then deleted the folder I created earlier... – Dennis Sep 23 '21 at 19:33
  • 1
    The best place to ask is on the issues page of the GitHub repo you cloned it from. The authors and existing contributors of the project are the most qualified to help you. – Daniel Mann Sep 23 '21 at 19:34
  • Yes, but surely this is a more generic issue? The VS Code Extension is only looking for available Unit tests and don't care about build scripts... – Dennis Sep 23 '21 at 19:38
  • Try using Pester 4.10.1 instead. There were some breaking changes in v5 that may be causing this for you. – Daniel Sep 24 '21 at 02:31
  • The `Pester Tester Extension` requires Pester 5.x but the build uses Pester 4.x. So that's probably why the extension is failing... – Dennis Sep 24 '21 at 14:24

1 Answers1

0

Ok, turns out it was the build that was at fault on my end (and wrong version of Pester, v4 needed).

Once all dependency modules was in place, I was able to run the Pester tests as invoked by the build.ps1.
No way of just running Invoke-Pester though in this project.

Dennis
  • 871
  • 9
  • 29
  • I downloaded and did the build and was able to run `Invoke-Pester` just fine from the Tests folder, using Pester v4.10.1 as mentioned in the comments. Version 5 does not work I believe because code needs to be placed explicitly in BeforeEach/BeforeAll blocks whereas in older version this was not necessary. – Daniel Sep 25 '21 at 18:12
  • 1
    Ah, you moved to the Tests folder first :) – Dennis Sep 25 '21 at 18:39
  • Didn't work. I'm still missing something that needs to be done to my local repo... `The specified module 'xFailOverCluster' was not loaded because no valid module file was found in any module directory`. Do I need to register a PS Repo for the output folder? – Dennis Sep 25 '21 at 18:45
  • 1
    Something strange, seems that `.\build.ps1 -Tasks build` needs to be run first in each powershell session for Invoke-Pester to work. If I close powershell and open again it build needs to happen again first – Daniel Sep 25 '21 at 18:57
  • Ok, so definitely a build thing? Perhaps better to move this discussion to [GitHub - Running Pester Unit tests locally before Pull Request #262](https://github.com/dsccommunity/xFailOverCluster/issues/262)? – Dennis Sep 26 '21 at 07:53