Skip to content
main
Switch branches/tags
Code

chat.io renovate-app badge cypress version

ci status chat.io

Cypress.io testing for a chat application that requires auth

Videos

Installation

$ npm install

You will need a MongoDB somewhere and a Redis instance. I assume the MongoDB is running in the cloud and the Redis is running locally in a Docker container.

Run the app

Using docker-compose

$ docker-compose up

Or you can run Redis and MongoDB separately

Using separate services

Start Redis

$ docker run -d -p 6379:6379 redis:alpine
$ MONGODB=... SESSION_SECRET=... npm start

Tip: use as-a to inject the above environment variables into a local / user profile file .as-a.init, something like this:

[chat.io]
SESSION_SECRET=MySecretVariable1234
MONGODB=mongodb://root:rootPass1234@localhost:27017/
$ as-a chat.io npm start

Run the tests

Because Cypress connects to the same MongoDB to clear the data in some tests, need to start it with the same environment variable

$ MONGODB=... npx cypress open

Read Testing Mongo with Cypress

Tip: you can use as-a to start Cypress with environment variables to connect to the MongoDB locally

$ as-a chat.io npx cypress open

Start the app and run the tests

Using start-server-and-test utility you can start the application and open Cypress (assuming the services have been started)

# assuming injecting ENV variables using "as-a"
$ as-a chat.io npm run dev

Watching mode

Watching the server

You can start the application server in watch mode. Any file change will automatically restart the server. Uses nodemon

$ npm run watch

Watching the specs

The Cypress tests automatically re-run when the spec files change. They also re-run when any files in the public folder change thanks to the cypress-watch-and-reload plugin.

History

All props for this Chat app goes to the original repo OmarElGabry/chat.io. I have only cloned to show it being tested, added more features, added Cypress tests

About me