@nightwatch/esbuild-utils
Advanced tools
Comparing version 0.1.10 to 0.2.0
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
@@ -25,51 +25,56 @@ const path = require('path'); | ||
if (browserName.toLowerCase() === 'chrome' || browserName.toLowerCase() === 'msedge') { | ||
cdpConnection = await browser.driver.createCDPConnection('page'); | ||
cdpConnection._wsConnection.on('message', function(message) { | ||
try { | ||
const params = JSON.parse(message); | ||
if (params.method === 'Runtime.consoleAPICalled') { | ||
const consoleEventParams = params['params']; | ||
const {type, args} = consoleEventParams; | ||
if (args.length > 0 && args[0].type === 'string' && args[0].value.startsWith('%c')) { | ||
return; | ||
try { | ||
cdpConnection = await browser.driver.createCDPConnection('page'); | ||
cdpConnection._wsConnection.on('message', function(message) { | ||
try { | ||
const params = JSON.parse(message); | ||
if (params.method === 'Runtime.consoleAPICalled') { | ||
const consoleEventParams = params['params']; | ||
const {type, args} = consoleEventParams; | ||
if (args.length > 0 && args[0].type === 'string' && args[0].value.startsWith('%c')) { | ||
return; | ||
} | ||
const message = args.reduce((prev, item) => { | ||
if (item.type === 'string' || item.type === 'boolean' || item.type === 'number') { | ||
prev.push(item.value); | ||
} else if (item === undefined) { | ||
prev.push(undefined); | ||
} else if (item.type === 'object' || item.type === 'function') { | ||
prev.push(Logger.inspectObject({ | ||
[item.className]: item.description | ||
})); | ||
} | ||
return prev; | ||
}, []); | ||
if (typeof console[type] == 'function') { | ||
console[type](Logger.colors.light_cyan('[browser]'), ...message); | ||
} | ||
} | ||
const message = args.reduce((prev, item) => { | ||
if (item.type === 'string' || item.type === 'boolean' || item.type === 'number') { | ||
prev.push(item.value); | ||
} else if (item === undefined) { | ||
prev.push(undefined); | ||
} else if (item.type === 'object' || item.type === 'function') { | ||
prev.push(Logger.inspectObject({ | ||
[item.className]: item.description | ||
})); | ||
if (params.method === 'Runtime.exceptionThrown') { | ||
const exceptionEventParams = params['params']; | ||
const {exceptionDetails = {}, timestamp} = exceptionEventParams; | ||
const {exception} = exceptionDetails; | ||
if (exception && exception.description) { | ||
const stackParts = exception.description.split('\\n'); | ||
const errorTitle = stackParts.shift(); | ||
const stackTrace = stackParts.join('\\n'); | ||
console.error(Logger.colors.light_cyan('[browser]'), Logger.colors.light_red(errorTitle) + '\\n' + Logger.colors.stack_trace(stackTrace)); | ||
} | ||
return prev; | ||
}, []); | ||
if (typeof console[type] == 'function') { | ||
console[type](Logger.colors.light_cyan('[browser]'), ...message); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
if (params.method === 'Runtime.exceptionThrown') { | ||
const exceptionEventParams = params['params']; | ||
const {exceptionDetails = {}, timestamp} = exceptionEventParams; | ||
const {exception} = exceptionDetails; | ||
if (exception && exception.description) { | ||
const stackParts = exception.description.split('\\n'); | ||
const errorTitle = stackParts.shift(); | ||
const stackTrace = stackParts.join('\\n'); | ||
console.error(Logger.colors.light_cyan('[browser]'), Logger.colors.light_red(errorTitle) + '\\n' + Logger.colors.stack_trace(stackTrace)); | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
cdpConnection.execute('Runtime.enable', {}, null); | ||
}); | ||
cdpConnection.execute('Runtime.enable', {}, null); | ||
} catch (err) { | ||
} | ||
} | ||
@@ -83,5 +88,9 @@ `; | ||
const componentDefault = module.exports["default"]; | ||
if (componentDefault && componentDefault.preRender) { | ||
const component = module.exports["${exportName}"]; | ||
let preRender = component && component.preRender || componentDefault && componentDefault.preRender; | ||
let postRender = component && component.postRender || componentDefault && componentDefault.postRender; | ||
if (preRender) { | ||
try { | ||
await componentDefault.preRender(browser, { | ||
await preRender(browser, { | ||
id: '${additionalTestData.id}', | ||
@@ -99,3 +108,3 @@ name: '${exportName}', | ||
} | ||
const component = module.exports["${exportName}"]; | ||
const test = await Promise.resolve((${createTest.toString()})({ | ||
@@ -127,5 +136,5 @@ data: ${JSON.stringify({exportName, modulePath, ...additionalTestData})}, | ||
if (componentDefault && componentDefault.postRender) { | ||
if (postRender) { | ||
try { | ||
await componentDefault.postRender(browser, { | ||
await postRender(browser, { | ||
id: '${additionalTestData.id}', | ||
@@ -132,0 +141,0 @@ name: '${exportName}', |
18165
452