Skip to content

Added possibility to pass tests script as string to address cases whe…#972

Merged
nohwnd merged 7 commits intopester:masterfrom
Chekusty:master
Dec 12, 2018
Merged

Added possibility to pass tests script as string to address cases whe…#972
nohwnd merged 7 commits intopester:masterfrom
Chekusty:master

Conversation

@Chekusty
Copy link
Copy Markdown
Contributor

@Chekusty Chekusty commented Jan 12, 2018

Added possibility to pass tests script as string to address cases when powershell scripts and tests for them are stored not on FileSystem but in some storage like DataBase and executed in Temp folder.

Example is Sitecore CMS, where we use SPE (Sitecore Powershell Extensions) module to create and run PS scripts. We store scripts and tests as Items in content tree and SPE executes them when needed in Temp folder on the server.

Will try to add Pester tests later this week.

…n powershell scripts and tests for them are stored not on FileSystem but in some storage like DataBase and executed in Temp folder.

Example is Sitecore CMS, where we use SPE (Sitecore Powershell Extensions) module to create and run PS scripts. We store scripts and tests as Items in content tree and SPE executes them when needed in Temp folder on the server.
@it-praktyk it-praktyk self-requested a review January 12, 2018 19:46
Copy link
Copy Markdown
Contributor

@it-praktyk it-praktyk left a comment

Choose a reason for hiding this comment

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

Please add tests which confirm that Pester executed with the new parameter really works.

Comment thread Pester.psm1 Outdated
[Parameter(Position = 0)]
[string] $Path,

[string] $Script, #in order to allow passing test script as a string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An added parameter is not explained in the comment based help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed it from here. Mentioned usage of this parameter in example (line 661). Do you think it understandable enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@it-praktyk Could you please review my PR again? I`ve added test and description for parameter. Changes are backward compatible.

Comment thread Pester.psm1 Outdated
)

& $Path @Parameters @Arguments
if(![string]::IsNullOrEmpty($Path))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use -not instead !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Thanks!

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Mar 19, 2018

@Chekusty It fails on the build server on PowerShell 2 with this error:

[21:05:13][Step 1/1] C:\TeamCity\BuildAgent\temp\buildTmp\powershell7172863267207089627.ps1 : Proper
[21:05:13][Step 1/1] ty 'ScriptStackTrace' cannot be found on this object. Make sure that it exists.
[21:05:13][Step 1/1]     + CategoryInfo          : InvalidOperation: (.:OperatorToken) [Write-Error 
[21:05:13][Step 1/1]    ], RuntimeException
[21:05:13][Step 1/1]     + FullyQualifiedErrorId : PropertyNotFoundStrict,powershell717286326720708 
[21:05:13][Step 1/1]    9627.ps1
[21:05:13][Step 1/1]  
[21:05:13][Step 1/1] Process exited with code 1
[21:05:13][Step 1/1] Process exited with code 1
[21:05:14][Step 1/1] Step Run Tests (PowerShell) failed
[21:05:14]NUnit report watcher
[21:05:14][NUnit report watcher] No reports found for paths:
[21:05:14][NUnit report watcher] +:Test.*.xml

@Chekusty
Copy link
Copy Markdown
Contributor Author

@nohwnd I think I need a little bit of your help, because I cannot find error locally, and error message is not descriptive.. Do you have any idea what can be wrong?

@nohwnd nohwnd self-assigned this Mar 27, 2018
@it-praktyk
Copy link
Copy Markdown
Contributor

@Chekusty, it's internal error of the TeamCity instance.

@Chekusty
Copy link
Copy Markdown
Contributor Author

@it-praktyk Ok. Can I expect that someone will fix this internal error?

@it-praktyk
Copy link
Copy Markdown
Contributor

I hope. I've asked yesterday @dlwyatt for that.

@Chekusty
Copy link
Copy Markdown
Contributor Author

@it-praktyk Great! Thank you, guys!

@it-praktyk it-praktyk requested a review from nohwnd May 8, 2018 21:20
@it-praktyk
Copy link
Copy Markdown
Contributor

I've found the reason why some tests fail under PowerShell 2.0

> Set-StrictMode -Version Latest
> Invoke-Pester
Executing all tests in '.'

Executing script <FOLDER_PATH>\Pester\Dependencies\Format\Format.Tests.ps1
Property 'ScriptStackTrace' cannot be found on this object. Make sure that it exists.
At <FOLDER_PATH>\Pester\Pester.psm1:879 char:47
+                     $firstStackTraceLine = $_. <<<< ScriptStackTrace -split '\r?\n' | & $script:SafeCommands['Select-
Object'] -First 1
    + CategoryInfo          : InvalidOperation: (.:OperatorToken) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented May 9, 2018

@it-praktyk Great. That is the line I thought will be the case. Weird that it does not print the whole error message in the TC output, I will try to enhance that first, and then fix this error.

@nohwnd nohwnd merged commit ab8725c into pester:master Dec 12, 2018
@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Dec 12, 2018

I could not push into your master, so I am merging this as is, and will merge a fix for the problems there were on PowerShell 2 shortly after. Thanks for the change.

Next time please make a branch for the change instead of making a pull-request from your master, if you don't know how to do it please ask 🙂

nohwnd added a commit that referenced this pull request Dec 12, 2018
Fix providing scripts directly to Invoke-Pester on PowerShell 2
@Chekusty
Copy link
Copy Markdown
Contributor Author

Chekusty commented Dec 13, 2018

OMG, thank you very much! I lost my hope this summer 😄 Now we will finally be able to switch to Pester, not ChekustyCustomPester 😌 Thank you!

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Dec 13, 2018

@Chekusty Sorry it took so long, I will release it in few days. 😊

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