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

currentContext exposure? #4792

Closed
nopeless opened this issue Nov 30, 2021 · 6 comments
Closed

currentContext exposure? #4792

nopeless opened this issue Nov 30, 2021 · 6 comments
Labels
type: question support question

Comments

@nopeless
Copy link

I was reading the code and found out that the local variable currentContext is used but not accessible outside the library
I think a simple mocha.getCurrentContext() would help developers and even myself write cleaner mocha extensions

Are there any problems with this? Can I write a pr for something this simple?

@nopeless nopeless added the type: question support question label Nov 30, 2021
@nopeless
Copy link
Author

the only reason I'm not making a pr is because I am inclined to believe that there is a good reason to not expose the that variable (given how easy it is to do so)

@juergba
Copy link
Member

juergba commented Dec 1, 2021

currentContext equals to global (globalThis), Mocha's functions are added to global within the selected ui interface.
We have added this currentContext proxy due to problems with parallel mode, where we have distinct global's for each process.
To expose global does not make sense.

@nopeless
Copy link
Author

nopeless commented Dec 1, 2021

@juergba Here is a js fiddle explaining my point
http://jsfiddle.net/stxfh2cz/3/
I know that the this rvalue is currentContext, I just think that certain functions like these can be easier to write

@nopeless
Copy link
Author

nopeless commented Dec 2, 2021

@juergba Any updates?

@juergba
Copy link
Member

juergba commented Dec 6, 2021

I don't know wether we are talking about the same currentContext.

  • there is no skip() on currentContext (global), but instead describe.skip() and it.skip().
  • you are passing this which isn't identical to global. I guess it's the runnable.
  • I don't understand why you don't just call skip() instead of skipIfTrueWithContext(true)

I'm sorry, but I don't understand your point.

@nopeless
Copy link
Author

nopeless commented Dec 8, 2021

@juergba sorry for the late reply
I found out that currentContext isn't quite what I think
I'll just extend the prototype of Context instead

But to give an idea what I thought was current Context,
I thought after(() => {}) hooks were working inside it()

But now that I follow the code execution, it has an empty context.

I'm not sure why after can be called while a test is executing

anyway I think I get the idea better now

@nopeless nopeless closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question support question
Projects
None yet
Development

No branches or pull requests

2 participants