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

Reset defaults before tests #1212

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,25 +1345,36 @@ marked.setOptions = function(opt) {
return marked;
};

marked.defaults = {
baseUrl: null,
breaks: false,
gfm: true,
headerIds: true,
headerPrefix: '',
highlight: null,
langPrefix: 'lang-',
mangle: true,
pedantic: false,
renderer: new Renderer(),
sanitize: false,
sanitizer: null,
silent: false,
smartLists: false,
smartypants: false,
tables: true,
xhtml: false
};
marked.getDefaults = function () {
var defaults = {
baseUrl: null,
breaks: false,
gfm: true,
headerIds: true,
headerPrefix: '',
highlight: null,
langPrefix: 'lang-',
mangle: true,
pedantic: false,
renderer: new Renderer(),
sanitize: false,
sanitizer: null,
silent: false,
smartLists: false,
smartypants: false,
tables: true,
xhtml: false
};

var clone = {};
Copy link
Member

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).

for (var opt in defaults) {
clone[opt] = defaults[opt];
}

return clone;
Copy link
Member

@styfle styfle Apr 10, 2018

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.

Copy link
Member Author

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

}

marked.defaults = marked.getDefaults();

/**
* Expose
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var marked = require('../../lib/marked.js');

beforeEach(function () {
marked.setOptions(marked.getDefaults());
});