-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
deprecate noHighlighting and replace it with reporterOptions.highlight #3701 #4049
Conversation
browser-entry.js
Outdated
@@ -130,7 +130,17 @@ mocha.setup = function(opts) { | |||
} | |||
for (var opt in opts) { | |||
if (opts.hasOwnProperty(opt)) { | |||
this[opt](opts[opt]); | |||
if (opt === 'noHighlighting' && opt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check opt
value here. We can show a deprecation message whether noHighlighting
is true
or false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I missed that, thank you so much.
@@ -224,6 +239,12 @@ function HTML(runner, options) { | |||
updateStats(); | |||
}); | |||
|
|||
runner.once(EVENT_RUN_END, function() { | |||
if (options.reporterOptions.highlight) { | |||
utils.highlightTags('code'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be enabled with noHighlighting
before it removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not here. In browser-entry.js
6780944
to
bccc722
Compare
4d3d444
to
bf6ff56
Compare
6541784
to
7770b95
Compare
👋 coming back to this @Mia-jeong, are you still interested in working on this PR? As of #5027 there are again maintainers who can review it now. No worries if you no longer have time - but if you do that'd be great! |
Closing for now to keep our queue small, as there's an unresolved comment: https://github.com/mochajs/mocha/pull/4049/files#r332832395. But if you end up having time to work on this again @Mia-jeong we'd love to see you re-open this PR or post a new one. And if anybody else sees this & sends their own, please include a co-authored-by attribution to credit @Mia-jeong for this work. |
Description
I added a deprecation notice for
noHighlighting
in browser and replace it with reporterOptions.highlight as mentioned in #3701Description of the Change
1.
If a user supplies {noHighlighting: true} to mocha.setup() or calls mocha.noHighlighting() in the browser, we should print a deprecation message along the lines of "noHighlighting is deprecated; provide {reporterOption: {highlight: false}} to mocha.setup().
while I was working on it. I found out a bug related to
noHighlighting
.Problem
Even though you pass
false
to noHighlighting inmocha.setup()
like below,noHighlighting
turns intotrue
, therefore we can't highlight text.Reason
I tracked down the code to deal with it, and found out a reason about it.
in
mocha.setup
inbrowser-entry.js
, you can see the code below. if options are passed, it calls the function named after the options.for example, if we supply
noHighlighting
tomocha.setup()
, noHighlighting() function will be invoked.In
noHighlighting() function
it settrue
tonoHighlighting
, No matter which value were passed. Here's the code in/lib/mocha.js
Solution
I changed
Mocha.prototype.noHighlighting()
inlib/mocha.js
like one below.I let function get a parameter called
enableHighlight
.If we call
mocha.noHighlighting()
, it will beundefined
, thenreporterOptions.highlight
is set asfalse
.If we set value to noHighlighting in
mocha.setup()
,reporterOptions.highlight
is set as the value depending on which value are supplied by user.As you can see it, I added a deprecation notice inside the function as well.
In addition, In case they pass
{reporterOptions: {highlight: false}}
tomocha.setup()
, to avoid throwing an error I added conditional statements below inbrowser-entry.js
as well. Because there's no function calledreporterOptions
2.
The html reporter's constructor should accept a reporterOptions object, which may be undefined, and may have a boolean highlight property. If the property is anything other than explicitly false, default to true. in order to set reporterOptions.highlight value to options
I add the code to set the default value to it. so if they didn't pass false to
reporterOptions.highlight
, it will betrue
as default.3.
The reporter's constructor should execute Mocha.utils.highlightTags('code') when the end event is emitted by the runner property.
to run it, I added the code below in
html.js
. The value ofenableHighlight
is going to be set as mentioned in 2I didn't check out whether
document
exists or not, because in html.js , I found out the code to throw an error when there's nodocument
4.
As I moved the highlighting code to html.js, I removed the duplicated checks below from browser-entry.js as mentioned in #3701
5.
add unit tests which assert the new behavior in test/unit/mocha.spec.js.
I modified test code of
noHighlighting
intest/unit/mocha.spec.js
.as a result of it, we can check out that if user calls
mocha.noHighlighting()
,reporterOptions.highlight
will be false.In fact I wanted to add another test only for reporterOptions.highlight. but I wasn't able to do it. I added the code to set the default value to reporterOptions.highlight in
html.js
. so If I want to add a test, I think I should do it tohtml.spec.js
, but There is nothing..6.
add the description about it in documentation, so I added the text to index.md.
Here's what it looks like.
Benefits
As I stated above, I also fix the bug about
noHighlighting()
, so it's going to be helpful to deal with it as well.Applicable issues
#3701
Thank you for reading my request :)