Reputation: 2689
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:
install Yarn
install dependencies from my app
install Playwright and Chromium browser
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
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,
yarn add pm2 ---dev
speaks --dev
incorrectlyNODE_ENV=production
with yarn install --production=false
, you may need thatUpvotes: 0