-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add setDefaultOptions and restoreDefaultOptions
- Loading branch information
Showing
4 changed files
with
140 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const merge = require("lodash.merge"); | ||
|
||
const defaultOptionsTemplate = { | ||
waitUntilNetworkIdle: false, | ||
launch: {}, | ||
screenshot: undefined, | ||
serve: [] | ||
}; | ||
|
||
let defaultOptions = defaultOptionsTemplate; | ||
|
||
const addArg = (opts, arg) => { | ||
// eslint-disable-next-line no-param-reassign | ||
if (!Array.isArray(opts.launch.args)) opts.launch.args = []; | ||
|
||
if (!opts.launch.args.includes(arg)) { | ||
opts.launch.args.push(arg); | ||
} | ||
}; | ||
|
||
module.exports.setDefaultOptions = options => { | ||
defaultOptions = merge({}, defaultOptionsTemplate, options); | ||
}; | ||
|
||
module.exports.restoreDefaultOptions = () => { | ||
defaultOptions = defaultOptionsTemplate; | ||
}; | ||
|
||
module.exports.getMergedOptions = options => { | ||
const opts = merge({}, defaultOptions, options); | ||
|
||
// config sugar to let users specify viewport directly | ||
if (options && options.viewport && !opts.launch.defaultViewport) { | ||
opts.launch.defaultViewport = options.viewport; | ||
} | ||
|
||
if (!Array.isArray(opts.serve)) { | ||
throw new Error("jsdom-screenshot: options.serve must be an array"); | ||
} | ||
|
||
// Disable "lcd text antialiasing" to avoid differences in the snapshots | ||
// depending on the used monitor. | ||
// See https://github.com/dferber90/jsdom-screenshot/issues/1 | ||
addArg(opts, "--disable-lcd-text"); | ||
|
||
return opts; | ||
}; |