1

I have container with React application which is running from docker-compose. When I print logs for this container using

docker-compose logs -f

There is a message:

PASS  src/App.test.js
  ✓ renders learn react link (28 ms)
tests_1  |
Test Suites: 1 passed, 1 total
tests_1  | Tests:       1 passed, 1 total
tests_1  | Snapshots:   0 total
tests_1  | Time:        1.258 s
tests_1  | Ran all test suites related to changed files.
tests_1  |
tests_1  | Watch Usage
tests_1  |  › Press a to run all tests.
tests_1  |  › Press f to run only failed tests.
tests_1  |  › Press q to quit watch mode.
tests_1  |  › Press p to filter by a filename regex pattern.
tests_1  |  › Press t to filter by a test name regex pattern.
tests_1  |  › Press Enter to trigger a test run.

Container works with bind mounts. Changes in my project directory are loaded into container. When I add some new tests, how can I "Press Enter to trigger a test run" inside running container? If I can't press enter in container how can I refresh container to run new tests? I use React 17, WSL, Windows and environment variables like FAST_REFRESH or CHOKIDAR_USEPOLLING don't work.

Best regards

Krzysztof
  • 33
  • 3
  • Simply changing a test file (or relevant source file for that matter) also causes them to rerun - why are you running them inside a container locally anyway? Jest sets up the testing "environment" you need to test, you shouldn't need to be environment agnostic outside of that so I'm not sure what benefit running tests inside a docker container would give you – Adam Jenkins Jan 06 '22 at 12:03
  • I totally agree. It's just a kind of small test configuration to check bind mounts behaviour. Unfortunatelly just changing test file doesn't work. Test file is changing inside docker container but react application in docker container doesn't see changes in test file and doesn't trigger tests :( – Krzysztof Jan 06 '22 at 13:04
  • Oh, I see, this is more of a socket bind mounts question than a react test question. I recall doing this locally and having it work just fine with volumes, never tried bind mounts, I guess bind mounts can’t watch the same? – Adam Jenkins Jan 06 '22 at 13:18
  • Theoretically bind mounts should work as expected. They connect with files on your host machine. When you change something locally changes should be visible by docker container with React application. But there is problem. Maybe somebody has the same situation and can help with this issue. – Krzysztof Jan 06 '22 at 14:12

1 Answers1

2

The issue is that the following command shows a stream of logs in the container. But it's not interactive (it's not a shell. It just shows the log).

docker-compose logs -f

If you really do a change to some of the test files in the host machine(in your machine) and save it, it will rerun the tests.

If you run the following docker command in the root folder of your react app it will start an interactive (-it) shell for the started container where you can press Enter to rerun tests.

docker run -it -w /app -v "$(pwd)":/app node:latest sh -c "npm run test" 
Amila Senadheera
  • 12,229
  • 15
  • 27
  • 43