How to prevent jest to show fail test details on summary - jestjs

When I run my tests with jest and some of them fails for each item failed I get a list like this:
FAIL src/app/models/item.model.spec.ts
● Item› #getItem › do stuff
expect(received).toBeFalsy()
Received: true
293 |
294 | test('do stuff', () => {
> 295 | expect(true).toBeFalsy();
| ^
296 | });
297 | });
298 | });
at src/app/models/item.model.spec.ts:295:20
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:391:26)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/proxy.js:129:39)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:390:52)
at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/dist/zone.js:150:43)
at Object.testBody.length (node_modules/jest-preset-angular/zone-patch/index.js:52:27)
which is the same info that I get above when the test first failed. In the case when a suite is really big and something breaks all their tests (or in more than one file) is really impossible to read that list because the details are always between the FAIL title and test names.
Is there a way to do jest to print a compact Failed Tests summary like this?
FAIL src/app/models/item.model.spec.ts
● Item› #getItem › do stuff
● Item› #getItem › do another Stuff
FAIL src/app/models/loader.model.spec.ts
● Loader> #loadSomething › be cool
● Loader› #loadAnything › be cooler
So if I want to read the fail details I can just scroll up or filter the failed test in my next run.

Related

In search of the mysterious skipped Jest test

We have the following output at the end of our Jest test base:
Test Suites: 273 passed, 273 total
Tests: 1 skipped, 1923 passed, 1924 total
Snapshots: 61 passed, 61 total
Time: 38.885 s, estimated 39 s
You see there is one skipped test.
When I search my test files either for it.skip or test.skip or generally skip I find nothing.
What I also tried is outputting the test run into JSON via:
jest --json --outputFile=testrun.json
In the top of the file I find this information:
{
"numFailedTestSuites": 0,
"numFailedTests": 0,
"numPassedTestSuites": 273,
"numPassedTests": 1923,
"numPendingTestSuites": 0,
"numPendingTests": 1,
"numRuntimeErrorTestSuites": 0,
"numTodoTests": 0,
"numTotalTestSuites": 273,
"numTotalTests": 1924,
...
}
so it looks like that numPendingTests is the one pointing to the skipped one. But when I search the output file, again, no trace of a skipped test. In fact, I did a search for "status": "[a-z]and there is no other status to be found than passed.
Short of looking through 270+ test suites, how else could a skipped test hide from me? Is there any way to find it?
As mentioned by johnrsharp as a comment, another way to skip tests in Jest is to prefix the term it(test) with x- so if you want to scan the files for skipped tests, you also need to look out for xit or xtest.

Pushing Results to KiwiTCMS using RobotFramework Ride Issue

I am trying to get Robotframework(Ride) work with KiwiTCMS.
I am making the connection to the KIWI server (local) but I am getting these errors that I am not sure where(In RIDE? or the .conf file?) to fix:
[ ERROR ] Calling method 'start_suite' of listener 'zealand.listener.KiwiTCMS' failed: ENVIRONFILE Version value not defined, missing one of TCMS_PRODUCT_VERSION, TRAVIS_COMMIT, TRAVIS_PULL_REQUEST_SHA or GIT_COMMIT
[ ERROR ] Calling method 'end_test' of listener 'zealand.listener.KiwiTCMS' failed: TypeError: 'NoneType' object is not subscriptable
TestKiwiRide | PASS |
------------------------------------------------------------------------------
KiwiTest.TestKiwi | PASS |
1 test, 1 passed, 0 failed
==============================================================================
KiwiTest | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output: C:\Users\hendri\Documents\KiwiTest\output.xml
Log: C:\Users\hendri\Documents\KiwiTest\log.html
Report: C:\Users\hendri\Documents\KiwiTest\report.html
(kiwi-env) C:\Users\hendri\Documents\KiwiTest>
Please assit?
Details goes into the bat file you use to call the test cases
check here : https://kiwitcms.readthedocs.io/en/stable/plugins/automation-frameworks.html
In plugin configuration section, you have to passe configuration as environment variables. e.g.
export TCMS_PLAN_ID=*PLAN_ID*

Fail2ban custom regular expresion

Trying to add custom rule on regular expression in order to block the below log.
Mar 17 18:46:52 s21409974 named[1577]: client #0x7g246c107030 1.1.1.1#8523 (.): query (cache) './ANY/IN' denied
I did tried with online tools like this one (https://www.regextester.com) but on the fail2ban-regex test command does display like it miss it.
Any suggestion about the rule or about how to better troubleshoot?
Thank in advance
Why do you try to write a custom regex? This message is pretty well matching with original fail2ban filter named-refused:
$ msg="Mar 17 18:46:52 s21409974 named[1577]: client #0x7g246c107030 1.1.1.1#8523 (.): query (cache) './ANY/IN' denied"
$ fail2ban-regex "$msg" named-refused
Running tests
=============
Use failregex filter file : named-refused
Use single line : Mar 17 18:46:52 s21409974 named[1577]: client #0x7...
Results
=======
Prefregex: 1 total
| ^(?:\s*\S+ (?:(?:\[\d+\])?:\s+\(?named(?:\(\S+\))?\)?:?|\(?named(?:\(\S+\))?\)?:?(?:\[\d+\])?:)\s+)?(?: error:)?\s*client(?: #\S*)? (?:\[?(?:(?:::f{4,6}:)?(?P<ip4>(?:\d{1,3}\.){3}\d{1,3})|(?P<ip6>(?:[0-9a-fA-F]{1,4}::?|::){1,7}(?:[0-9a-fA-F]{1,4}|(?<=:):)))\]?|(?P<dns>[\w\-.^_]*\w))#\S+(?: \([\S.]+\))?: (?P<content>.+)\s(?:denied|\(NOTAUTH\))\s*$
`-
Failregex: 1 total
|- #) [# of hits] regular expression
| 1) [1] ^(?:view (?:internal|external): )?query(?: \(cache\))?
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [1] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-
Lines: 1 lines, 0 ignored, 1 matched, 0 missed
[processed in 0.01 sec]
But if you need it, here you go (regex interpolated from fail2ban's pref- & failregex):
^\s*\S+\s+named\[\d+\]: client(?: #\S*)? <ADDR>#\S+(?: \([\S.]+\))?: (?:view (?:internal|external): )?query(?: \(cache\))? '[^']+' denied
replace <ADDR> with <HOST> if your fail2ban version is smaller than 0.10.

Asserting a null value via a Scenario outline

I am trying to assert a JSON response null value via the feature file below
Scenario Outline: GET incident notifications
Given I made a GET request for incident notifications for the "<incident>"
Then I should be able to see "<NotificationID>", "<DateTime>", "<ActionID>", "<Subject>", "<CreatedBy>","<Notes>"
Examples:
| incident |NotificationID|DateTime |ActionID|Subject |CreatedBy|Notes|
| 399 | 211 |2017-11-28T14:30:11.01|0 |Logged with Openreach| | |
| 400 | 2112 |2017-11-28T14:35:11.01|1 |Processed at Openreach|Agent | AgentNotes |
this is my step definition-
assertThat(webModel.getRestServices().response.getBody().path("CreatedBy[0]"),is(CreatedBy));
assertThat(webModel.getRestServices().response.getBody().path("Notes[0]"),is(Notes));
this is the error assertion error i get-
java.lang.AssertionError:
Expected: is ""
but: was null
I could get this thing working by asserting to nullValue() however, the 2nd run will fail as it has to take the parameter from the feature file.
any help would be greatly appreciated.
When we give any parameter as blank in the feature file, its taken as null. That's the reason you are getting this error as it is comparing null with a String.
We can solve this problem by doing a null or empty check before the assert. If the value is null, it would skip the assertion otherwise it will assert.

Do hooks in Mocha run regardless of test failures?

Just like the title says. Do before/after/beforeEach/afterEach hooks in Mocha work even if tests fail?
Yes, they do run even if the test fail.
However, if you run Mocha with the bail option, the teardown hooks will not run.
Just did an quick check with existing test suites here.
The code:
setup(function() {
console.log("1");
});
teardown(function() {
console.log("2");
});
The executions:
D:\Dev\JS\toposort>mocha
Toposort
◦ should sort correctly: 1
√ should sort correctly
2
◦ should find cyclic dependencies: 1
1) should find cyclic dependencies
2
◦ #2 - should add the item if an empty array of dependencies is passed: 1
√ #2 - should add the item if an empty array of dependencies is passed
2
2 passing (15 ms)
1 failing
1) Toposort should find cyclic dependencies:
AssertionError: expected [Function] to not throw 'Error' but [Error: Cyclic dependency found. '3' is dependent of itself
.] was thrown
D:\Dev\JS\toposort>mocha --bail
Toposort
◦ should sort correctly: 1
√ should sort correctly
2
◦ should find cyclic dependencies: 1
1) should find cyclic dependencies
1 passing (14 ms)
1 failing
1) Toposort should find cyclic dependencies:
AssertionError: expected [Function] to not throw 'Error' but [Error: Cyclic dependency found. '3' is dependent of itself
.] was thrown

Resources