@nightwatch/esbuild-utils
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "", | ||
@@ -14,3 +14,8 @@ "main": "index.js", | ||
}, | ||
"author": "", | ||
"author": "Andrei Rusu", | ||
"files": [ | ||
"src", | ||
"LICENSE.md", | ||
"index.js" | ||
], | ||
"license": "MIT", | ||
@@ -17,0 +22,0 @@ "dependencies": { |
@@ -81,2 +81,19 @@ const path = require('path'); | ||
it${addOnly(onlyConditionFn, {name, exportName, modulePath, modulePublicUrl}, argv)}('${typeof name === 'string' ? name : name(exportName)}', async function (browser) { | ||
const componentDefault = module.exports["default"]; | ||
if (componentDefault && componentDefault.preRender) { | ||
try { | ||
await componentDefault.preRender(browser, { | ||
id: '${additionalTestData.id}', | ||
name: '${exportName}', | ||
title: '${additionalTestData.name}' | ||
}); | ||
} catch (err) { | ||
const error = new Error('► preRender test hook threw an error for "${additionalTestData.name}" story:'); | ||
error.detailedErr = err.stack; | ||
error.stack = err.stack; | ||
throw error; | ||
} | ||
} | ||
const component = module.exports["${exportName}"]; | ||
const test = await Promise.resolve((${createTest.toString()})({ | ||
@@ -92,4 +109,2 @@ data: ${JSON.stringify({exportName, modulePath, ...additionalTestData})}, | ||
const component = module.exports["${exportName}"]; | ||
if (data.beforeMountError) { | ||
@@ -100,3 +115,7 @@ console.error(data.beforeMountError.message); | ||
if (component && component.test) { | ||
await Promise.resolve(component.test(browser, data)); | ||
if (data.component instanceof Error) { | ||
throw data.component; | ||
} else { | ||
await Promise.resolve(component.test(browser, data)); | ||
} | ||
} | ||
@@ -107,2 +126,18 @@ | ||
} | ||
if (componentDefault && componentDefault.postRender) { | ||
try { | ||
await componentDefault.postRender(browser, { | ||
id: '${additionalTestData.id}', | ||
name: '${exportName}', | ||
title: '${additionalTestData.name}' | ||
}); | ||
} catch (err) { | ||
const error = new Error('► postRender test hook threw an error for "${additionalTestData.name}" story:'); | ||
error.detailedErr = err.stack; | ||
error.stack = err.stack; | ||
throw error; | ||
} | ||
} | ||
} | ||
@@ -116,23 +151,2 @@ );`; | ||
const itFn = function({name, exportName, createTest, modulePath, onlyConditionFn = function() {}, additionalTestData, modulePublicUrl}, argv) { | ||
return ` | ||
it${addOnly(onlyConditionFn, {name, exportName, modulePath, modulePublicUrl}, argv)}('${typeof name === 'string' ? name : name(exportName)}', function (browser) { | ||
const test = ((${createTest.toString()})({ | ||
data: ${JSON.stringify({exportName, modulePath, ...additionalTestData})}, | ||
publicUrl: "${modulePublicUrl}", | ||
modulePath: "${modulePath}", | ||
exportName: "${exportName}", | ||
})); | ||
const result = test(browser); | ||
const data = result === null || result === undefined ? {} : result; | ||
const component = module.exports["${exportName}"]; | ||
if (component && component.test) { | ||
return component.test(browser, data); | ||
} | ||
});`; | ||
}; | ||
/** | ||
@@ -147,3 +161,3 @@ * Creates a virtual test file | ||
module.exports = async function (modulePath, {name, data = () => {}, showBrowserConsole = false, exports, createTest, transformCode = (code) => code, onlyConditionFn}, { | ||
argv = {}, nightwatch_settings = {} | ||
argv = {}, nightwatch_settings = {}, metadata = {} | ||
} = {}) { | ||
@@ -154,3 +168,2 @@ if (typeof createTest != 'function') { | ||
const isCreateTestAsync = createTest.constructor.name === 'AsyncFunction'; | ||
const virtualFilePath = getVirtualFilePath(modulePath); | ||
@@ -175,3 +188,3 @@ const modulePublicUrl = modulePath.replace(process.cwd(), '').split(path.sep).join('/'); | ||
return isCreateTestAsync ? itFnAsync(opts, argv): itFn(opts, argv); | ||
return itFnAsync(opts, argv); | ||
}); | ||
@@ -189,13 +202,21 @@ | ||
componentDefault = module.exports.default; | ||
if (componentDefault && componentDefault.test) { | ||
testNamespace = componentDefault.test; | ||
if (componentDefault && componentDefault.parameters) { | ||
testNamespace = componentDefault.parameters; | ||
} | ||
before(async function(browser) { | ||
${browserConsoleCode} | ||
before(async function(browser) { | ||
${browserConsoleCode} | ||
if (testNamespace && typeof testNamespace.before == 'function') { | ||
await testNamespace.before(browser); | ||
} | ||
}); | ||
if (componentDefault && componentDefault.setup) { | ||
try { | ||
await componentDefault.setup(browser); | ||
} catch (err) { | ||
const error = new Error('► setup test hook threw an error:'); | ||
error.detailedErr = err.stack; | ||
error.stack = err.stack; | ||
throw error; | ||
} | ||
} | ||
}); | ||
@@ -211,7 +232,14 @@ if (testNamespace && typeof testNamespace.beforeEach == 'function') { | ||
after(async function(browser) { | ||
if (testNamespace && typeof testNamespace.after == 'function') { | ||
after(testNamespace.after); | ||
} | ||
if (componentDefault && componentDefault.teardown) { | ||
try { | ||
await componentDefault.teardown(browser); | ||
} catch (err) { | ||
const error = new Error('► teardown test hook threw an error:'); | ||
error.detailedErr = err.stack; | ||
error.stack = err.stack; | ||
throw error; | ||
} | ||
} | ||
}); | ||
} catch (err) { | ||
@@ -218,0 +246,0 @@ console.error('Error:', err); |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
1
17796
10
445