Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nightwatch/esbuild-utils

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nightwatch/esbuild-utils - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

5

package.json

@@ -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": {

8

src/esbuild.js
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);
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc