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

Fix missing command temp-directory #928

Merged
merged 4 commits into from Jan 6, 2019
Merged

Conversation

AndrewFinlay
Copy link
Contributor

Hi all,

So I've come up with this and added a few tests to confirm behaviour.
Let me know if anything more needs to be done to get this over the line.

Thanks,
Andrew

AndrewFinlay and others added 2 commits October 20, 2018 08:17
After changing tempDirectory to tempDir, with a fallback for tempDirectory, the default values set in the 'temp-dir' yargs option were being used rather than falling back to tempDirectory and then the default temp dir.
This change removes the yargs default value for the option 'temp-dir'.
This means the statement that assigns '_tempDirectory' in 'index.js' attempts to use temp-dir, then temp-directory, then the default value.  
This is now under test with some new test cases that show:
  - tempDir is preferred to tempDirectory
  - tempDirectory is used if tempDir isn't set
  - that we fall back to the '.nyc_output' dir if neither tempDir or tempDirectory are set.
@coreyfarrell
Copy link
Member

One concern I hadn't previously thought of, this will stop yargs from displaying the default value in nyc --help. It's possible that a better fix would be to leave the default in place but modify index.js:

this._tempDirectory = config.tempDirectory || config.tempDir

This would use --temp-directory if specified, --temp-dir otherwise. Removing the || './.nyc_output' at the end would avoid future confusion about how the value is set.

Sorry I didn't think of this at first. @AndrewFinlay @bcoe @JaKXz do you have any opinion on this?

@AndrewFinlay
Copy link
Contributor Author

It did cross my mind that you'd lose the default setting in the help, but I also thought it to be important to prefer tempDir over tempDirectory.

Looking at the yargs docs there is the opt key defaultDescription, this can output a default description of './.nyc_output' as help text without affecting the value of tempDir. It looks the same in the help text as if a default value were set. This solution is getting a little messy though, and wouldn't do much to clear up confusion about whether the default value is set while building yargs objects or in the index.js file.

So I suppose if preferring tempDir over tempDirectory isn't important we'll go with your solution, otherwise I can add the code to provide defaultDescription.

With a best case solution in mind, and I think we may have discussed it before, adding something like a silentAlias option key to yargs would make what we're trying to do here a whole lot neater.

@coreyfarrell
Copy link
Member

I was not aware of the defaultDescription attribute. Unfortunately it looks like that option doesn't work correctly without a truthy value for default. Just setting defaultDescription causes that value to be used as default for tempDir. Even setting default: '' or default: false does not seem to prevent defaultDescription from being used as the actual default.

As for preferring temporaryDir over tempDir this might actually be better. Old versions of nyc --temp-dir were silently ignored. So if both options are specified (silly I know), the old behavior would be to honor --temporary-dir.

@AndrewFinlay
Copy link
Contributor Author

Sounds good, will move it over to that.
Had a bit more of a look at the tests I proposed and they're not correct so I'll give those another spin.

Unknown added 2 commits October 21, 2018 14:03
Maintains notice of default temp-dir in help output.
Removed tests as I'm not confident with these right now, will take another look when I get some time.
fix pointless changes
@coreyfarrell
Copy link
Member

@simlu Could you test this updated patch, confirm that it resolves your issue? Thanks!

@AndrewFinlay thanks for your quick responses to this issue!

Copy link
Member

@coreyfarrell coreyfarrell left a comment

Choose a reason for hiding this comment

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

Pending feedback from issue reporter.

Copy link
Member

@JaKXz JaKXz left a comment

Choose a reason for hiding this comment

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

This makes sense! too bad we didn't catch it the first time. Would it be possible to write a test case? 🤷‍♂️

@AndrewFinlay
Copy link
Contributor Author

AndrewFinlay commented Jan 3, 2019

This has been on my list for a while now, it hasn't been my highest day job priority but since it's the quiet season I had planned to get onto this next week. Anyway I had a few troubles getting the tests up and running on my first attempt at this and dumped them as they weren't right. So I'll try and get them working properly and submit them with this fix.

It'll need a refactor too as it's a pretty messy commit history so far.

@simlu
Copy link

simlu commented Jan 3, 2019

@coreyfarrell This was so breaking for me that I had to fix it immediately - this fix came to late unfortunately. So I'm not really able to test at this point if the old syntax still works as expected - the new one however does the job.

@JaKXz
Copy link
Member

JaKXz commented Jan 4, 2019

Don't worry about the commit history, we'll do a squash when we merge.

@bcoe @coreyfarrell can we just merge this as is and let @AndrewFinlay write a test in a later PR?

@JaKXz JaKXz merged commit 28b6d09 into istanbuljs:master Jan 6, 2019
@AndrewFinlay AndrewFinlay deleted the tempDirFix branch February 27, 2019 02:46
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.

None yet

4 participants