How to read gulp task names from command params? - command-line

I have the following code, which reads what task name I passed to gulp: release or test and decides what task group to load from the files based on that.
var argv = require('yargs').argv;
var group = argv._[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);
Isn't there a better way to get the commanded tasks from gulp itself instead of using yargs?

I found a great tutorial about tools for CLI. According to it I should use commander, so I do so. It is much better than yargs. Another possible solution to use process.argv[2] in this case, but it is much better to use a parser in long term.
var program = require("commander");
program.parse(process.argv);
var group = program.args[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);

Related

Iteration through RestAPI POST calls

I'm working with a private cloud platform that is used for creating and testing Virtual Machines. They have rich API which allows me to create VMs:
{
"name": "WIN2016-01",
"description": "This is a new VM",
"vcpus": 4,
"memory": 2147483648,
"templateUuid": "sdsdd66-368c-4663-82b5-dhsg7739smm",
...
}
I need to automate this process of creating machines by just simply iterating -01 part, so it becomes:
"name": "WIN2016-01",
"name": "WIN2016-02",
"name": "WIN2016-03"
etc.
I tried to use Postman Runner and build the workflow https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/ but with no luck - not sure what syntax I need to use in Tests tab.
This is one way of doing it.
Create a collection and your POST request.
In your pre-request, add the following:
/* As this will be run through the Collection Runner, this extracts
the number of the current iteration. We're adding +1, as the iteration starts from 0.*/
let count = Number(pm.info.iteration) + 1;
//Convert the current iteration number, to a '00' number format (will be a string)
let countString = ((count) < 10) ? '0' + count.toString() :
count.toString();
//Set an environment variable, which can be used anywhere
pm.environment.set("countString", countString)
In your POST request body, do something like this:
{
"name": "WIN2016-{{countString}}",
...
}
Now, run your collection through the 'Collection Runner', and enter the number of Iterations (e.g. how many times you want your collection to run). You can also add a Delay, if your API imposes rate limits.
Finally, click Run.

Running Protractor cucumber in parallel with consolidated report

This may sound duplicate but it is not.
I know that I can use the below configuration in config file and start multiple instance of the chrome driver that would run the features in parallel that share the step definitions.
capabilities: {
'browserName': 'chrome',
'shardTestFiles': true,
'maxInstances': 0
},
Q1. But my question is around why the chromedriver doesn't exit when a scenario fails?(That happens only when I use value of maxInstance > 0 ).
The chromedriver exit with exitcode- 3 and exitcode- 1.
Q2. Is anyone able to sort out the reporting issue? How can I generate the report when all the features have finished?
Any sort of help will be appreciated?
Thanks
In order to generate the consolidated html report after parallel run,I have used afterLaunch parameter in the protractor.conf.js file and have used https://github.com/gkushang/cucumber-html-reporter. Below is the code-
afterLaunch: function afterLaunch () {
var cucumberHtmlReporter = require('cucumber-html-reporter');
var jsonReportFolder = '/path/to/all/json/reports';
var cucumberhtmlReport = path.join(jsonReportFolder, cucumber.html');
var options = {
theme: 'bootstrap',
jsonDir: jsonReportFolder,
output: cucumberhtmlReport,
reportSuiteAsScenarios: true,
launchReport: true
};
cucumberHtmlReporter.generate(options);
}
The existing behavior is correct.Do not use 'maxInstances': 0
The default value is 1 and any value>1 is the right way to do it. The error that you are seeing is because thats how the source code - taskScheduler
They are handling shard tests in this taskScheduler exports and logic of maxinstances is as below
this.maxInstance = capabilities.maxInstances || 1;
/**
* Get maximum number of concurrent tasks required/permitted.
*
* #return {number}
*/
count += Math.min(queue.maxInstance, queue.specLists.length);
So if you have maxInstances 0, It will cause problems and your code will never exit cleanly. Also I dont think your code will run in parallel
What I would suggest is
Check your protractor version and update to latest
Change your config file to - 'maxInstances': 3 //anything greater than 1. 1 is default

command line arguments make file

So I know how to create variables and store values from command line.
But normally, I would type my command this way: make run VAR="abc", and VAR will be assigned the new value "abc"
However, if I want to do something like this VAR="abc" make run, how can I change my make file? Right now, if I run this, VAR still has the initial value when it was created in the make file.
This is my make file:
VAR = ""
.PHONY : build run
build : program.c
gcc -o prog -g program.c
run : build
./prog $(VAR)
When you write VAR = "", you're overwriting any value VAR might have had (e.g. from the environment, or the command line). You can use a conditional assignment instead, which looks like this:
VAR ?= ""
This sets VAR only if it wasn't set already. It's equivalent to e.g.
ifeq ($(origin VAR), undefined)
VAR = ""
endif
VAR = ${VAR}
if i remember right

Why doesn't karma-cli accept files as command line argument?

I'm using the config from my project but would like to run karma just for one specific test script one time. I don't want to have to create a whole new config file just for this case and would prefer just passing in the script I want run (so basically telling karma to use files: ['myTest.js'].
But there don't seem to be any options for that AFAICT in the docs. Why would this be missing? It seems like a fundamental feature IMO.
in karma.conf something like that:
function mergeFilesWithArgv(staticFiles) {
var source = staticFiles, argv = process.argv;
argv.forEach(function (arg) {
var index = arg.indexOf('--check=');
if (index !== -1) {
source.push(arg.substring(8));
}
});
return source;
}
config.set({
...
files: mergeFilesWithArgv([
'js_src/tests/*.test.js'
]),
...
});
use: karma start --check='./path/to/file.js'
or for multiple files: karma start --check='./path/to/file.js' --check='/another/path/to/another/file.js'

error .match expression results null

I am working on a mail merge script. I have used Logger.log to find out that the error is in the expression that tells match what to find. In my case I am trying to pull all the keys that are inside ${xxxxxxx}. Below is what I have and I need help cleaning it up because at this point it returns null.
var template = "This is an example ${key1} that should pull ${key2} both keys from this text."
var templateVars = template.match(/\$\{\"[^\"]+\"\}/g);
Thanks for any guidance anyone can share on this problem.
-Sean
I am not really familiarized with Google Apps Script, but I think this code in Javascript can help you.
It looks for all the ocurences of ${key} and returns each value inside the ${ }. I think that is what you are looking for.
var template = "This is an example ${key1} that should pull ${key2} both keys from this text.";
var matches = template.match(/\$\{[0-9a-zA-Z]*\}/mg);
console.log(matches);
for ( var i = 0; i < matches.length; i++ ) {
console.log(matches[i].replace(/[\$\{|\}]/gm, ""));
}