All mocha tests pass locally but fail on Travis CI - node.js

I am building an api, everything works locally but on Travis-CI, the test fails. For the first time I was getting "mocha: permission denied". I deleted node_modules in my repository so that the Travis can install all dependacies with "npm install". And then I start getting this: enter image description here
Thanks for your help!

As you can see in picture that you have supplied on remote machine node --version is v0.10.48. In that version Node.js is not supporting ES6 syntax.
In your .travis.yml file you need to set node_js version on which you want to run tests like this:
node_js:
- 10
- 9
- 8
With this part your tests will be run on three version of Node.js. More information what you can put in .travis.yml you can find in official documentation.

Related

Not allowed to load local resource -error on chrome, Angular app is not running after production build

I am having a problem with the deployment of an angular app. It does not occur on another machine if deployed. My app is not running and it shows the following error on Chrome:
Not allowed to load local resource
and in Mozilla:
'src' attribute of element is not a valid URI
The thing is, it is working completely fine if deployed from other machines. So I am guessing the issue is with the versions of node or typescript or ng or whatsoever. I am new to server deployment and this kind of issue is new to me.
I am using following command to generate the deployment folder:
ng build --prod --base-href /candidate/
Following is my version details:
Node version: v10.16.3
Application typescirpt version: Version 2.9.2
Globally installed typescript version on the machine: Version 3.6.3
I deleted node modules and package-lock.json file and run npm install before production build. I got no error and was successfully able to generate dist folder.
The deployment folder works perfectly if it is deployed from machines which have upgraded or downgraded node version installed.
I have found many suggestions regarding the error shown on the browser, tried upgrading the node global versions but there is no way around. I am quite unsure about what I am missing here. Any kind of heads up would be great in this situation.
After digging into deep I found out that the problem is not with the version rather with the base URL it is generating in index.html file after build.
This issue occurs when using git-bash on Windows.
The git-bash sees the last argument of the command- ng build --prod --base-href /candidate/ as a path relative to its binary folder and prepends the argument with that (it converts the "seems-to-be" relative path into an absolute path).
So, I used PowerShell instead of Git-Bash and the issue was gone. The base-href parameter is handled fine there.
To resolve the issue with git-bash go through this link, which actually helped me to resolved my particular issue.
You should control base tag in index.html in dist folder.
<base href="/">

Cannot build / run test properly in travis. Permission denied

I have a simple node.js code/project. I write some test with jestjs. I run the test on my local machine with the command 'npm run test'. The test is able to pass.
I moved the project onto GitHub and wanted to tinker with Travis CI. But my build on travis ci fails. The error message on travis is shown below.
Below is the state of my Git repo:
I never committed the folder 'node_modules' into Git because I read somewhere that this folder should be excluded as Travis would have its 'own environment to run and build the project'.
Below is my .travis.yml :
Below is my package.json file:
I tried modifying this file as well. I am still stuck, Should I remove the lines that states the "build" ?
Appreciate any help!
Maybe try adding the following to travis.yml
before_script: chmod 0555 ./node_modules/.bin/travis
I resolved the situation by adding the below:
before_script: chmod 0555 ./node_modules/.bin/jest
I think this is trying to tell the machine running to allow the use of the jest library. Therefore the jests unit test is able to run properly.

Set up an xcode bot to build and deploy a nodejs express server

I am attempting to set up a xcode project and bot that will build a nodejs application on commit from a github repository and restart the server after the build completes. The bot is currently picking up on the repository changes but fails to build correctly.
I am using a xcode external build tool project that uses /bin/bash as the tool path and the working directory is set to the local repository path.
The bot's after integration script is something like,
npm install --production
npm run build
npm run server:restart
I am getting errors like [npm|node] is not recognized.
Just looking for some clarity to what I might be missing or what could be going wrong.
Add this to the beginning of your script and review the output:
which node
set | grep PATH
This will happen if node is not in your path, which may happen because build scripts have a pretty basic environment - they're not running as a normal user. You may need to add it to your PATH at the start of your build script.

Travis-CI with jasmine-node

I'm trying to get travis-ci to test my nodejs module with jasmine-node. When I run the tests from the commandline, they all pass, but for whatever reason, Travis always reports my build as failing. My .travis.yml looks like this:
language: node_js
node_js:
- 0.6
- 0.8
and my package.json looks like this:
"scripts": {
"test": "jasmine-node tests/*.spec.js"
}
I've tried adding a before_script to my travis.yml
language: node_js
node_js:
- 0.6
- 0.8
before_script:
- "sudo npm i -g jasmine-node"
Any ideas?
After spending some time with the travis-ci lint web app, it looks like it just came down to a matter of formatting in my .travis.yml file. My text editor was inserting tabs, where it appears that yaml requires you only use spaces. I also added quotes around everything for good measure.
It now looks like this, after making sure I was only using single spaces and newlines:
language: node_js
node_js:
- "0.6"
- "0.8"
before_script:
- "npm i -g jasmine-node"
Here is a repository with a working exemple of a travis build launching jasmine-node tests: https://github.com/yosethegame/yosethegame.
Note that the package.json declares the jasmine-node dependency that travis will install in its npm install phase.
I had a similar problem some time ago, I was using at the time jasmine-node -g and since it was a simple kata I thought there was no need for adding a package.json in the folder, but when I moved onto integrating that same project with travis-ci, I went through hell to be able to configure it.
With time I've learnt that it is better to keep things nice and tight and use your friendly package.json instead of global installations (There is a good post talking about it here for example: Why to avoid global test runners )
My advice would be for you to add jasmine-node to the package.json, something as short as this
{
"name" : "XXX",
"version" : "1.0.0",
"devDependencies" : {
"jasmine-node" : "latest"
},
"scripts" : {
"test" : "jasmine-node specs/*spec.js"
}
}
Will surely save you a headache and tons of configuring time not only with travis-ci integration, and it may as well save someone else's time in case someone wants to reuse what you've done. ;)

Using Travis-CI for Node.js project

I'm trying to set up travis-ci for my node.js project hosted on github. For some reason travis keeps using ruby worker for building/testing the project.
My .travis.yml looks like:
language: node_js
node_js:
- 0.6
script:
- "make test"
What am I missing?
OK got it.
The .travis.yml file must not contain 'tab' characters. Instead I have replaced them with spaces.

Resources