travelsqosa.blogg.se

Node js docker
Node js docker





With request() we set an Express application of which we want test the endpoints with Chai.We use it() to create a test, describe() to group them in suites.We use chai.should() to choose should as assertion style.We use e() to add the chai-http plugin to Chai.Let's see more in detail how this test is structured: should ( ) describe ( 'Homepage', ( ) => ) Import the dependencies var chai = require ( 'chai' ) var chaiHttp = require ( 'chai-http' ) // Import the application to test var app = require ( './index' ) // Configure ChaiĬhai. If you haven't already created an image from the Dockerfile, do it now Since the first option doesn't need further clarification and the second one has already been examined, let's take the opportunity to see a new approach. Starting a container, update the file inside the container and copy it to the outside in our working directory.Starting a container, update the file inside the container and propagate changes to the outside by using a volume (we saw how to do in the second article of this series).

node js docker

  • Adding the dependencies to the file manually.
  • The Dockerfile, index.js and package.json files from the previous post.īefore building a new image, we have to update the package.json file and add mocha, chai and chai-http (a Chai plugin for testing HTTP endpoints) to the dependencies.
  • node js docker

    In this guide, we'll use Mocha as test framework and Chai as assertion library. Meanwhile, on the app side, we can use the stack that we want. It's easy to create a testing environment and it doesn't need particular configurations as regards the Docker container. Although in the early stages of development it seems that manual testing is enough to check that our app works properly, the growth of its codebase and complexity will make this solution very inefficient and we will need automatic, fast and widespread tests to check the behavior of app's components. In the previous posts, we created a Node.js web application and we learned how to manage its deployment, development and debugging with Docker.







    Node js docker