NodeJS: How to test nightmareJS e2e when launching the docker application

I am creating a docker image / container for testing purposes from my productive build application (nodeJS app). Now I want to test e2e using mocha / chai and nightmareJS . Therefore, I created a very simple test file.

Now my problem is how to test a running application. Therefore, I want to download an application, for example

- goto http://localhost
- check if login form is existing
- do login
- check if login was successful

I do not know how to do this in my docker / e2e.js-file ...

This is how I create the docker image:

Dockerfile

# Use the production image as base image
FROM productive_build:latest

# Copy the test files
COPY e2e.js /

# Override the NODE_ENV environment variable to 'dev', in order to get required test packages
ENV NODE_ENV dev

# 1. Get test packages; AND
# 2. Install our test framework - mocha
RUN (cd programs/server && npm install)
RUN npm install -g mocha
RUN npm install chai nightmare

# Override the command, to run the test instead of the application
CMD ["mocha", "e2e.js", "--reporter", "spec"]

And here is what my main e2e.js file looks like:

e2e.js

var Nightmare = require('nightmare'),
    expect = require('chai').expect

describe('test', function () {
  it('should always be true', function () {
    var nightmare = Nightmare()
    nightmare.end()
    expect(true).to.be.true
  })
})
+4
2

, Dockerfile,

,

, mocha. , supervisord, , .

bash script CMD:

ENTRYPOINT ["./bin/run.sh"]

script :

#!/bin/bash
npm start & mocha e2e.js --reporter spec

, - , . , , , , .

var Nightmare = require('nightmare')
var expect = require('chai').expect

describe('test login', function () {

 it('should login and display my username', function (done) {
    var nightmare = Nightmare({ show: false })

    nightmare
      .goto('http://localhost:8000') // your local url with the correct port
      .type('#login', 'your login') // change value of the login input
      .type('#password', 'your password')
      .click('#submit') // click the submit button
      .wait('#my-username') // wait for this element to appear (page loaded)
      .evaluate(function () {
        // query something once logged on the page
        return document.querySelector('#my-username').innerText
      })
      .end()
      .then(function (result) {
        // the result will be the thing you grabbed from the window in the evaluate
        expect(result).to.equal('user3142695')
        done()
      })
      .catch(done)

  })

})
+1

: nightmarejs

node.js. nodemon - , Docker nodemon Visual Studio, node.js.

: https://github.com/docker/labs/blob/master/developer-tools/nodejs-debugging/VSCode-README.md

0

Source: https://habr.com/ru/post/1676869/


All Articles