Instanbul/Nyc only picking up some files - node.js

I tried to set up Istanbul/Nyc/Mocha for test coverage for my project and although I was able to run Nyc successfully, I am only able to see some files being picked up for test coverage not all the .ts files that I have.
So when I run
npm run coverage
I get
-----------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------------|---------|----------|---------|---------|-------------------
All files | 0 | 100 | 100 | 0 |
develop-potta | 0 | 100 | 100 | 0 |
swagger.ts | 0 | 100 | 100 | 0 | 1
develop-potta/models | 0 | 100 | 100 | 0 |
students.ts | 0 | 100 | 100 | 0 | 1
swaggerDefinition.ts | 0 | 100 | 100 | 0 | 1
develop-potta/routes | 0 | 100 | 100 | 0 |
routescontroller.ts | 0 | 100 | 100 | 0 | 4-5
This only covers about 50% of my code base. For example I have a develop-potta/DBConnection/OracleConnection.ts which is also a ts file which isn't being picked up by my script. I am unable to figure out why? Could it be a certain naming convention? Could it be that I didn't export those modules?

Typescript + mocha + nyc can be picky. Especially the all: true setting messes up the coverage a lot. But as you mention it's hard to bring it cover all files. My template repo covers those cases. Maybe it can help you.
https://github.com/Flowkap/typescript-node-template
If you're only interested in coverage check the .ncyrc.yml and mocharc.yml as well as the call config in package.json. VsCode launch configs also included.

Related

jest how to see all uncovered lines in CLI?

I want to see uncovered lines which is hidden by "..." like: "... 03,104,107,111"
Any ideas?
validation.ts | 76.92 | 82.61 | 53.33 | 76.19 |... 03,104,107,111 |
worklistPage-util.ts | 0 | 0 | 0 | 0 |... 63,68,69,70,73 |
I found a solution, but not for the CLI.
I was able to check all uncovered lines by type start coverage/lcov-report/index.html which is created by istanbul.js in Window system

All tests pass 100% coverage but jest returns exit code 1

I have looked into --detectLeaks and --detectOpenHandles, and it does raise some errors but there are no clear issues in the output.
I have a monorepo and I'm running jest in jenkins within a docker / pipeline.
> abide#1.0.0 jest /var/jenkins_home/workspace/abide
> jest --coverage --no-cache --runInBand
[BABEL] Note: The code generator has deoptimised the styling of "/var/jenkins_home/workspace/abide/node_modules/lodash/lodash.js" as it exceeds the max of "500KB".
PASS packages/help.parse-argv/index.test.js (10.842s)
[BABEL] Note: The code generator has deoptimised the styling of "/var/jenkins_home/workspace/abide/node_modules/text-encoding/lib/encoding-indexes.js" as it exceeds the max of "500KB".
hello
npm notice created a lockfile as package-lock.json. You should commit this file.
+ example-working#0.0.1
added 2 packages from 2 contributors and audited 2 packages in 2.837s
found 0 vulnerabilities
require successfull
Usage: --function <args> [--function <args>]
--a (echo hi)
--b (echo hi)
--c (echo hi)
--help (shows this help output)
--------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
command | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
command-plus | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
dep-merge | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
dep-merge-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
dep-pointer | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
dep-pointer-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
gitpkg.traverse-up | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
gitpkg.upsert | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
help | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
help.filter-until | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
help.parse-argv | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
help.set-entire | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
help.string-argv | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
here | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey.coerce-to-array | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey.coerce-to-plain-object | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey.fn-free | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey.fn-reduce | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
journey.pass-thru | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
lerna.paths | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
lerna.utils | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
monorepo-babel-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
monorepo-dep-lint-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-babel-6-to-node-4 | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-babel-7-to-node-4 | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-cobalt | 0 | 0 | 0 | 0 | |
index.js | 0 | 0 | 0 | 0 | |
pkg-plugin-jest | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-name-dir | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-name-scope | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-prop | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-sort | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg-plugin-standard | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.file-exists | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.fs | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.is-local-module | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.json-parse | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.pretty-json | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.prop-overwrite | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.read-json | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkg.throw-error | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkgprop | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
pkgprop-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
reggi-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
replace-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
requireable | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
requireable-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
results-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
shebang-check | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
shebang-check-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
subrepo | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
subrepo-cli | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
--------------------------------|----------|----------|----------|----------|-------------------|
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! abide#1.0.0 jest: `jest --coverage --no-cache --runInBand`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the abide#1.0.0 jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-06-20T13_11_31_412Z-debug.log
Here's my jest configuration:
{
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"<rootDir>/unpublished/.+",
"<rootDir>/packages/.+/examples/.+",
".+build.js",
"<rootDir>packages/pkg-plugin-prop/index.build.js"
],
"coverageReporters": [
"html",
"text"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"modulePathIgnorePatterns": [
"<rootDir>/unpublished/.+",
"<rootDir>/packages/.+/examples/.+",
".+build.js"
],
"projects": [
"<rootDir>/packages/.+"
],
"testPathIgnorePatterns": [
"<rootDir>/unpublished/.+",
"<rootDir>/packages/.+/examples/.+",
".+build.js"
],
"watchPathIgnorePatterns": [
"<rootDir>/unpublished/.+",
"<rootDir>/packages/.+/examples/.+",
".+build.js"
]
}
What is going on here?
Locally it does return a 0 exit code and prints:
Snapshot Summary
› 11 snapshots written from 6 test suites.
Test Suites: 55 passed, 55 total
Tests: 290 passed, 290 total
Snapshots: 11 written, 12 passed, 23 total
Time: 112.189s
Ran all test suites.
> abide#1.0.0 postjest /Users/thomas/Desktop/github.com/reggi/abide
> here --cleanCoverage
I had one module that was calling process.stderr.write()
I used lerna to run each individually to find it.
lerna exec --concurrency 1 -- jest --no-cache --runInBand --ci

Spotfire - Identify each time a value changes in a particular pattern for a particular type

Apologies for the bad title, I'm struggling to describe exactly what I;m trying to do (which has also made it difficult to search for an existing answer.
I have a series of date with the columns "Asset", "Time", and a "State" that is a calculated column that changes based on several other values. The data is source from a constant, and non-regular stream of data (though in the table below I have created a sample of timestamps that are regular).
The below table shows the source data ("Asset", "Time" and "State"), as well as an intended calculated column "Event" that tracks each time an event starts. I do not simply want to count the number of times an "Asset" has a Bad "State", but identify each time an "Asset" changes from a "State" of Good to a state of Bad (note in the real data there is a large number of different states, but the pattern I'm trying to identify is consistent).
+-------+----------+-------+-------+
| Asset | Time | State | Event |
+-------+----------+-------+-------+
| 1 | 12:00:00 | Good | 0 |
| 2 | 12:00:00 | Good | 0 |
| 1 | 12:00:01 | Good | 0 |
| 2 | 12:00:01 | Good | 0 |
| 1 | 12:00:02 | Bad | 1 |
| 2 | 12:00:02 | Good | 0 |
| 2 | 12:00:03 | Good | 0 |
| 2 | 12:00:03 | Good | 0 |
| 1 | 12:00:04 | Bad | 0 |
| 1 | 12:00:04 | Good | 0 |
| 2 | 12:00:05 | Good | 0 |
| 2 | 12:00:05 | Bad | 1 |
| 2 | 12:00:06 | Bad | 0 |
| 1 | 12:00:06 | Good | 0 |
| 2 | 12:00:07 | Bad | 0 |
| 2 | 12:00:07 | Good | 0 |
| 2 | 12:00:08 | Good | 0 |
| 1 | 12:00:08 | Bad | 1 |
| 2 | 12:00:09 | Good | 0 |
| 1 | 12:00:09 | Bad | 0 |
| 2 | 12:00:10 | Good | 0 |
| 1 | 12:00:10 | Good | 0 |
+-------+----------+-------+-------+
I intend to create a chart for this data to show how many times an event occurs for a particular asset per day. I figured the easiest way to do that is to have a column that counts a 1 when the event starts, and then sum this column over the dates to create the visualisation.
My idea was for a calculated column that picks up when the "State" is bad, and then checks to see if the previous state for that "Asset" was good, and set as a 1 if so. I have so far been unable to find a way to identify what the value was for a previous row entry for a particular "Asset".
Note that there are roughly 100 (or more) individual "Asset" entries, so creating an individual calculated column to track each would not be feasible. I am also using Spotfire 7.1.
Thanks in advance, and sorry again if the way I've written this is confusing.

ionic 2 project reports 97% coverage but sonar reports 0% coverage

I'm trying to integrate an ionic project with sonar, and everything seems to be OK but the coverage, tests are developed with jest and the test:coverage task (jest --coverage) is reporting a 97% but I get a 0 coverage in sonar.
npm run test:coverage result:
Test Suites: 5 passed, 5 total
Tests: 14 passed, 14 total
Snapshots: 0 total
Time: 3.004s
Ran all test suites.
-----------------------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-----------------------------------|----------|----------|----------|----------|----------------|
All files | 97.53 | 75 | 84.85 | 97.22 | |
app | 100 | 76.92 | 100 | 100 | |
app.component.ts | 100 | 76.92 | 100 | 100 | 14 |
app.html | 100 | 100 | 100 | 100 | |
pages/appointment | 100 | 100 | 100 | 100 | |
appointment.module.ts | 100 | 100 | 100 | 100 | |
pages/appointment/appointmentItem | 100 | 76.92 | 100 | 100 | |
appointmentItemPage.html | 100 | 100 | 100 | 100 | |
appointmentItemPage.ts | 100 | 76.92 | 100 | 100 | 17,18 |
pages/appointment/appointmentList | 94.12 | 75 | 80 | 93.33 | |
appointmentListPage.html | 100 | 100 | 100 | 100 | |
appointmentListPage.ts | 93.75 | 75 | 80 | 92.86 | 32 |
pages/home | 85.71 | 66.67 | 66.67 | 83.33 | |
home.html | 100 | 100 | 100 | 100 | |
home.ts | 83.33 | 66.67 | 66.67 | 80 | 16 |
providers/appointment | 100 | 66.67 | 83.33 | 100 | |
appointmentData.ts | 100 | 100 | 83.33 | 100 | |
appointmentProvider.ts | 100 | 66.67 | 100 | 100 | 21 |
prospectData.ts | 100 | 100 | 66.67 | 100 | |
-----------------------------------|----------|----------|----------|----------|----------------|
The coverage/lcov.info it's been correctly generated (abstract of a file):
TN:
SF:/home/jmgomez/securitas/sst/src/app/app.component.ts
FN:11,(anonymous_2)
FN:14,MyApp
FN:15,(anonymous_4)
FNF:3
FNH:3
FNDA:1,(anonymous_2)
FNDA:1,MyApp
FNDA:1,(anonymous_4)
DA:11,1
DA:12,1
DA:15,1
DA:18,1
DA:19,1
DA:22,1
LF:6
LH:6
BRDA:14,0,0,1
BRDA:14,0,1,0
BRDA:14,1,0,1
BRDA:14,2,0,1
BRDA:14,2,1,1
BRDA:14,2,2,0
BRDA:14,3,0,1
BRDA:14,3,1,1
BRDA:14,4,0,1
BRDA:14,4,1,1
BRDA:14,4,2,0
BRDA:14,5,0,1
BRDA:14,5,1,1
BRF:13
BRH:10
end_of_record
And linked into the sonar-project.properties file:
sonar.projectKey=sst:app
sonar.projectName=sst_app
sonar.projectVersion=1.0
sonar.sources=./src/
sonar.tests=.
sonar.test.inclusions=**/*.spec.ts
sonar.javascript.lcov.reportPaths=coverage/lcov.info
This is the listing for the coverage folder
ls coverage/ -la
total 36
drwxrwxr-x 3 myuser mygroup 4096 ene 3 12:01 .
drwxrwxr-x 11 myuser mygroup 4096 ene 3 11:57 ..
-rw-rw-r-- 1 myuser mygroup 19778 ene 3 11:57 coverage-final.json
-rw-rw-r-- 1 myuser mygroup 4032 ene 3 11:57 lcov.info
drwxrwxr-x 7 myuser mygroup 4096 dic 20 15:27 lcov-report
Related log lines for sonnar-scanner command are the following:
INFO: Excluded sources:
INFO: **/*.spec.ts
INFO: Included tests:
INFO: **/*.spec.ts
INFO: 35 files indexed
...
INFO: Sensor TypeScript LCOV Coverage Sensor [typescript]
INFO: Sensor TypeScript LCOV Coverage Sensor [typescript] (done) | time=4ms
INFO: Sensor JavaScript Squid Sensor [javascript]
INFO: 1 source files to be analyzed
INFO: Test Coverage Sensor is started
INFO: 1/1 source files have been analyzed
INFO: Analysing [/home/jmgomez/securitas/sst/coverage/lcov.info]
INFO: Sensor JavaScript Squid Sensor [javascript] (done) | time=135ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=29ms
Any hint?, Am I missing something?

values of new table changing dynamically with the input of the initial table

I have a question in Excel and need your help!
I can do this if it was static problem but I need my end result to adjust to my input in the table because the year sometimes the year finishes sooner or later or is different or the number of activities vary.
Initial table (It always go in chronological order and it only has 1 or nothing. (I put 0 there because I wanted to put space and didn't know how to do it. also Number of activities may vary)
+----------------+------+------+------+------+------+------+
| year | 2016 | 2016 | 2016 | 2017 | 2017 | 2017 |
+----------------+------+------+------+------+------+------+
| month calendar | 10 | 11 | 12 | 1 | 2 | 3 |
| month project | 1 | 2 | 3 | 4 | 5 | 6 |
| Activity 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Activity 2 | 0 | 0 | 1 | 1 | 1 | 1 |
| Activity 3 | 0 | 0 | 0 | 1 | 1 | 0 |
| Activity 4 | 0 | 1 | 1 | 0 | 0 | 0 |
| Activity 5 | 1 | 1 | 1 | 1 | 1 | 1 |
+----------------+------+------+------+------+------+------+
I want in another sheet
+---------------+------------+------------+------------+------------+
| Activity year | 2016 | | | |
| | | | | |
| Activity 1 | Activity 2 | Activity 3 | Activity 4 | Activity 5 |
| 25,0% | 12,5% | 0,0% | 25,0% | 37,5% |
| | | | | |
| Activity year | 2017 | | | |
| | | | | |
| Activity 1 | Activity 2 | Activity 3 | Activity 4 | Activity 5 |
| 0,0% | 37,5% | 25,0% | 0,0% | 37,5% |
+---------------+------------+------------+------------+------------+
Now imagine that in the "another sheet" I have nothing and I want the result to adjust to the initial table. How can I do this?
Sorry for bad editing but I can't do better.
Any help is good thank you, I answer any question you might have.
I'm going to add something that is related to this and I also need. I need a formula to get the number of different activities per year that happen at least once for my calculations later. In this case it would be a formula for 2016 which the result is 4 and 2017 is 3.

Resources