-
Notifications
You must be signed in to change notification settings - Fork 18
/
options.js
47 lines (36 loc) · 1.24 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
};