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?
Related
We are trying to get our multi-stack application deployed using the cdk pipeline library.
We have recently disabled the publishAssetsInParallel flag, as with the default setting our pipeline would create >20 FileAsset objects under the Assets stage, which AWS then complains as being too many CodeBuild projects running parallel.
However, with this property now disabled, I'm getting the following error for the Assets stage:
[Container] 2022/11/14 12:04:24 Phase complete: DOWNLOAD_SOURCE State: FAILED
[Container] 2022/11/14 12:04:24 Phase context status code: YAML_FILE_ERROR Message: stat /codebuild/output/src112668013/src/buildspec-c866864112c35d54804951dbe96b99440c9b891fde-FileAsset.yaml: no such file or directory
I'm assuming this is supposed to be a build spec that is create by cdk pipeline, as we didn't need to create a build spec when things were running in parallel.
Here is the current pipeline code:
const pipeline = new CodePipeline(this, 'Pipeline', {
publishAssetsInParallel: false,
selfMutation: false,
pipelineName: fullStackName('Pipeline', app),
synth: new CodeBuildStep('SynthStep', {
input: CodePipelineSource.codeCommit(repo, repoBranchName, {codeBuildCloneOutput: true}),
buildEnvironment: {computeType: ComputeType.MEDIUM},
installCommands: [
'npm install -g yarn',
'yarn install',
'cd apps/cloud-app',
'yarn install',
'yarn global add aws-cdk'
],
commands: [
'yarn build',
'cdk synth'
],
primaryOutputDirectory: 'apps/cloud-app/cdk.out'
}
)
});
UPDATE:
I reverted the publishAssetsInParallel flag to its default setting to compare, and it seems there is a fundamental difference in the way it creates the FileAsset CodeBuild projects based on this flag. With it enabled, when I inspect the build details for one of the FileAsset projects that is created, I can see under the buildspec section it contains a concrete implementation of a build spec, eg:
{
"version": "0.2",
"phases": {
"install": {
"commands": [
"npm install -g cdk-assets#2"
]
},
"build": {
"commands": [
"cdk-assets --path \"MyStack.assets.json\" --verbose publish \"2357296280127ce793d8dbb13e6c907db22f5dcc57a173ba77fcd19a76d8f444:12345678910-eu-west-2\""
]
}
}
}
With the flag disabled, the buildspec simply contains a pointer to a buildspec file as below, which it then fails to find...
buildspec-c866864112c35d54804951dbe96b99440c9b891fde-FileAsset.yaml
Self-mutation has to be enabled - currently, asset updates mutate the pipeline.
Reference: https://github.com/aws/aws-cdk/issues/9080
I'm trying to build an installer with electron-builder but every time I generate the installer and install my application, I get an error that "dist/index" doesn't exist in .asar file. I checked and no dist file is packed inside .asar.
The error I'm getting:
Not allowed to load local resource: file:///C:/Users/user1/AppData/Local/Programs/myApp/resources/app.asar/dist/index.html
I'm building with this script:
"publish": "set GH_TOKEN=<my_token> && electron-builder --win -p always"
Does electron-builder have any flags to tell him where to put the output files?
Okey after some trial and error, I found what was wrong...
So basically my package.json was configured wrong. In order to include dist in build it must be specified like this:
...
"build": {
"appId": "si.app.testing",
...
"directories": {
"output": "release",
"buildResources": "dist"
},
"files": [
"**/*",
"dist/**/*",
...
"!.github",
"!.vs",
"!node_modules/*"
]
},
...
I use:
VS Code 1.14.1
Tasks 2.0
node 6.11.1
My problem is that some tasks are working, and some are not.
Here my tasks.json file.
{
"version": "2.0.0",
"tasks": [
{ // This task work fine.
"label": "tsc",
"type": "typescript",
"tsconfig": "tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
},
{ // This task work fine.
"taskName": "css",
"type": "shell",
"command": "./scss.sh",
"windows": {
"command": "./scss.cmd"
},
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{ // This task not work. (See output #1 below)
"taskName": "npm-install",
"type": "shell",
"command": "npm install",
"problemMatcher": [],
"presentation": {
"reveal": "always",
}
},
{ // This task not work. (See output #2 below)
"type": "gulp",
"task": "clean",
"problemMatcher": []
}
]
}
Output #1 - When I try to run npm task with type shell\npm, I get the same result:
> Executing task: npm install <
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, login, logout, ls, outdated, owner, pack, ping,
prefix, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, tag, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\usr\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#3.10.10 C:\Program Files\nodejs\node_modules\npm
Output #2 - When I try to run gulp task I get next (gulp package installed as global (npm install gulp -g),(I have gulpfile.js with correct content)):
> Executing task: node_modules\.bin\gulp.cmd clean <
clean: node_modules.bingulp.cmd: command not found
I can use gulp, npm, node and other tools from cmd as usually, and it's works fine, but not in the VS Code.
Current solution of this thing:
Create batch files for each stuff.
Create shell task for each batch file (as scss.cmd)
Run those tasks.
Yep, it works well, but you need to do too much action for simple tasks.
What can you advise in this regard?
I found a solution to this problem, the problem was in the default terminal application.
By default on Windows OS visual studio code use powershell as terminal app, in my case, I changed it to the git-bash app and got this problem. After that I changed it back to powershell and all works fine.
I did not bother about why gitbash does not work, it is possible that additional configuration is required in the configuration in the vs code.
This is an issue in VS Code. A < gets added at the end of commands, making them fail. There doesn't seem to be a direct fix at the moment.
I am new to Mocha so this might probably be a trivial question but couldn't yet find an answer:
I have a simple NodeJS project with the below package.json
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "davide talesco",
"license": "ISC",
"devDependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
}
}
and the following 2 tests files under test folder:
test1.js
process.env.NODE_ENV = 'test';
var chai = require('chai');
var should = chai.should();
describe('Test setProp', function(){
it('env variable should be test', function(done){
process.env.NODE_ENV.should.be.equal('test');
return done();
});
});
test2.js
process.env.NODE_ENV = 'prod';
var chai = require('chai');
var should = chai.should();
describe('Test setProp', function(){
it('env variable should be prod', function(done){
process.env.NODE_ENV.should.be.equal('prod');
return done();
});
});
when I run npm test the first test complete succesfully whilst the second fails as per below
ie-macp-davidt:crap davide_talesco$ npm test
> pc-lib#1.0.0 test /Users/davide_talesco/development/crap
> mocha
Test setProp
1) env variable should be test
Test setProp
✓ env variable should be prod
1 passing (16ms)
1 failing
1) Test setProp env variable should be test:
AssertionError: expected 'prod' to equal 'test'
+ expected - actual
-prod
+test
at Context.<anonymous> (test/test1.js:11:36)
npm ERR! Test failed. See above for more details.
its pretty clear that the tests are running under the same process...
my question is : how can I make them run under completely separate processes so each one can set its own environment?
Thanks,
Davide
One of the most simple ways is to use Unix find command:
find ./test -name '*.js' -exec mocha \{} \;
I'd recommend to use local mocha binaries to avoid troubles in case it isn't installed globally:
find ./test -name '*.js' -exec ./node_modules/.bin/mocha \{} \;
If you want to add that to package.json, please note that backslashes should be escaped:
...
"scripts": {
"test": "find ./test -name '*.js' -exec ./node_modules/.bin/mocha \\{} \\;"
},
...
If you want to abort testing as soon as a test file fails, you can do it like this:
find ./test -type f -name "*.js" -exec sh -c 'for n; do ./node_modules/.bin/mocha "$n" || exit 1; done' sh {} +
Alternatively you can use mocha-parallel-tests.
To install:
https://www.npmjs.com/package/mocha-parallel-tests
To use:
"scripts": {
"test": "mocha-parallel-tests"
},
Nice thing is that it is a proper mocha runner so you can configure reports and pass standard mocha configuration like bail.
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.