How to execute server and client tests in one command/process? - javascript

as I'm developing a web application using AngularJS in the front-end and Node.js in the server. For now I'm writing tests for the node server (based on Express) using Mocha (+ Chai + Supertest), and client side tests using Mocha and Testacular as a test runner, since Testacular is the tool of choice with Angular.
Note that the Angular app is "embedded" in the node app, as it's located in the template files.
My testing process : for server tests, I just npm test, i.e. mocha <my-test-folder> <my-test-options> ; for client tests, I launch a Testacular server that watches changes in the desired files. But I don't like this parallel and disconnected process and I'm sure there's a better, unified automated way.
Could help me refine the process ?

In my travels I haven't seen a precident for this, but you should be able to achieve it using grunt. You can make a grunt target that calls both.
I have a github project that should help show how to use testacular on an angular project using grunt which will at least help with the client part; will help get you part of the way there.

Related

How do I run my react front-end and express back-end together?

I'm attempting to build a simple react/node/express app from scratch (not using the create-react-app). I've built out a simple back end to pass some data to the front end but am having a hard time figuring out how the two communicate. How can I run the front-end and back-end together and view the front-end with the data passed into it?
I'd like to do this all in one command. Do I have to use a tool like webpack to bundle everything together into one runnable package?
My repo can be found here, it is the react-and-express branch that I've linked to. Any help is much appreciated! Currently I'm running the app by starting index.js but that is only the backend, how do I run my front-end App.js and get the two to communicate?
https://github.com/int-a/contacts-application/tree/react-and-express
You can use concurrently to run two node commands at the same time (1 for front-end and 1 for back-end). And then use the proxy configuration in webpack dev server to alias the calls to the backend port number for the same machine.

How do I deploy Node.js applications as a single executable file using systemd?

I want to deploy my node application as single executable file, is it possible by using systemd, containers. I dont have enough knowledge on systemd and containers. Please help me if anybody knows about it.
Where i work we use pm2 to run NodeJS applications.
It allows you to run multiple instances on one server, monitors them and restarts if needed (on failure or you can provide a memory limit).
If you insist going with systemd, you will have to create a unit - a file that describes the execution path of you application for systemd.
It would usually be in /usr/lib/systemd/system
You would have to create a file ending with ".service"
[Unit]
Description=My NodeJS App
[Service]
ExecStart=/usr/bin/node /path/to/my/app/index.js

How to test WebSocket component on client side?

There is an App build with Grunt. While building, Karma runs some unit-tests for client, using Phantom JS.
There is a new component, working with server via WebSocket. And i need to cover it with some tests. Then working with Ajax, everything is much more clear. There is a description how to do ajax-tests in Jasmine tutorial. But i have no idea there to start with WebSocket testing.
How did you solved this problem? How should i write and run this tests?

What is the correct way to test javascript with unit AND integrations tests, using Visual Studio and Team City?

I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.

Javascript/PHP continuous integration, testing, deployment

I am building a web application in javascript with a PHP/MySQL backend. The entire UI is Javascript based, except the index.php which only contains a few PHP lines. Out of that, it all works with AJAX calls. Then I have a PHP backend answering the AJAX calls with JSON.
I have a few questions on how to create a "clean" deployment process. My process should contain:
CI Running Javascript & PHP unit tests, backend JSON tests
JS compression
Deployment to a test server
UI/Acceptance testing
Eventual deployment to a prod server
What tools should I use to do that? I see many CI servers, but which one can do Javascript testing and compression and PHP unit testing?
How can I do staging in Javascript and PHP? I don't want my Javascript on the test instance to connect to the prod backend, neither the test backend to connect to the prod database. How should I implement this switch ?
Moreover, would it be better if I split my project in 2 parts - front-end and back-end or is it OK to deploy/test the whole javascript/php thing as one package?
Thank you a lot for you help
You can do CI of heterogeneous projects using Jenkins
Aside of unit tests you can set there coverage, mess detection and even selenium by simple plugins.
You can do simple deployment using any version control software just don't hardcode your javascript urls and dont user absolute urls. Instead base your your config on environmental variables on your staging and production. IDE's like PhpStorm also have deployment systems if you are interested in something more advanced.
CodeShip (www.codeship.com) can do this. It has the ability to run tools like Grunt or Gulp, Bower, NPM and Composer. And it can run phpunit, selenium, qunit etc. and it can deploy.

Categories

Resources