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

Add testFilePath to test context #7536

Closed
PhoenixHe-NV opened this issue Dec 19, 2018 · 5 comments
Closed

Add testFilePath to test context #7536

PhoenixHe-NV opened this issue Dec 19, 2018 · 5 comments

Comments

@PhoenixHe-NV
Copy link

PhoenixHe-NV commented Dec 19, 2018

🚀 Feature Proposal

It would be nice if the jest-environment could access test file path via test context

Motivation

Under the context of jest-environment we couldn't access the test file path, but I need it.

Example

class SomeEnvironment extends PuppeteerEnvironment {
  setup() {
    this.context.testFilePath // should be path to current test script
  }
}

Pitch

Why does this feature belong in the Jest core platform?

It can't be done by custom reporter because the reporter and the environment may not be in the same process thanks to jest-runner. There's almost no way to pass information between jest environment and jest reporter. If the jest environment could collect the test file path then they could communicate via some temporary file.

@PhoenixHe-NV
Copy link
Author

Here is the background:

I want to capture video via devtools (in puppeteer) and generate subtitle under my custom reporter. Each test file should generate 2 files, one mkv video and one srt subtitle. The video capture must be captured in jest environment because in reporter we cannot access puppeteer environment. The subtitle must be generated in reporter because only in reporter we could collect test results. Now the problem is in jest environment there is no way to figure out current test file path, so the jest environment don't know the correct path for the video.

I've tried to copy path from reporter context to global in reporter's onTestStart() so that jest environment could collect the test file path from global. It works if --runInBand is enabled, but not works without the flag. If there are some way else to handle my scenario please let me know. Thanks!

@PhoenixHe-NV
Copy link
Author

Another approach I've tried is to 'steal' the path via argument.callee.caller in jest environment. That doesn't work because strict mode is enabled.

@SimenB
Copy link
Member

SimenB commented Dec 19, 2018

This will be implemented via #7442, you can track that 🙂

@SimenB SimenB closed this as completed Dec 19, 2018
@PhoenixHe-NV
Copy link
Author

Oh thanks!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants