Fix #216 and add additional mocha configuration options#168
Fix #216 and add additional mocha configuration options#168mousetraps merged 5 commits intomicrosoft:masterfrom
Conversation
Makes the mocha UI, Reporter, Timeout, etc configurable using a mocha.json to specify the values.
|
Hi @lukedgr, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
There was a problem hiding this comment.
This should be console.error("NTVS_ERROR:", blah), otherwise the test reporter won't pick it up and display it i nthe output window (it's a bit confusing because you see it printed out in debug mode.)
There was a problem hiding this comment.
I saw your comment fly by in email, but I can't see it on github for some reason. Anyways to elaborate on this... as the code is written now, the user will not see it. "NTVS_ERROR" is a string that we search for and strip out of the final output when we display it in the output window.
IEnumerable<String> stdoutLines = stdout.Split(new string[] {Environment.NewLine},
StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("NTVS_ERROR:")).Select(s => s.Trim().Remove(0,11));You'll only see the full output printed out when the product is built with the "Debug" configuration, but not the "Release" config. So using logError is the way to go here.
|
Updated the comment/title to point to the right issue (just created a feature for mocha config options). Separate issues helps us track and verify everything is working before a release. I also just submitted a fix to the defaults on #217, which would be good to merge with these changes as well. So we can also consider adding another timeout for debug mode. |
There was a problem hiding this comment.
console.error instead of console.log. Also see recent changes (very minor), so adding another argument here would be good too.
|
Hey, thanks so much for the contribution! 😃 I left some more specific notes on the code, but some more general comments below. I've actually been toying around with this change in my mind, and it would be great to hear your thoughts. I'm not entirely sure about the configuration discovery aspect (projectFolder\tests), but I also think it's a big step in the right direction 😃. So I'm in favor of taking this change, and then adapting it over time as we get feedback on it and understand people's preferences. Ultimately if people like this approach, and they start requesting it for more features, we might want to start including many more settings in a single file (sort of like VSCode's settings.json). But this is a good litmus test. The other interesting note is that... when we get the chance, we'll want to consider moving to the Common Project System (rather than maintaining VisualStudio-SharedProject, as we do now), and CPS is a more folder/file based system, so we'll probably have to revisit this issue then.- and not just go for mocha tests, but really settings in general. On the technicalities end...
|
Use path instead of manual path setting and updated error reporting.
There was a problem hiding this comment.
with logError, there is no need to prepend NTVS_ERROR here anymore.
|
Thx for the new iteration. Added some super minor comments, and lgtm after that |
|
I am happy to help improve NTVS! ... On the mocha options json path, I agree that it is not ideal to have the relative path hard-coded, and I think it would be great if each .njsproj had it's own settings file. The reason I decided to use projectFolder\test\mocha.json is that when running from the command line mocha will look for options at .\test\mocha.opts (http://mochajs.org/#mocha.opts). |
|
Ahh, that makes much more sense now, and thanks for the link - I wasn't familiar with mocha.opts So eventually... what if instead of specifying a separate json file, we could just pick up the options from the mocha.opts? That way it "just works" with an existing setup. |
|
I see your point of it just working with the existing set up, however the downside to that is you are unable to specify different options for the CL and VS. For example, my project uses a different reporter on the CL than when running inside VS. |
|
Gotcha, good call |
|
👍 with the new changes btw. I'll merge it in when I get the chance. |
|
Any plans to support more options (like the --require flag)? Also, it might be good to document which flags don't currently work. I'm tempted to hack around in the mocha.js file to get things working but I don't want to break my upgrade path. |
|
@landonpoch I don't think we have any plans to do this at the moment, but feel free to look into adding additional options and submit a PR (see #940.) However, I don't think we want to encourage the use of the |
#216
This change adds the ability to configure mocha by adding a config file to the project located at $(ProjectDirectory)\test\mocha.json. The relative path under the test directory was chosen because this is where mocha looks for a configuration by default when run from the command line (looks for mocha.opts). Adding the mocha.json file will result in the mocha tests running with the options specified.
An example of a valid mocha.json file is:
{
"ui": "tdd",
"timeout": 300000,
"reporter": "xunit"
}
Also, note that if the config file does not specify a ui, timeout or reporter the default will be chosen automatically.