@nightwatch/esbuild-utils
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "", | ||
@@ -17,4 +17,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/core": "^7.19.3", | ||
"esbuild": "^0.15.8", | ||
"lodash.merge": "^4.6.2" | ||
"lodash.merge": "^4.6.2", | ||
"lodash.mergewith": "^4.6.2" | ||
}, | ||
@@ -21,0 +23,0 @@ "devDependencies": { |
const fs = require('fs'); | ||
const path = require('path'); | ||
const {build, transform} = require('esbuild'); | ||
const merge = require('lodash.merge'); | ||
const mergeWith = require('lodash.mergewith'); | ||
const {pathToFileURL} = require('url'); | ||
const babel = require('./babel.js'); | ||
const ESBUILD_LOADERS = Object.freeze({ | ||
'.js': 'js', | ||
'.js': 'jsx', | ||
'.cjs': 'js', | ||
@@ -89,5 +93,41 @@ '.jsx': 'jsx', | ||
const buildFile = function(modulePath, additionalConfig = {}) { | ||
const config = merge({}, ESBUILD_CONFIG, additionalConfig); | ||
const ESBUILD_CONFIGS = ['esbuild.config.mjs', 'esbuild.config.js']; | ||
async function resolveExternalConfig() { | ||
for (const name of ESBUILD_CONFIGS) { | ||
if (fs.existsSync(name)) { | ||
try { | ||
const {default: values} = await import(pathToFileURL(path.resolve(name))); | ||
return values; | ||
} catch { | ||
continue; | ||
} | ||
} | ||
} | ||
return {}; | ||
} | ||
const buildFile = async function(modulePath, additionalConfig = {}) { | ||
const fileConfig = await resolveExternalConfig(); | ||
if (additionalConfig.babel) { | ||
additionalConfig.plugins = additionalConfig.plugins || []; | ||
additionalConfig.plugins.push( | ||
babel(typeof additionalConfig.babel === 'boolean' ? {} : additionalConfig.babel) | ||
); | ||
delete additionalConfig.babel; | ||
} | ||
mergeWith(fileConfig, additionalConfig, function customizer(objValue, srcValue) { | ||
if (Array.isArray(objValue)) { | ||
return objValue.concat(srcValue); | ||
} | ||
}); | ||
const config = merge({}, ESBUILD_CONFIG, fileConfig); | ||
return build({...config, entryPoints: [modulePath]}); | ||
@@ -94,0 +134,0 @@ }; |
@@ -91,3 +91,3 @@ const path = require('path'); | ||
const component = ${exportName === 'default' ? `${path.basename(modulePath, path.extname(modulePath)).replace(/-+/, '_')}_${exportName}` : exportName}; | ||
const component = module.exports["${exportName}"]; | ||
@@ -98,3 +98,3 @@ if (data.beforeMountError) { | ||
if (component.test) { | ||
if (component && component.test) { | ||
await Promise.resolve(component.test(browser, data)); | ||
@@ -128,4 +128,4 @@ } | ||
const component = ${exportName === 'default' ? `${path.basename(modulePath, path.extname(modulePath)).replace(/-+/, '_')}_${exportName}` : exportName}; | ||
if (component.test) { | ||
const component = module.exports["${exportName}"]; | ||
if (component && component.test) { | ||
return component.test(browser, data); | ||
@@ -180,4 +180,9 @@ } | ||
this.skipTestcasesOnFail = false; | ||
let testNamespace; | ||
try { | ||
componentDefault = ${path.basename(modulePath, path.extname(modulePath)).replace(/[^a-zA-Z0-9]+/g, '_')}_default; | ||
componentDefault = module.exports.default; | ||
if (componentDefault && componentDefault.test) { | ||
testNamespace = componentDefault.test; | ||
} | ||
@@ -187,22 +192,21 @@ before(async function(browser) { | ||
if (typeof componentDefault.before == 'function') { | ||
await componentDefault.before(browser); | ||
if (testNamespace && typeof testNamespace.before == 'function') { | ||
await testNamespace.before(browser); | ||
} | ||
}); | ||
if (typeof componentDefault.beforeEach == 'function') { | ||
beforeEach(componentDefault.beforeEach); | ||
if (testNamespace && typeof testNamespace.beforeEach == 'function') { | ||
beforeEach(testNamespace.beforeEach); | ||
} | ||
if (typeof componentDefault.afterEach == 'function') { | ||
afterEach(componentDefault.afterEach); | ||
if (testNamespace && typeof testNamespace.afterEach == 'function') { | ||
afterEach(testNamespace.afterEach); | ||
} | ||
after(async function(browser) { | ||
if (typeof componentDefault.after == 'function') { | ||
after(componentDefault.after); | ||
if (testNamespace && typeof testNamespace.after == 'function') { | ||
after(testNamespace.after); | ||
} | ||
}); | ||
} catch (err) { | ||
@@ -209,0 +213,0 @@ console.error('Error:', err); |
@@ -57,4 +57,4 @@ const path = require('path'); | ||
const data = result === null || result === void 0 ? {} : result; | ||
const component = Primary; | ||
if (component.test) { | ||
const component = module.exports["Primary"]; | ||
if (component && component.test) { | ||
return component.test(browser, data); | ||
@@ -101,7 +101,7 @@ } | ||
const data = mountResult || {}; | ||
const component = Primary; | ||
const component = module.exports["Primary"]; | ||
if (data.beforeMountError) { | ||
console.error(data.beforeMountError.message); | ||
} | ||
if (component.test) { | ||
if (component && component.test) { | ||
await Promise.resolve(component.test(browser, data)); | ||
@@ -115,3 +115,35 @@ } | ||
const describeBlock = `describe("Button.stories.jsx component", function() { | ||
let componentDefault; | ||
let cdpConnection; | ||
this.desiredCapabilities.pageLoadStrategy = "eager"; | ||
this.skipTestcasesOnFail = false; | ||
let testNamespace; | ||
try { | ||
componentDefault = module.exports.default; | ||
if (componentDefault && componentDefault.test) { | ||
testNamespace = componentDefault.test; | ||
} | ||
before(async function(browser) { | ||
if (testNamespace && typeof testNamespace.before == "function") { | ||
await testNamespace.before(browser); | ||
} | ||
}); | ||
if (testNamespace && typeof testNamespace.beforeEach == "function") { | ||
beforeEach(testNamespace.beforeEach); | ||
} | ||
if (testNamespace && typeof testNamespace.afterEach == "function") { | ||
afterEach(testNamespace.afterEach); | ||
} | ||
after(async function(browser) { | ||
if (testNamespace && typeof testNamespace.after == "function") { | ||
after(testNamespace.after); | ||
} | ||
}); | ||
} catch (err) { | ||
console.error("Error:", err); | ||
}`; | ||
assert.ok(text.includes(textToMatch)); | ||
assert.ok(text.includes(describeBlock)); | ||
}); | ||
@@ -118,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
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
26596
16
621
4
5
+ Added@babel/core@^7.19.3
+ Addedlodash.mergewith@^4.6.2
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.2(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedbrowserslist@4.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001684(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedelectron-to-chromium@1.5.64(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlodash.mergewith@4.6.2(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedyallist@3.1.1(transitive)