can I use karma to test page interaction like drag & drop? - node.js

I'm evaluating end to end testing of a MEAN stack app. There's a few critical spots in the app where drag and drop (via a directive) is used. I can't find any information about using karma to test this. Is it possible? If not, what library would you recommend?

Yes, Angular comes bundled with e2e testing that can be run via Karma. The angular-seed application is a good example of a project structure that includes both e2e and unit tests. From the project home page:
End to end testing
Angular ships with a baked-in end-to-end test runner that understands
angular, your app and allows you to write your tests with jasmine-like
BDD syntax.
Requires a webserver, node.js + ./scripts/web-server.js or your
backend server that hosts the angular static files.
Check out the end-to-end runner's documentation for more info.
create your end-to-end tests in test/e2e/scenarios.js
serve your project directory with your http/backend server or node.js +
scripts/web-server.js
to run do one of:
open http://localhost:port/test/e2e/runner.html in your browser
run the tests from console with Karma via scripts/e2e-test.sh or script/e2e-test.bat
Also, it should be noted that apparently the Angular team will be replacing this current e2e setup with Protractor at some point in the future.

Related

Where to install Cypress when testing frontend/backend utilities and doing end-to-end tests?

I have a React project with a Node.js backend. Both parts are in seperate folders with separate package.json and node_modules.
The thing is that I want to do backend unit tests, frontend unit tests, and end-to-end tests.
I don't know if I should install Cypress twice on both the frontend and backend. Or there would be a way to only keep one Cypress installation.
Cypress runs in the browser and isn't used to test backends directly as far as I am aware.
I suggest placing it in the root of the repo as it tests both the frontend and backend projects.
One way to think about it would be to do it as if you were in a monorepo.
In a monorepo you might have multiple backend server and multiple frontend apps. Each of these will have their own unit tests in their own folder.
For end-to-end tests, we would put it inside each frontend apps. This is because different frontend apps do not interact with each other, but could call multiple different backend servers. By doing like this we group our test by website/apps.

how to get code coverage when running tests written in tavern with pytest, having nodejs app running in backend?

I have an API written in node js, and integration tests for endpoints written in tavern with pytest. I want to get code coverage of those integration tests after running. For now, the setup is; first starting node app, and running tavern test suites with pytest command.
See lots of scenarios but all have a consistency in btw test engine and app engine e.g python - python or js - js. How could I get code coverage of tavern tests suites w.r.t node app?
-UPDATE-
The API written in node js -v12.16.2- with nest js framework, we run app with nest start, and running tests written with tavern -v0.34.0- with pytest -v4.5.0- on the other tab against running api. And I want to learn how to get code coverage of app by being hit endpoints by test requests by tavern.
You have 2 programs here:
The nodejs app
The tavern test suite
You're interested in finding the coverage of the nodejs part, which means you need to instrument that program.
I've only had a quick look around, but it would appear that using https://github.com/istanbuljs/nyc is a good bet, meaning you can just run your server with nyc prepended to measure the coverage when you run the tavern tests.
Note: this is a vague answer, I will update if the question is made more specific.

Is `ng serve` command suitable for production?

I'm building a small project using Angular 7. When you run
ng serve
and a NodeJS server is spun up to handle requests, does each request block until processing is complete? We are trying to evaluate how effective using this in production would be as opposed to using a more traditional application server.
Run build --prod to generate a "./dist" folder.
Then you have to put that on a web server.
You can use Angular Server Side Rendering (SSR) to run it on a node.js server.
You should not use ng serve for production because it use webpack-dev-server that is build for development only.
Github link
ng serve runs a webpack development server behind the hood.
a development server.
It's made to mimic the production build and see your final application in an esay way.
If you didn't have that command, you would need to run a command like simplehttpserver after rebuilding all of your application on every change.
This is a convenience tool provided by the CLI to ease your development, in no case it's suited for production mode. This is a server without security, without optimization, without performance, without ... Well, without anything that makes a server, a server. By default, it deosn't even make your application accessible outside of your localhost. Not so useful for a production mode ...
So, never, I repeat, never, use this command for your production server.
Run ng build --prod
It will generate minification code in "dist" folder. you have to upload the file content of this "dist" folder. It will give faster response for loading web pages.
For more details please refer Angular deployment guide
When using ng serve, you are spawning a backend nodejs environment with a web server to handle requests towards your angular application. That's great for reloading and quick startup when developing. But needing such resources for static pages is unnecessary.
At the end of the day Angular is just a framework telling you its opinion on how to build an SPA. No matter the framework or library you use, you will always end up with an index.xxx, Javascript files and other resource files from vendors or internally. Only these matters to the browser loading the webpage.
Hence, you need to build your app to generate the static files that will be served (i.e. ng build --prod). Then you have 2 good options:
Choose a web server that will serve the files (i.e. nginx) on a dedicated server (or even container).
Place the files behind a CDN provider. Since they are static, they will be cached and served to a browser requesting them based on its location.
I would opt for #2 as opposed to #1 forcing you to keep running resources (CPU, RAM, HDD) for files that will be requested not that often. I say not often because your SPA will be handling all routes within itself in the client's browser (and minimum once a day will request a cache refresh).

Configure project for Jasmine Test Case using Oracle Weblogic

I am having a web based project which I deploy in weblogic server as EAR for execution. I need to implement Jasmine for unit testing.
I came to know that Jasmine can be executed in NodeJS server but my project has some servlets also as a part of it. So, how can I configure Jasmine to run on oracle weblogic server.
Also, if it is possible by any other means like integrating weblogic with NodeJS (I am not sure about this.) , kindly explain me the process to set up.
I wouldn't try to run your Jasmine tests from WebLogic. That is like saying you want to run your JUnit tests on WebLogic.
JUnit tests are run from the command line in your development environment (often wrapped by the IDE) and also on your CI build agent. Jasmine tests should follow the same pattern. You shouldn't have to go through an entire deploy cycle just to run your unit tests.
I suggest looking at using Karma to run your tests, both locally and on CI.

A simple way to set up automated BDD test environment for Node.js server + SPA javascript framework?

Here's my project's setup:
Frontend: Angular.js/Backbone.js SPA app
Backend: Node.js + NoSQL db as backend
Testing:
Already have Karma set up for SPA testing (with mock JSON responses)
Already have Mocha set up for Node.js, with an isolated "test" environment for test DB setup and teardown
Now the problem comes when I try to set up integrated BDD test (namely, start node servers, start a browser and run SPA tests inside the browser with actual JSON calls to the backend). After some searching, I failed to find a simple and straightforward solution to my problem, so I thought I'd ask here so other people in similar situation may also benefit from the answers. Thanks!
I would suggest Gruntjs all the way. While on the surface it seems like just another redo of make(1), the community support and HUGE collection of plugins makes it super useful. It will solve all the problems you mentioned plus some.
Website
Github

Resources