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
Explain in docs why .reset() is deprecated, or un-deprecate it #1639
Comments
This should not be the case: could you please give us some code reproducing this?
Did you try building a fresh yargs instance before each test, instead of reusing and resetting the same instance each time? |
Sure: it’s the state of the code after this commit of my open-source project. In that commit, you can see I added a How to reproduce locally:
The relevant parts of the code:
|
I mean using const yargs = require('yargs')
const yargsParser = yargs() or const yargs = require('yargs/yargs')
const yargsParser = yargs() which would return a new yargs instance, instead of using it as an object: const yargs = require('yargs')
const yargsParser = yargs which is always the same instance, initialized the first time the module is loaded (the so-called singleton mentioned in the docs - but maybe cryptically - here: https://github.com/yargs/yargs/blob/master/docs/advanced.md#using-the-non-singleton-interface). |
For interest, I came across another mention of decreased reliance on |
The non-singleton API to yargs is now the primary method used in the documentation, and is the recommended approach for multiple parsing situations like unit tests. i.e. Make a fresh yargs instance for each test.
|
Documentation problem
The
.reset()
API documentation on https://yargs.js.org/docs/ starts like this:It doesn’t explain why
.reset()
is deprecated or what to use instead. This is bad because it’s the only option I see for my use-case, but it leaves me wondering if some bug will eventually bite me.My use-case for
.reset()
is unit tests: my unit tests of my CLI arg parsing sometimes fail when I try to parse args multiple times due to global state that persists between tests, so I have to callyargs.reset()
before each test.Possible resolutions
It looks like the file docs/api.md is the source of https://yargs.js.org/docs/. That’s the file that should be updated.
I see one related closed issue, #654. Reading that issue, I can guess that maybe you added the deprecation warning when that issue was created but forgot to delete it when that issue was closed.
The first comment in that issue also mentions a non-singleton API
require('yargs/yargs')
as an alternative. Right now https://yargs.js.org/docs/ doesn’t mention that API anywhere and I’m not sure if it still exists (the comment mentioning it was written in 2016). If it still exists, that API would be perfect for my use-case – even better than.reset()
– and it should be mentioned in.reset()
’s documentation, whether or not.reset()
stays deprecated. (That non-singleton API should also be mentioned in the API section at the top of the documentation, though this can be a separate issue.)The text was updated successfully, but these errors were encountered: