Print spec reporter output to file in WebdriverIO? - node.js

I'm trying to find a way to print spec reporter output to a text file once the test suite is complete. I'm using WebdriverIO but none of the completion callbacks seem to provide any access to the actual report output. There's also no documentation on any config variable you can pass in to set a file output. There an outputDir option but it only writes the log before the actual report to the selected location.

My solution was to use tee to write all output of the test suite to a file and stdout. The report is then contained at the end of the file.
./node_modules/.bin/wdio wdio.conf.js | tee test-report.txt
For running individual tests run:
./node_modules/.bin/wdio wdio.conf.js -- --spec <Spec File Name> | tee test-report.txt

Related

lcov | using --summary and --remove

I use lcov --summary output as an input to some program,
So far i didn't need the --remove option so i only used:
lcov --summary "$my_trace_file"
and the output was of the following form:
Reading tracefile /local/home/......
Summary coverage rate:
lines......: 18.9% (61703 of 327102 lines)
functions..: 4.2% (12308 of 296143 functions)
branches...: no data found
Now i need to filter some test files from the out so I used:
lcov --remove "$my_trace_file" "*src/testfiles/*" alon with other patterns.
However now the output is different:
it composed a lot of lines of the form:
TN:
SF:/local/home/....
FN:21,_ZN3EBS22...
FN:31,_ZNK3EBS22
FN:36,_ZNK3EBS22
FN:41,_ZNK3EBS22
FN:46,_ZNK3EBS22
FN:51,_ZN3EBS22
FN:56,_ZN3EBS22
FN:61,_ZN3EBS22
FN:68,_sdfdsfds
FN:76,_edfsdfd
.
.
.
.
...
and
....
Removing /local/home/.....
Removing /local/home/.....
Summary coverage rate:
lines......: 19.2% (61703 of 320880 lines)
functions..: 17.1% (12308 of 72152 functions)
branches...: no data found
Apparently the first part is for stdout and the other for stderr.
however, the program must get all of it through stdout preferably at the regular form as the --summary without any additional data.
What i essentially asking is a way to tell lcov to use --remove but to print only the summary data, and to print it to stdout.
I tried to use both of the options but i got an error saying they are mutually exclusive.
(I know i can use redirection for stderr, but currently it consumed by some other code that only use stdout)
Update: I have tried to play it a little, just to get how it works and redirected the output with > my_file 2>&1 however i got a weird thing:
The redirection order is got mixed: first a some messages of stdout, then stderr and then stdout again, so what im getting is an unordered result. If i run it on the bash itself, i get the right order (that's, the lines:
lines......: 19.2% (61623 of 320880 lines)
functions..: 17.0% (12301 of 72152 functions)
branches...: no data found
are at the end of the output as opposed to the output file, there those lines are in the middle).
Im not sure if solving this will help me since basically I need to use it all with stout but i'd like to understand why this weird thing happens. Thanks

String method tutorial in abinit - no output file produced

I'm trying to follow this tutorial in abinit: https://docs.abinit.org/tutorial/paral_images/
When trying to run abinit for any of the tstring files, no output file is produced. For instance, I copy the files tstring_01.in and tstring.files into the subdirectory work_paral_string, edit the tstring.files with the appropriate file names, and run the command mpirun -n 20 abinit < tstring.files > log 2> err. No error message is shown but also no output is produced. (The expected output file would be tstring_01.out.)
Any suggestions?

Is it possible to take a log of whole script?

I have deployed a post-receive hook script and I want to get whole output logs in a file as a block starting with date. I have tried one method but it take line by line log, meaning I have to put that command against every line to get the log. Is there any way to get the whole script log once starting with date?
Script file looks like this:
#!/bin/bash
any_command | ts '[%F %T]' >> /home/Man/Man_log.log
second_command | ts '[%F %T]' >> /home/Man/Man_log.log
third_command | ts '[%F %T]' >> /home/Man/Man_log.log
see i have to put this line | ts '[%F %T]' >> /home/Man/Man_log.log against every command to get log. And I have 90 lines, so it is not a perfect way to do this. I need an efficient way, like only one line in my script which takes the output of the whole script as log and stores it to another Man_log.log file starting with the date.
What i want is similar to this.
#!/bin/bash
ts '[%F %T]' >> /home/Man/Man_log.log #a command which can store logs of every command below this to a separate file starting with date
any_command
second_command
third_command
Probably the easiest way would be to modify your script to print the date everytime is called:
#!/bin/sh
date -u +"%Y-%m-%dT%H:%M:%SZ"
# your commands below
...
if you can't modify the script then you could group your commands for example:
(date && anycommand) >> out.log
Grouping a (list of commands) in parenthesis causes them to be executed as if they were a single unit. "sub-shell"
Let's say this is the script that should give us some logs:
#!/bin/bash
echo "log_line1
log_line2
log_line3
log_line4"
And let's call it script.sh.
Running it as ./script.sh | printf "%(%F)T {\n$(cat)\n}" >> Man_log.log, content of Man_log.log will be:
2018-05-04 {
log_line1
log_line2
log_line3
log_line4
}
Let me now explain what exactly the pipe does.
%(%F)T is replaced with current date in YEAR-MONTH-DAY format
$(cat) are the logs that are output of ./script.sh. In general it is data received as standard input.
Basically ./script.sh writes it's logs to standard output. The pipe then passes that standard output to standard input of echo. Running cat without parameters is the same as cat /dev/stdin.

Tell Mocha where to look for test files

How can I tell Mocha where to look for my test files? My test files dont reside in the standard project root ./test folder. My test sit in Modules/.*/Tests/.
I've attempted to use the --grep command line argument but I have a feeling this argument looks for test NAMES not for test FILE NAMES.
mocha --grep Modules\/.*\/Tests
The above command gives the error:
Warning: Could not find any test files matching pattern: test
No test files found
You have to match not only directory but also its files . Besides, do no need grep , use only -- :
mocha -- Modules/**/Tests/*.js
// or `mocha -- Modules/Tests/*.js` (I am not sure because you didn't give the project hierarchy )

Write console output to a file

I want to collect and write the CONSOLE output to a file.
Actually, the output need to be displayed on CONSOLE as well.
I tried below code just to get each line buffer of CONSOLE but it's not correct:
while(!feof(stdout))
{
fgets(szReadBuff, sizeof(szReadBuff), stdout);
// Then write szReadBuff to a created file
...
}
Anyone can help me?
A simple way would be to run ./myprogram | tee output.txt from your shell. tee is a utility that allows you to write to both standard output and one or more files.

Resources