How to do conditional requirements for browserify? - browserify

I have some code that I'm compiling with Browserify. How can i create conditional requirements,
for example
const Worker = (node === true) ? require('tiny-worker') || window.Worker

The best answer I could find is to use browserify-shim
https://www.npmjs.com/package/browserify-shim

Related

How to implement conditional When method in Karate

I would like to reuse a feature both for POST-ing and PUT-ing a JSON Object. In order to achieve that I am trying to use a condition in the call:
Given param admin = admin
And request role
When method (role.id == null) ? karate.POST : karate.PUT
The error I get:
no step-definition method match found for: method (role.id == null) ? karate.POST : karate.PUT
I checked the documentation and the examples and search for the solution here, but I did not find an answer to this question.
Thanks in advance for the help.
You can use a variable for the method step:
* def action = 'GET'
* url 'https://httpbin.org/get'
* method action
Other than that I have no suggestions. I strongly advise you to not do this kind of "re-use" as it leads to un-readable and un-maintainable tests. Please read this once: https://stackoverflow.com/a/54126724/143475

Syntax to check more than one condition on exclusive gateway using kiefunctions

I am trying to check more than one conditions to redirect the flow on an exclusive gateway using kiefunctions JavaScript in jbpm. I am using the below syntax but I think I might be using the wrong syntax
return Kiefunctions.isTrue(customer.isValid) && customer.status == “retired” || customer.status == “employed”;
Can someone suggest me the correct syntax please
Probably KieFunctions is not written correctly (case-sensitive)
Try this and share the result:
return KieFunctions.isTrue(customer.isValid) && (KieFunctions.equalsTo(customer.status, "retired") || KieFunctions.equalsTo(customer.status, "employed"));

Cucumber Ordered Tagged Hooks

I am trying to use an ordered, tagged hook using Java cucumber. For example:
#Before("#quicklink", order = 20)
The compiler doesn't seem to like it. Is it not possible to have an ordered, tagged hook ? Seems like a reasonable combination of functionality. If so, what is the syntax ?
thnx
I have tried the same but in a different way
#Before(value = "#quicklink", order = 20)
But, this may create odd issues if you have another hook method with the same order number for other tests. Like both the methods will run for this scenario.
So I suggest using the tagged expressions if you are using same order like as follows:
For other methods use
#Before(value = "~#quicklink", order = 20)
this will make sure this scenario will never run on other methods
and for this scenario alone,
#Before(value = "#quicklink", order = 20)
this will make sure the above method will never run for those.
If you are using 2x version of tagged expressions in your project, you can replace the '~' with a 'not'
This might come handy if you want to replace a method in hooks class in just a specific scenario.
#Before(value = "#quicklink", order = 20)
You should be able to specify the order for hooks like this:
Annotated method style (if you are using cucumber-java):
#Before(order = 10)
public void doSomething(){
// Do something before each scenario
}
Lambda style (if you are using cucumber-java8):
Before(10, () -> {
// Do something before each scenario
});

How to check if two paths are the same in npm?

In npm path module, people use path.join because it handles cross platform slashes and extra slashes. However, is there a way to compare two paths to see if its the same folder in a cross platform way?
I want to avoid situations where it ends up comparing /foo/bar to \foo\bar and says its not the same but it really is.
Thanks
I've solved this by using path.resolve on both the paths I want to compare. This makes paths absolute against process.cwd() and solves the backslash/forwardslash issue. It also resolves ../../a/b/ paths.
The other answer doesn't take into account that paths on win32, unlike most other platforms, are case-insensitive. The following should do the trick:
function pathsAreEqual(path1, path2) {
path1 = path.resolve(path1);
path2 = path.resolve(path2);
if (process.platform == "win32")
return path1.toLowerCase() === path2.toLowerCase();
return path1 === path2;
}
Testing:
path.resolve("C:\\Users\\user") == path.resolve("C:\\Users\\USER") // false
pathsAreEqual("C:\\Users\\user", "C:\\Users\\USER") // true

include multiple js files using Ti.include function

I can include 1 js file with Ti.include like:
Ti.include("login.js")
But, i am having problem with including multiple js files.
As a work around, i write Ti.include multiple times, which is less readable.
Any idea, how to achieve that?
Tweetanium does it like so:
Ti.include(
'/tweetanium/ui/ui.js',
'/tweetanium/model/model.js',
'/tweetanium/config/config.js'
);
Generally we should avoid including js file. It will hamper performance. You can have common js functionality to call any function defined in other files..
var All = require('ui/common/All');
Tree = require('ui/common/Tree');
EBOM = require('ui/common/E-BOM');
MBOM = require('ui/common/M-BOM');
SBOM = require('ui/common/S-BOM');