dorriz
dorriz

Reputation: 2689

Run Vue tests in Docker

I have a Dockerfile

FROM node:19-bullseye-slim

WORKDIR /app
# Install prerequisites
RUN apt-get update && apt-get install -y \
gnupg \
curl \
bash 

COPY . /app

CMD ./bootstrap.sh

and a bash script

#!/bin/bash

npm add yarn 
yarn add pm2 ---dev
yarn install
npx playwright install-deps chromium
yarn test
echo "Finished"

The commands:

  1. install Yarn

  2. install dependencies from my app

  3. install Playwright and Chromium browser

  4. Run a test command which is in my package.json file as "test"

     "test": "pm2 start server.js && npm run test:cucumber",
     "test:cucumber": "cucumber-js --require ./cucumber.js --require ./tests/e2e-playwright/step-definitions/**/*.js -f json:cucumber_report.json --publish-quiet",
    

That command should start the dev server for Vue and then run the cucumber tests

My server.js file is

module.exports  = {
    apps: [
      {
        name: "WEB",
        script: "./node_modules/@vue/cli-service/bin/vue-cli-service.js",
        args: "serve"
      }
    ]

};

pm2 starts server.js, which calls vue-cli-service serve (starts the Vue dev-server)

But the vue dev server doesn't start and my tests fail as the application isn't available

If I run vue-cli-service serve everything works as expected , and the website is available at http:localhost:8080

How can I get pm2 to run the server and it will be available?

Can I run my tests and connect with port 8080 in the Docker container, or would I have to point my tests to use host.docker.internal? And how would I do that?

Upvotes: 1

Views: 278

Answers (1)

Dimava
Dimava

Reputation: 10909

Please make sure that you are running the server and test concurrently, like with '&' or https://www.npmjs.com/package/concurrently

The "test": "pm2 start server.js && npm run test:cucumber" seems like it first launches the server, then waits for server to exit, and only then tries to statr tests.

Basically, try running the same commangs (or the same bash) on your own PC before putting it into container

Also,

  • your yarn add pm2 ---dev speaks --dev incorrectly
  • cucumber is likely to be a test dependency, so you may be not installing it
  • You can install the dev dependencies in NODE_ENV=production with yarn install --production=false, you may need that
  • node@>=16 container iirc provides yarn by default

Upvotes: 0

Related Questions