I want to test my node docker image with "npm run test" as a command overwrite when running my container.
My Dockerfile is:
FROM node:alpine
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY ./ ./
CMD ["npm", "run", "start"]
The "npm run test" command should be run in my container and exit to the terminal (locally and Travis CI) but the test run is stuck at "Ran all test suites." waiting for input.
My docker run command is:
docker run myimage npm run test -- --coverage
I also tried with:
docker run myimage npm run test -- --forceExit
But none of them exits when the test have run (neither locally or in Travis CI).
My App.test.js file is the standard test:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
What should I do to automatically exit the test when it is finished?
If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. You could as well type the exit command. TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl. Then the same with ctrl and d.
Found that the docker run command should contain -e CI=true to exit immediately:
docker run -e CI=true myimage npm run test
From React documentation about "CI=true":
The test command will force Test to run in CI-mode, and tests will only run once instead of launching the watcher.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With