2019-02-06 15:08:23 +00:00
|
|
|
const Nightmare = require('nightmare');
|
2019-10-15 14:19:35 +00:00
|
|
|
const config = require('./config.js');
|
|
|
|
|
2019-01-23 14:34:16 +00:00
|
|
|
let nightmare;
|
2017-09-10 18:04:22 +00:00
|
|
|
|
2019-11-28 11:54:34 +00:00
|
|
|
module.exports = function createNightmare(width = 1280, height = 800) {
|
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,
|
2019-10-14 06:25:04 +00:00
|
|
|
waitTimeout: 2000,
|
2019-11-11 15:32:03 +00:00
|
|
|
// openDevTools: {mode: 'detach'}
|
2019-01-21 14:21:24 +00:00
|
|
|
}).viewport(width, height);
|
2017-09-10 18:04:22 +00:00
|
|
|
|
2019-01-21 14:21:24 +00:00
|
|
|
nightmare.on('console', (type, message, ...args) => {
|
2019-08-13 09:48:00 +00:00
|
|
|
if (type === 'error') {
|
|
|
|
console[type](message, ...args);
|
2019-01-22 14:55:58 +00:00
|
|
|
throw new Error(message);
|
2019-08-13 09:48:00 +00:00
|
|
|
} else
|
2019-01-21 14:21:24 +00:00
|
|
|
console[type](message, ...args);
|
2017-09-10 18:04:22 +00:00
|
|
|
});
|
2018-10-24 08:57:14 +00:00
|
|
|
|
|
|
|
nightmare.header('Accept-Language', 'en');
|
2019-10-15 14:19:35 +00:00
|
|
|
return nightmare.goto(config.url);
|
2019-02-06 15:08:23 +00:00
|
|
|
};
|