@nightwatch/esbuild-utils
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -17,3 +17,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"esbuild": "^0.15.8" | ||
"esbuild": "^0.15.8", | ||
"lodash.merge": "^4.6.2" | ||
}, | ||
@@ -20,0 +21,0 @@ "devDependencies": { |
const fs = require('fs'); | ||
const {build, transform} = require('esbuild'); | ||
const merge = require('lodash.merge'); | ||
@@ -31,2 +32,3 @@ const ESBUILD_LOADERS = Object.freeze({ | ||
loader: ESBUILD_LOADERS, | ||
outdir: './out', | ||
bundle: true, | ||
@@ -87,4 +89,6 @@ target: 'node12', | ||
const buildFile = function(modulePath) { | ||
return build({...ESBUILD_CONFIG, entryPoints: [modulePath]}); | ||
const buildFile = function(modulePath, additionalConfig = {}) { | ||
const config = merge({}, ESBUILD_CONFIG, additionalConfig); | ||
return build({...config, entryPoints: [modulePath]}); | ||
}; | ||
@@ -91,0 +95,0 @@ |
@@ -5,5 +5,5 @@ const transform = require('./transform.js'); | ||
module.exports = async function (modulePath, options) { | ||
module.exports = async function (modulePath, options, argv) { | ||
const code = await transform(modulePath, options); | ||
const code = await transform(modulePath, options, argv); | ||
const virtualFilePath = getVirtualFilePath(modulePath); | ||
@@ -10,0 +10,0 @@ |
@@ -5,6 +5,6 @@ const path = require('path'); | ||
const itFnAsync = function({name, exportName, createTest, modulePath, additionalTestData, modulePublicUrl}) { | ||
const itFnAsync = function({name, exportName, createTest, onlyConditionFn = function() {}, modulePath, additionalTestData, modulePublicUrl}, argv) { | ||
return ` | ||
it('${typeof name === 'string' ? name : name(exportName)}', async function (browser) { | ||
it${addOnly(onlyConditionFn, {name, exportName, modulePath, modulePublicUrl}, argv)}('${typeof name === 'string' ? name : name(exportName)}', async function (browser) { | ||
const test = await Promise.resolve((${createTest.toString()})({ | ||
@@ -17,4 +17,4 @@ data: ${JSON.stringify({exportName, modulePath, ...additionalTestData})}, | ||
const result = await Promise.resolve(test(browser)); | ||
const data = result === null || result === undefined ? {} : result; | ||
const element = await Promise.resolve(test(browser)); | ||
const data = element === null || element === undefined ? {} : {component: element}; | ||
@@ -34,6 +34,10 @@ const component = ${ | ||
const itFn = function({name, exportName, createTest, modulePath, additionalTestData, modulePublicUrl}) { | ||
const addOnly = function(conditionFn, options, argv) { | ||
return conditionFn(options, argv) ? '.only': ''; | ||
}; | ||
const itFn = function({name, exportName, createTest, modulePath, onlyConditionFn = function() {}, additionalTestData, modulePublicUrl}, argv) { | ||
return ` | ||
it('${typeof name === 'string' ? name : name(exportName)}', function (browser) { | ||
it${addOnly(onlyConditionFn, {name, exportName, modulePath, modulePublicUrl}, argv)}('${typeof name === 'string' ? name : name(exportName)}', function (browser) { | ||
const test = ((${createTest.toString()})({ | ||
@@ -65,4 +69,8 @@ data: ${JSON.stringify({exportName, modulePath, ...additionalTestData})}, | ||
* @param {Object} description | ||
* @param {Object} argv | ||
* @param {Object} nightwatch_settings | ||
*/ | ||
module.exports = async function (modulePath, {name, data, exports, createTest}) { | ||
module.exports = async function (modulePath, {name, data, exports, createTest, transformCode = (code) => code, onlyConditionFn}, { | ||
argv = {}, nightwatch_settings = {} | ||
}) { | ||
if (typeof createTest != 'function') { | ||
@@ -73,3 +81,2 @@ throw new Error('createTest function must be defined.'); | ||
const isCreateTestAsync = createTest.constructor.name === 'AsyncFunction'; | ||
const virtualFilePath = getVirtualFilePath(modulePath); | ||
@@ -83,16 +90,41 @@ const modulePublicUrl = modulePath.replace(process.cwd(), '').split(path.sep).join('/'); | ||
? allModuleExports | ||
: allModuleExports.filter((name) => name !== 'default'); | ||
: allModuleExports.filter((innerName) => innerName !== 'default'); | ||
const {outputFiles: [{text}]} = await buildFile(modulePath); | ||
const additionalTestData = typeof data === 'function' ? await data() : data; | ||
const result = await buildFile(modulePath, nightwatch_settings.esbuild || {}); | ||
const {outputFiles: [{text}]} = result; | ||
const createItFn = function(isCreateTestAsync) { | ||
return function(opts) { | ||
return isCreateTestAsync ? itFnAsync(opts): itFn(opts); | ||
const testItems = exportNames.map((exportName) => { | ||
const additionalTestData = data(exportName); | ||
const opts = { | ||
exportName, name, createTest, additionalTestData, modulePath, onlyConditionFn, modulePublicUrl | ||
}; | ||
}; | ||
return isCreateTestAsync ? itFnAsync(opts, argv): itFn(opts, argv); | ||
}); | ||
const describeFn = `describe('${path.basename(modulePath)} component', function () { | ||
${exportNames.map((exportName) => createItFn(isCreateTestAsync)({exportName, name, createTest, additionalTestData, modulePath, modulePublicUrl})).join('\n')} | ||
});`; | ||
let componentDefault; | ||
this.skipTestcasesOnFail = false; | ||
try { | ||
componentDefault = ${path.basename(modulePath, path.extname(modulePath)).replace(/\./g, '_')}_default; | ||
if (typeof componentDefault.before == 'function') { | ||
before(componentDefault.before); | ||
} | ||
if (typeof componentDefault.beforeEach == 'function') { | ||
beforeEach(componentDefault.beforeEach); | ||
} | ||
if (typeof componentDefault.afterEach == 'function') { | ||
afterEach(componentDefault.afterEach); | ||
} | ||
if (typeof componentDefault.after == 'function') { | ||
after(componentDefault.after); | ||
} | ||
} catch (err) { | ||
console.error('Error:', err); | ||
} | ||
${testItems.join('\n')} | ||
}); | ||
`; | ||
@@ -105,3 +137,3 @@ const {code} = await transformFile(` | ||
return code; | ||
return transformCode(code); | ||
}; |
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
19761
441
2
+ Addedlodash.merge@^4.6.2
+ Addedlodash.merge@4.6.2(transitive)