mardi 30 avril 2019

Node in Docker: npm test and exit

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?

Aucun commentaire:

Enregistrer un commentaire