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

Start interactive execution from BeforeDiscovery #2217

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Jul 14, 2022

PR Summary

Extends interactive execution to also being triggered from root-level BeforeDiscovery.

This is necessary to avoid leaking variables from a BeforeDiscovery-block to Run-phase during interactive execution when BeforeDiscovery is placed before Context\Describe which it usually is. The variables would've been made available in Run-phase from a parent scope.

Before-/AfterEach throw when used in root and Before-/AfterAll only works when in Discovery-phase, so they're not affected.

Fix #2092

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@fflaten
Copy link
Collaborator Author

fflaten commented Jul 15, 2022

@nohwnd Do you know what this does? It was only added for Context in #1435 and I don't think it's triggered. The variable would be lost the next time since it's local to Context-function.

if ($invokedInteractively) {
return
}
$invokedInteractively = $true

Early attempt of solving this maybe?

if ($null -ne $script:lastExecutedAt -and ([datetime]::now - $script:lastExecutedAt).TotalMilliseconds -lt 100 -and $script:lastExecutedFile -eq $ScriptName) {
# skip file if the same file was executed less than 100 ms ago. This is here because we will run the file from the first
# describe and the subsequent describes in the same file would try to re-run the file. 100ms window should be good enough
# to be transparent for the interactive use, yet big enough to advance from the end of the command to the next, even on slow systems
# use the file name as well to allow running multiple files in sequence
$script:lastExecutedFile = $ScriptName
$script:lastExecutedAt = [datetime]::Now
return
}

Update: I've suggested to remove it in the related PR

@fflaten fflaten changed the title Start interactive execution from root-level BeforeDiscovery Start interactive execution from BeforeDiscovery Jul 16, 2022
@nohwnd
Copy link
Member

nohwnd commented Jul 25, 2022

Yeah that looks like it was early attempt to solve having multiple top-level blocks in the same file.

@nohwnd nohwnd merged commit c0e6578 into pester:main Jul 25, 2022
@fflaten fflaten deleted the fix-interactive-beforediscovery branch July 25, 2022 09:03
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.

Test fails when no breakpoint is set, test passes with a breakpoint set
2 participants