How to config karma with puppeter in docker?

I need puppeter to test some specifics pdf cenarios and stuffs.

currently my karmaConfig is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>module.exports = function (config) {
const process = require("process");
process.env.CHROME_BIN = require("puppeteer").executablePath();
config.set({
basePath: "",
frameworks: ["jasmine", "@angular-devkit/build-angular"],
plugins: [
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-jasmine-html-reporter"),
require("karma-junit-reporter"),
require("karma-coverage-istanbul-reporter"),
require("@angular-devkit/build-angular/plugins/karma"),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require("path").join(__dirname, "./coverage/aaweb"),
reports: ["html", "lcovonly", "text-summary", "cobertura"],
fixWebpackSourcePaths: true,
},
reporters: ["progress", "kjhtml", "junit", "coverage-istanbul"],
junitReporter: {
outputDir: "./junit/aaweb",
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
aautoWatch: true,
browsers: ["Chrome", "ChromeHeadless"],
singleRun: false,
restartOnFileChange: true,
browserDisconnectTolerance: 2,
customLaunchers: {
ChromeDebug: {
base: "Chrome",
flags: ["--remote-debugging-port=9333"],
debug: true,
},
ChromeHeadlessCI: {
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
},
});
};
</code>
<code>module.exports = function (config) { const process = require("process"); process.env.CHROME_BIN = require("puppeteer").executablePath(); config.set({ basePath: "", frameworks: ["jasmine", "@angular-devkit/build-angular"], plugins: [ require("karma-jasmine"), require("karma-chrome-launcher"), require("karma-jasmine-html-reporter"), require("karma-junit-reporter"), require("karma-coverage-istanbul-reporter"), require("@angular-devkit/build-angular/plugins/karma"), ], client: { clearContext: false, // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { dir: require("path").join(__dirname, "./coverage/aaweb"), reports: ["html", "lcovonly", "text-summary", "cobertura"], fixWebpackSourcePaths: true, }, reporters: ["progress", "kjhtml", "junit", "coverage-istanbul"], junitReporter: { outputDir: "./junit/aaweb", }, port: 9876, colors: true, logLevel: config.LOG_INFO, aautoWatch: true, browsers: ["Chrome", "ChromeHeadless"], singleRun: false, restartOnFileChange: true, browserDisconnectTolerance: 2, customLaunchers: { ChromeDebug: { base: "Chrome", flags: ["--remote-debugging-port=9333"], debug: true, }, ChromeHeadlessCI: { base: "ChromeHeadless", flags: ["--no-sandbox"], }, ChromeHeadlessNoSandbox: { base: "ChromeHeadless", flags: ["--no-sandbox"], }, }, }); }; </code>
module.exports = function (config) {
      const process = require("process");
      process.env.CHROME_BIN = require("puppeteer").executablePath();
      config.set({
        basePath: "",
        frameworks: ["jasmine", "@angular-devkit/build-angular"],
        plugins: [
          require("karma-jasmine"),
          require("karma-chrome-launcher"),
          require("karma-jasmine-html-reporter"),
          require("karma-junit-reporter"),
          require("karma-coverage-istanbul-reporter"),
          require("@angular-devkit/build-angular/plugins/karma"),
        ],
        client: {
          clearContext: false, // leave Jasmine Spec Runner output visible in browser
        },
        coverageIstanbulReporter: {
          dir: require("path").join(__dirname, "./coverage/aaweb"),
          reports: ["html", "lcovonly", "text-summary", "cobertura"],
          fixWebpackSourcePaths: true,
        },
        reporters: ["progress", "kjhtml", "junit", "coverage-istanbul"],
        junitReporter: {
          outputDir: "./junit/aaweb",
        },
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        aautoWatch: true,
        browsers: ["Chrome", "ChromeHeadless"],
        singleRun: false,
        restartOnFileChange: true,
        browserDisconnectTolerance: 2,
        customLaunchers: {
          ChromeDebug: {
            base: "Chrome",
            flags: ["--remote-debugging-port=9333"],
            debug: true,
          },
          ChromeHeadlessCI: {
            base: "ChromeHeadless",
            flags: ["--no-sandbox"],
          },
          ChromeHeadlessNoSandbox: {
            base: "ChromeHeadless",
            flags: ["--no-sandbox"],
          },
        },
      });
    };

dockerFile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM node:alpine AS build-angular
WORKDIR /app
RUN npm cache clean --force
COPY ./ /app/
RUN npm install && npm run build
RUN npm test
FROM nginx:alpine
COPY --from=build-angular /app/dist/aplicationame/browser /usr/share/nginx/html
COPY /nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV PUPPETEER_SKIP_DOWNLOAD='true'
RUN apk update && apk install chromium
CMD ["nginx", "-g", "daemon off;"]
</code>
<code>FROM node:alpine AS build-angular WORKDIR /app RUN npm cache clean --force COPY ./ /app/ RUN npm install && npm run build RUN npm test FROM nginx:alpine COPY --from=build-angular /app/dist/aplicationame/browser /usr/share/nginx/html COPY /nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 ENV CHROME_BIN=/usr/bin/chromium-browser ENV PUPPETEER_SKIP_DOWNLOAD='true' RUN apk update && apk install chromium CMD ["nginx", "-g", "daemon off;"] </code>
FROM node:alpine AS build-angular
    
    WORKDIR /app
    RUN npm cache clean --force
    COPY ./ /app/
    RUN npm install && npm run build
    RUN npm test
    
    FROM nginx:alpine
    
    COPY --from=build-angular /app/dist/aplicationame/browser /usr/share/nginx/html
    
    COPY /nginx.conf /etc/nginx/conf.d/default.conf
    
    EXPOSE 80
    
    ENV CHROME_BIN=/usr/bin/chromium-browser
    ENV PUPPETEER_SKIP_DOWNLOAD='true'
    RUN apk update && apk install chromium
    
    CMD ["nginx", "-g", "daemon off;"]

but keeps giving me the error when the tests are executed:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[![Launching browsers ChromeHeadless with concurrency unlimited
60.11 11 09 2024 02:32:06.719:INFO [launcher]: Starting browser ChromeHeadless
60.14 11 09 2024 02:32:06.751:ERROR [launcher]: Cannot start ChromeHeadless
60.14 Can not find the binary /usr/bin/chromium-browser
60.14 Please set env variable CHROME_BIN
</code>
<code>[![Launching browsers ChromeHeadless with concurrency unlimited 60.11 11 09 2024 02:32:06.719:INFO [launcher]: Starting browser ChromeHeadless 60.14 11 09 2024 02:32:06.751:ERROR [launcher]: Cannot start ChromeHeadless 60.14 Can not find the binary /usr/bin/chromium-browser 60.14 Please set env variable CHROME_BIN </code>
[![Launching browsers ChromeHeadless with concurrency unlimited
60.11 11 09 2024 02:32:06.719:INFO [launcher]: Starting browser ChromeHeadless
60.14 11 09 2024 02:32:06.751:ERROR [launcher]: Cannot start ChromeHeadless
60.14   Can not find the binary /usr/bin/chromium-browser
60.14   Please set env variable CHROME_BIN

I`ve already tried to set the path hardcoded like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>process.env.CHROME_BIN = /usr/bin/chromium-browser;
</code>
<code>process.env.CHROME_BIN = /usr/bin/chromium-browser; </code>
process.env.CHROME_BIN = /usr/bin/chromium-browser;

didnt work as well, is there something i`m missing?

maybe this question is duplicated cause i already read like 10 or more posts with the same doubt, but so far none of them solved this issue for me, so if anyone can give me a clue.

Thanks.

UPDATE:

I manage to solve the first issue by adding the following to the dockerfile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>RUN apk update && apk add --no-cache
chromium
udev
ttf-freefont
nss
harfbuzz
freetype
&& rm -rf /var/cache/apk/*
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
</code>
<code>RUN apk update && apk add --no-cache chromium udev ttf-freefont nss harfbuzz freetype && rm -rf /var/cache/apk/* ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser </code>
RUN apk update && apk add --no-cache 
chromium 
udev 
ttf-freefont 
nss 
harfbuzz 
freetype 
&& rm -rf /var/cache/apk/*
      
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

but now i having the problem telling that:

ERROR:zygote_host_impl_linux.cc(89)] Running as root without –no-sandbox is not supported

witch is strange because i already put in my karma.config the following sections:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> browsers: ["Chrome", "ChromeHeadless"],
singleRun: true,
restartOnFileChange: true,
browserDisconnectTolerance: 2,
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
},
browsers: ["ChromeHeadlessNoSandbox"],
singleRun: true,
});
</code>
<code> browsers: ["Chrome", "ChromeHeadless"], singleRun: true, restartOnFileChange: true, browserDisconnectTolerance: 2, customLaunchers: { ChromeHeadlessNoSandbox: { base: "ChromeHeadless", flags: ["--no-sandbox"], }, }, browsers: ["ChromeHeadlessNoSandbox"], singleRun: true, }); </code>
 browsers: ["Chrome", "ChromeHeadless"],
singleRun: true,
restartOnFileChange: true,
browserDisconnectTolerance: 2,
customLaunchers: {
  ChromeHeadlessNoSandbox: {
    base: "ChromeHeadless",
    flags: ["--no-sandbox"],
  },
},
browsers: ["ChromeHeadlessNoSandbox"],
singleRun: true,
  });

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật