Skip to content

Conversation

philipp-spiess
Copy link
Member

While working on #14078, there were a couple of debugging techniques that we were using quite frequently:

  • Being able to cd into the test setup
  • Seeing the stdio and stdout data in real-time (this currently requires us to mark a test as failing)
  • Checking the exact commands that are being run

Since we naturally worked around this quite often, I decided to make this a first-level API with the introduction of a new test.debug flag. When set, it will:

  • Create the test setup in the project dir within a new .debug folder and won't delete it after the run. Having it in an explicit folder allows us to easily delete it manually when we need to.
  • Logs all run commands to the console (> for a sync call, >& for a spawned process)
  • Logs stdio and stderr to the console in real time.
  • Run the test as .only
Screenshot 2024-08-06 at 13 19 49


options.onTestFinished(dispose)

let context = {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was moved up so that pnpm install can use the same exec function that we also export


child.stdout.on('data', (result) => {
let content = result.toString()
if (debug) console.log(content)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have like a [stdout] prefix or something? Just so it's more easily distinguishable in the test output?

Copy link
Contributor

Choose a reason for hiding this comment

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

thinking out loud: should probably prefix every line of the output

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, maybe? It could help with the onStderr helper we have but I wonder why we need to be so diligent about this in the first place. In normal terminal apps you don't see the difference between stdout and stderr in the console either unless you pipe line stream to another location. I decided to replicate this here by using console.log for stdout and console.error for stderr

Copy link
Member

Choose a reason for hiding this comment

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

I personally don't think the [stdout] or [stderr] prefix helps here because Vitest already shows that for us:

image

})
child.stderr.on('data', (result) => {
let content = result.toString()
if (debug) console.error(content)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto but with [stderr]


child.stdout.on('data', (result) => {
let content = result.toString()
if (debug) console.log(content)
Copy link
Member

Choose a reason for hiding this comment

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

I personally don't think the [stdout] or [stderr] prefix helps here because Vitest already shows that for us:

image

rejectDisposal = reject
})

if (debug) console.log(`>& ${command}`)
Copy link
Member

Choose a reason for hiding this comment

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

We could do the same here as above, but this now results in the same command log, but just with a different prefix:
image

I would maybe just drop this? 🤔

Suggested change
if (debug) console.log(`>& ${command}`)

Copy link
Member Author

Choose a reason for hiding this comment

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

@RobinMalfait I’m confused, how did you get to the above log? Were you doing both exec() and spawn()? (and if that is the case, would you not expect both to log? 🤔)

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait, right, I'm confused as well haha. Not sure how I got the output twice. Please ignore.

@RobinMalfait RobinMalfait force-pushed the feat/add-content-support branch from ad400be to 737a5d2 Compare August 7, 2024 14:13
@RobinMalfait RobinMalfait mentioned this pull request Aug 7, 2024
8 tasks
@RobinMalfait
Copy link
Member

I think this PR should be merged in next instead of the @source support PR.

@philipp-spiess
Copy link
Member Author

@RobinMalfait yeah I need to rebase it I just wanted it to be based on the latest changes :)

Base automatically changed from feat/add-content-support to next August 7, 2024 14:38
@philipp-spiess philipp-spiess merged commit af2e699 into next Aug 8, 2024
@philipp-spiess philipp-spiess deleted the feat/test.debug branch August 8, 2024 10:02
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