How to test WebSocket component on client side? - javascript

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?

Related

Electron - How to write e2e tests?

I am using electron react boilerplate as base for my project. I wrote small backend for it, which uses winston to write logs.
Jest can easly test single functions and components but I need help with e2e tests. Because this app is using ipcRenderer, cypress throws errors that ipcRenderer is undefined so it cannot connect backend.
Are there any tools that can access electron's ipcRenderer to send messages ? Easiest way to fix it would be to push electron as dependency, instead of devDependency, but I don't think it should be done that way
Thx in advance

Can you create tasks in the Windows Task Scheduler from a react native desktop app (or any other js framework)

I am trying to find a way to create a desktop application where I can setup Tasks to run that will turn on my pc and run a c# app / shell script that will send an api request with a video file and a text file.
If you use nodejs, you can execute commands in the terminal with the exec function from the child_process module, then use the schtasks command to schedule tasks.
Commands with nodejs:
https://stackabuse.com/executing-shell-commands-with-node-js/
schtasks command:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks
I am unsure about turn on PC part.
You could write a Windows Service worker that runs in the backend, then interact with it vai a local datasource (like a Database or Text file) from your react native desktop app.
In the .Net world you could also host a HangFire web site or something like it. To expose API endpoints for your application to fire off jobs or series of jobs.
https://www.hangfire.io/
Or:
You should be able to call a PowerShell script.
*** Addison Schmidt answer it likely much more direct. Depending on your needs.

Why does React need to connect to a server?

I just started working with React and I came to 2 big questions that I never realized before:
Why does React need to connect to a server (localhost, deployment, etc)? Isn't it usually the backend that needs the server url, not the frontend? From my frontend experience, I would just have a .js file with jQuery doing the DOM scripting for the associated html file and that was it.
If I am making a React full stack application with let's say a .NET backend, then React will have its localhost:3000 server url and the .NET backend (ASP.NET Core) would have something like a localhost:54204. Does that mean I need 2 deployments to run that application? Is that normal, or is there some process to mesh the two?
Thank you so much for answering this, hopefully these 2 questions answered will make me fully grasp the concept of React
For the first question does react have server and why? Yes it has and its in the bundler which is called webpack. In fact it runs server script under hood and it is for development. What about the deployment when you use create-react-app and finish your app you can run npm run buld it creates a folder for bundled files. So you can use it in your backend a static files or can create different server script and deploy as an independent application.

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.

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

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.

Categories

Resources