salix/e2e/helpers/nightmare.js

26 lines
620 B
JavaScript
Raw Normal View History

2019-02-06 15:08:23 +00:00
const Nightmare = require('nightmare');
2019-01-23 14:34:16 +00:00
let nightmare;
2019-02-06 15:08:23 +00:00
module.exports = function createNightmare(width = 1280, height = 720) {
2019-01-23 14:34:16 +00:00
if (nightmare)
return nightmare;
nightmare = new Nightmare({
2019-01-21 14:21:24 +00:00
show: process.env.E2E_SHOW,
typeInterval: 10,
x: 0,
y: 0,
waitTimeout: 2000
}).viewport(width, height);
2019-01-21 14:21:24 +00:00
nightmare.on('console', (type, message, ...args) => {
2018-11-21 15:59:09 +00:00
if (type === 'error')
2019-01-22 14:55:58 +00:00
throw new Error(message);
2019-01-21 14:21:24 +00:00
else
console[type](message, ...args);
});
nightmare.header('Accept-Language', 'en');
return nightmare;
2019-02-06 15:08:23 +00:00
};