nyc coveralls integration not working - travis-ci

I try to make nyc working with coveralls following the instruction:
https://github.com/istanbuljs/nyc#integrating-with-coveralls
But I can't get it to work. Here is an example repo:
https://github.com/unional/showdown-highlightjs-extension
Travis build is successful: https://travis-ci.org/unional/showdown-highlightjs-extension
And Coveralls notice the build, but does not seem to get any data:
https://coveralls.io/github/unional/showdown-highlightjs-extension
Here is my .travis.yml:
language: node_js
notifications:
email:
on_success: never
on_failure: change
node_js:
- "stable"
before_install:
- npm install -g npm
script:
- npm run verify
after_script:
- npm install coveralls && npm run coveralls
And here is my package.json:
{
...
"scripts": {
"coverage": "npm test && nyc check-coverage --branches 85 --functions 85 --lines 85",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "npm run clean && tsc && nyc ava"
...
},
"nyc": {
"exclude": [
"scripts",
"**/*.spec.*",
"**/fixtures/**/*"
]
},
...
}

Try adding your Coveralls repo API token (which can be found on the Coveralls page for your repo) to a new COVERALLS_REPO_TOKEN encrypted environment variable on Travis, as per the (somewhat sketchy) documentation on the Coveralls site.

I found out the issue is in my tsconfig.json:
{
"compilerOptions": {
"sourceRoot": "/showdown-highlight-extension"
...
}
}
This setting gives me the correct (I assume) source map in the browser. See What's the proper way to set sourceRoot in typescript?
But is not liked by the coverage tool.
Once I remove it, it starts working.
Need to find an answer to that question.

Related

How to increase version of NPM package.json in Jenkinsfile

I am trying to modify Jenkinsfile to bump the version of my NPM package before deploying the server.
I have this on the deploy method:
if (env.GIT_COMMIT != env.GIT_PREVIOUS_COMMIT && env.GIT_BRANCH == "origin/develop"){
def version=sh(returnStdout: true, script: "npm version")
echo "Version is ${version}"
echo "${version.test}"
sh "npm version patch"
sh "git push"
}
I am checking if my previous commit is different than the actual, so if there is any change between the last deploy and the current, it should increase the version number.
The version variable output is:
{
test: '0.0.3',
npm: '6.12.1',
ares: '1.15.0',
brotli: '1.0.7',
cldr: '35.1',
http_parser: '2.8.0',
icu: '64.2',
llhttp: '1.1.4',
modules: '72',
napi: '5',
nghttp2: '1.39.2',
node: '12.13.1',
openssl: '1.1.1d',
tz: '2019c',
unicode: '12.1',
uv: '1.33.1',
v8: '7.7.299.13-node.16',
zlib: '1.2.11'
}
I would like test to go from 0.0.3 to 0.0.4 and then use npm version 0.0.4 to set that version in the app.
${version.test} is not working. It throws the following error:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.String test
How can I get that value and increase it so I can use properly the npm version 0.0.X and then pushing it to the repository?
Thanks in advance.

How to publish electron app to GitHub releases using electron builder?

I am trying to publish my electron app to GitHub releases but I cannot get it to work.
This is what I have:
package.json
....
"scripts": {
"start": "electron . --disable-gpu",
"test": "echo \"Error: no test specified\" && exit 1",
"win": "electron-builder --windows nsis:ia32",
"linux": "electron-builder --linux",
"publish":"electron-builder -p onTag"
},
....
"build": {
"publish": [
"github"
],
....
}
when I run npm run publish it creates the executable but it does not publish on my GitHub releases repository:
$ npm run publish
> Inventory-pro#1.0.1 publish /home/xander/Develop/Electron/InventoryV2
> electron-builder -p onTag
• electron-builder version=21.2.0 os=5.3.0-26-generic
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist/builder-effective-config.yaml
• packaging platform=linux arch=x64 electron=7.1.3 appOutDir=dist/linux-unpacked
• building target=deb arch=x64 file=dist/Inventory-pro_1.0.1_amd64.deb
I want to publish it so that I can include auto-update on my app on every release.
Don't specify the -p option and it will always publish a release because your script in the package.json is named release.
But please consider using automatic rules instead of explicitly specifying publish:
If npm script named release, — always.
Source: https://www.electron.build/configuration/publish#how-to-publish
...
"scripts": {
...
"publish":"electron-builder"
},
...

nyc and mocha code coverage failing when running in jenkins

I'm trying to generate the code coverage report for our builds in Jenkins -
Locally when I execute the command
npm run coverage
"scripts": {
"test": "cross-env mocha test -t 5000 --recursive --exit --reporter mochawesome",
"coverage":"nyc --reporter=html --reporter=text ./node_modules/.bin/mocha test -t 5000 --recursive --exit"
},
it will run the tests and then give me the code coverage results
Now when the same code runs in jenkins I get this error
/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/path-to-regexp/index.js:63
path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?'))
^
TypeError: Cannot read property 'length' of undefined
at pathtoRegexp (/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/path-to-regexp/index.js:63:49)
at new Layer (/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/express/lib/router/layer.js:45:17)
apparently is doing something with the node_module folder and I'm not sure how to avoid that. I exclude the folder and files in the nyc config
"nyc": {
"branches": 5,
"lines": 25,
"functions": 13,
"statements": 25,
"check-coverage": true,
"exclude": [
"**/services/plaidService.js",
"**/node_modules/**",
"**/node_modules/plaid/lib/PlaidClient.js"
]
},
Any ideas what should I do to avoid the node_modules folder to be checked?

Travis - Executing bower in sh script fails

I try to execute bower commands in a sh script that is run in the after-success phase o a travis build. I installed bower in the install phase:
install:
- npm install -g bower
[...]
after_success:
- if [ ${TRAVIS_PULL_REQUEST} = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
./my-script.sh;
fi
Unfortunately, if I call bower in the sh script it produces the following output:
./my-script.sh: line 30: ./node_modules/.bin/bower: No such file or directory
I do not know how to proceed to fix the error. Any help would be greatly appreciated, thank you already!
I had to call the script using
bash my-script.sh;
instead of
./my-script.sh;
Now everything is working fine.

coveralls github integration (with qunit, istanbul, grunt)

I'm having issues getting coveralls to work. I've created a simple project here.
It seems to be outputting the report correctly, but I'm definitely missing a step somewhere because coveralls doesn't see me as being set up.
No branches show up, and it simply gives instructions on how to set it up.
I've tried to copy what qunit is doing, because they obviously have it working.
Here is what I've done so far.
Created the project that uses node/grunt/qunit as well as the coveralls account and toggled on the project.
I've then replaced the qunit reference in the devDependencies section in package.json with this.
"grunt-coveralls": "0.3.0",
"grunt-qunit-istanbul": "^0.4.0"
I've added this to my package.json.
"scripts": {
"ci": "grunt && grunt coveralls"
}
I've added this config for qunit in my Gruntfile.js.
options: {
timeout: 30000,
"--web-security": "no",
coverage: {
src: [ "src/<%= pkg.name %>.js" ],
instrumentedFiles: "temp/",
coberturaReport: "report/",
htmlReport: "build/report/coverage",
lcovReport: "build/report/lcov",
linesThresholdPct: 70
}
},
I then added this to my .travis.yml.
language: node_js
node_js:
- "0.10"
before_install:
npm install -g grunt-cli
install:
npm install
before_script:
grunt
after_script:
npm run-script coveralls
I got it working, check the repo for the example https://github.com/thorst/Code-Coverage-Qunit
While its not always possible, I found jasmine to be easier in multiple ways. I have a complete example here: https://github.com/thorst/Code-Coverage-Jasmine
I still haven't gotten mocha to work though. That (broken) repo is here: https://github.com/thorst/Code-Coverage-Mocha

Resources