Pester does not seem to be seeing my changes

I’m running PowerShell on a WSL2 instance of Ubuntu 22.04. I have the latest version of PowerShell (7.5.1) and Pester (5.7.1). Everything was working fine until recently when Pester stopped seeing my changes. I’m seeing errors like this:

[-] DnD Character test cases.random character tests.random ability is in range 2ms (1ms|0ms)
 at <ScriptBlock>, /home/rzuckerm/git/rzuckerm/exercism/powershell/dnd-character/DndCharacter.ps1:33
 at Character, /home/rzuckerm/git/rzuckerm/exercism/powershell/dnd-character/DndCharacter.ps1:32
 at <ScriptBlock>, /home/rzuckerm/git/rzuckerm/exercism/powershell/dnd-character/DndCharacter.tests.ps1:123
 RuntimeException: The property '_' cannot be found on this object. Verify that the property exists and can be set.

I accidentally forgot $ before the _. I have since added the $, but Pester still isn’t seeing that change. I decided to just go ahead and submit the code, and it passes just fine here.

Any idea how I can fix this?

It’s happening again. I think this is related to exercises that use classes. I’m working on High Scores, and Pester is not seeing my changes. I had to keep exiting VSCode and relaunching it.

At work I sometimes experience similar problems when using VSCode. Files are reported to be saved to disk but actually are not. You can take a look at the file change time reported in your WSL2 shell to verify that you experience this kind of problem.

PS: Editing WSL files uses VSCodes Remote Editing extension, and you could run PowerShell on Windows directly. What’s the reason for the additional complexity here?

I do all my software development in Linux. It’s just what I’m used to. Also, all of my developer tools are installed in Linux. I really don’t want to have to duplicate things in Windows, like git.

I know that i’m not contributing to solving the issue, but I can’t help but wonder, why run Linux under WSL in the first place, if you prefer it to Windows?

I don’t prefer Windows for software development. Instead, I prefer Linux for that, and WSL is the easiest way to do that without having to buy another system and install Bare-Metal Linux. I run Windows because I have applications that only run in Windows.

Can someone please help me with my issue instead of making me justify my development practice?!

I have confirmed that this only happens for exercises that use classes. I just had the same problem with Allergies, and I have not had this problem with any other non-class related exercises.

Not a Powersheller but can you use Powershell classes via WSL2 outside of Pester? If we could isolate the issue to Pester, that’d be helpful since we already know the code seems to work with Pester on Alpine Linux.

@BNAndras What would be the best way to do that? I’m still pretty new to PowerShell. Would I just create some trivial class, run . ./path-to-script.ps1, and try to do something with the class? It seems like changes wouldn’t take effect until I did . ./path-to-script.ps1 again

This seems interesting:
https://stackoverflow.com/questions/42838107/remove-class-from-memory-in-powershell

I think I’ll try that and see what happens.

The StackOverflow article seems to work. I tried this for the Allergies exercise:

pwsh -Command Invoke-Pester

I made a change to the constructor to just do Write-Host "Code=$Code", ran the command above, and I saw the output. It’s annoying, but at least I have a workaround now that is better than restarting VSCode.

2 Likes