@nightwatch/esbuild-utils
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
@@ -5,2 +5,57 @@ const path = require('path'); | ||
const getBrowserConsoleCode = ` | ||
const {Logger} = require('nightwatch'); | ||
const {browserName = ''} = browser.capabilities; | ||
if (browserName.toLowerCase() === 'chrome') { | ||
const 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') { | ||
prev.push(item.value); | ||
} else if (item.type === 'object') { | ||
prev.push(Logger.inspectObject({ | ||
[item.className]: item.description | ||
})); | ||
} | ||
return prev; | ||
}, []); | ||
if (typeof console[type] == 'function') { | ||
console[type](Logger.colors.light_cyan('[browser]'), ...message); | ||
} | ||
} | ||
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); | ||
} | ||
`; | ||
const itFnAsync = function({name, exportName, createTest, onlyConditionFn = function() {}, modulePath, additionalTestData, modulePublicUrl}, argv) { | ||
@@ -17,4 +72,4 @@ return ` | ||
const element = await Promise.resolve(test(browser)); | ||
const data = element === null || element === undefined ? {} : {component: element}; | ||
const mountResult = await Promise.resolve(test(browser)); | ||
const data = mountResult || {}; | ||
@@ -26,3 +81,2 @@ const component = ${ | ||
}; | ||
if (component.test) { | ||
@@ -72,3 +126,3 @@ await Promise.resolve(component.test(browser, data)); | ||
*/ | ||
module.exports = async function (modulePath, {name, data, exports, createTest, transformCode = (code) => code, onlyConditionFn}, { | ||
module.exports = async function (modulePath, {name, data, showBrowserConsole = false, exports, createTest, transformCode = (code) => code, onlyConditionFn}, { | ||
argv = {}, nightwatch_settings = {} | ||
@@ -97,3 +151,3 @@ }) { | ||
const opts = { | ||
exportName, name, createTest, additionalTestData, modulePath, onlyConditionFn, modulePublicUrl | ||
exportName, name, showBrowserConsole, createTest, additionalTestData, modulePath, onlyConditionFn, modulePublicUrl | ||
}; | ||
@@ -104,2 +158,3 @@ | ||
const browserConsoleCode = showBrowserConsole ? getBrowserConsoleCode: ''; | ||
const describeFn = `describe('${path.basename(modulePath)} component', function () { | ||
@@ -111,5 +166,10 @@ let componentDefault; | ||
if (typeof componentDefault.before == 'function') { | ||
before(componentDefault.before); | ||
} | ||
before(async function(browser) { | ||
${browserConsoleCode} | ||
if (typeof componentDefault.before == 'function') { | ||
await componentDefault.before(browser); | ||
} | ||
}); | ||
if (typeof componentDefault.beforeEach == 'function') { | ||
@@ -116,0 +176,0 @@ beforeEach(componentDefault.beforeEach); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21898
491