I’m trying to run my mocha test suite with puppeteer inside a docker container but it keeps failing. The error message I get is about missing shared libraries: Error: Mocha: Got error running globalSetup - /usr/src/app/node_modules/mocha-environment-puppeteer/setup.js, reason: Failed to launch the browser process! /usr/src/app/node_modules/puppeteer/.local-chromium/linux-884014/chrome-linux/chrome: error while loading shared libraries: libxshmfence.so.1: cannot open shared object file: No such file or directory
I’m pretty new to containerization so I’m not sure what’s missing. Here are my config files:
mocha.config.ts
module.exports = {
setupFiles: ['dotenv/config'],
preset: "mocha-puppeteer",
roots: ['<rootDir>/tests'],
transform: {
'^.+\.tsx?$': 'ts-mocha'
},
testRegex: '(/__tests__/.*|(\.|/)(test|spec))\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
mocha-puppeteer.config.js
module.exports = {
launch: {
headless: true,
defaultViewport: null,
args: ['--start-maximized', '--disable-gpu',
'--disable-dev-shm-usage', '--disable-setuid-sandbox',
'--no-sandbox'],
},
testEnvironmentOptions: { resources: 'usable' },
};
Dockerfile
FROM node:16.14.0
WORKDIR /app/src
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
RUN chown -R node /app/src
USER node
CMD npm run test
I tried installing chrome manually in the container but that didn’t help either.