How to config karma with puppeter in docker?

Discussão em 'Angular' iniciado por Percy22, Setembro 11, 2024.

  1. Percy22

    Percy22 Guest

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

    currently my karmaConfig is:

    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:

    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:

    [![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:

    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.

    Continue reading...

Compartilhe esta Página