material-svelte / vite-web-test-runner-plugin

MIT License
39 stars 13 forks source link

Running tests in docker does not wait for completion #6

Closed bmz1 closed 3 years ago

bmz1 commented 3 years ago

Hi! First of all, thank you for creating this plugin.

From the command line it works great, but I've tried running the tests with docker, and it actually doesn't wait for the tests to complete. I think this is because the vite dev server startup gives back a 0 exit code. This is just a guess though.

Have you tried this plugin in docker? If so, have you faced the same problem?

betaboon commented 3 years ago

hm. I am using it within github-ci which i believe is docker/osi based. could you provide a repro?

bmz1 commented 3 years ago

@betaboon There you go: https://github.com/bmz1/vite-wtr-plugin-repro

betaboon commented 3 years ago

@bmz1

adapted from here

diff --git a/Dockerfile b/Dockerfile
index 28b322d..d25fb95 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,12 +14,6 @@ RUN apt-get update \
 ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
 ENV DOCKER=true

-COPY package.json yarn.lock /app/
+RUN npm i puppeteer

-RUN yarn install
-
-COPY . /app/
-
-RUN yarn test
-
-ENTRYPOINT [ "" ]
+CMD ["google-chrome-stable"]
diff --git a/package.json b/package.json
index a6a4067..25f8f0e 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,9 @@
   "scripts": {
     "dev": "vite",
     "build": "vite build",
-    "test": "web-test-runner --coverage"
+    "test": "web-test-runner --coverage",
+    "docker-build": "docker build -t wtr:v1 .",
+    "docker-test": "docker run -i --init --rm -v $(pwd):/app wtr:v1 yarn test"
   },
   "dependencies": {
     "lit-element": "^2.4.0"
bmz1 commented 3 years ago

@betaboon My problem is not running puppeteer, but the following: test

When I run the tests with the same Dockerfile without the plugin, it waits for the tests to finish. But somehow it does not wait with the plugin.

betaboon commented 3 years ago

tbh I'm not sure if it's the right approach to run the tests in the build-phase of a docker image oO

Edit: i think the main issue here is that during docker build the RUN commands are not run in an interactive-shell, which web-test-runner doesnt seem to like. tbh i think this has nothing to do with this plugin.

Edit2: i just tried to apply the same approach with snowpack. there it somehow works.

IanVS commented 3 years ago

I'm having this same problem as well, in Github actions.

@betaboon if it's working for you, what versions of web-test-runner and vite are you using?

betaboon commented 3 years ago

@IanVS that issue/codepath is a nice find. that would completly explain the behavior. I'm perplexed why it works in my github-actions tho.

"@web/test-runner": "^0.13.3",
"chai": "^4.3.4",
"vite": "^2.2.3",

But i currently don't have the time to look into it. so thank you very much for spending the time and working on a solution :)

bmz1 commented 3 years ago

Merged: https://github.com/vitejs/vite/pull/3659

IanVS commented 3 years ago

@bmz1 after a new version of vite is released, it would be great if you could check that it solves your issue.

IanVS commented 3 years ago

vite@2.4.0-beta.0 has been released with the referenced PR. Does it solve your problem, @bmz1?

bmz1 commented 3 years ago

@IanVS Yes it does 🍾 . Setting ENV CI=true in the Dockerfile solves it. Thanks for your cooperation.

IanVS commented 3 years ago

🎉 should this issue be closed, then?

betaboon commented 3 years ago

perfect. thank you guys for following up :)