-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Reset defaults before tests #1212
Conversation
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.
This cloned object could have the same problem if it’s mutated. Instead, created a function marked.getDefaults() that returns a new object each time. That function can be used to assign the default object the first time.
good call |
lib/marked.js
Outdated
clone[opt] = defaults[opt]; | ||
} | ||
|
||
return clone; |
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.
Is the clone still necessary?
Can't you return defaults;
here instead?
It's always returning a new object each call to the function so I can't think of a scenario where it would break.
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.
I see what you are saying
I ran into problems using beforeEach(function() {
marked.defaults = {
headerIds: false,
xhtml: true
}
});
afterEach(function() {
marked.defaults = {
headerIds: true,
xhtml: false
}
}); The CommonMark spec doesn't recognize header IDs and uses XHTML for some of the tests. |
lib/marked.js
Outdated
xhtml: false | ||
}; | ||
|
||
var clone = {}; |
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.
Is it possible to do this as part of the test itself instead of the lib? Believe @styfle mentioned something like that before. Thinking it would be better to have the test use a blank object over the singleton pattern that seems preferred by Node (understandably in many use cases).
@joshbruce We could do something like that in the tests but then next time we add a new test file we will have to remember to do the same thing or we will fall into the same trap. This way we never have to think about it again. |
@UziTech: Agreed. Think that's on us as reviewers. Not sure how often we'll be adding new test suites at this juncture, just seems the more logical place and, if we can do it in a single place, then we should be good. |
@UziTech: PS. good catch on the not returning thing. I mean to ask about that. |
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.
LGTM 👍
@joshbruce I think this PR should land before the other PRs that involve the test harness. |
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.
Just want to verify the order of operations here. Before each, we set the options to defaults, the tests modify where needed. We are also making the defaults a getter only because we have the setter via setOptions
.
Yes, We are resetting |
Reset defaults before tests
Marked version: 0.3.19
Description
marked.getDefaults()
that gets assigned tomarked.defaults
Contributor
Committer
In most cases, this should be a different person than the contributor.