简体   繁体   English

错误:开玩笑:运行 globalSetup 时出错 - /home/pptruser/app/node_modules/jest-environment-puppeteer/setup.js

[英]Error: Jest: Got error running globalSetup - /home/pptruser/app/node_modules/jest-environment-puppeteer/setup.js

When running from local, its getting passed.从本地运行时,它会通过。 Below error is thrown when run from docker locally.从 docker 本地运行时抛出以下错误。 I am in the process of setting up my code for my puppeteer test.我正在为我的 puppeteer 测试设置我的代码。

I also included here below package.json, jest-puppeteer.config, jest.config files.我还在 package.json、jest-puppeteer.config、jest.config 文件下方包含了这里。 Here I haven't included my tests files.这里我没有包含我的测试文件。

shall you please someone help?你可以请人帮忙吗? Thanks.谢谢。

Error: Jest: Got error running globalSetup - /home/pptruser/app/node_modules/jest-environment-puppeteer/setup.js, reason: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (1022525).
    at ChromeLauncher.launch (/home/pptruser/app/node_modules/puppeteer/lib/cjs/puppeteer/node/ChromeLauncher.js:70:23)
    at async Promise.all (index 0)
    at async setup (/home/pptruser/app/node_modules/jest-environment-puppeteer/lib/global.js:37:16)
    at async /home/pptruser/app/node_modules/@jest/core/build/runGlobalHook.js:125:13
    at async waitForPromiseWithCleanup (/home/pptruser/app/node_modules/@jest/transform/build/ScriptTransformer.js:209:5)
    at async runGlobalHook (/home/pptruser/app/node_modules/@jest/core/build/runGlobalHook.js:116:9)
    at async runJest (/home/pptruser/app/node_modules/@jest/core/build/runJest.js:369:5)
    at async _run10000 (/home/pptruser/app/node_modules/@jest/core/build/cli/index.js:320:7)
    at async runCLI (/home/pptruser/app/node_modules/@jest/core/build/cli/index.js:173:3)
    at async Object.run (/home/pptruser/app/node_modules/jest-cli/build/cli/index.js:155:37)

jest.config.js: jest.config.js:

module.exports = {
  preset: "jest-puppeteer" 
  notifyMode: "always",
  maxWorkers: "50%",
  maxConcurrency: 150,
  maxWorkers: 1,
  bail: 1,
  collectCoverage: true,
  testRunner: "jest-jasmine2",
  timers: "fake",
  testTimeout: 9000000,
  watchman: false,
};

package.json: package.json:

"devDependencies": {
    "@babel/preset-env": "^7.18.2",
    "babel-jest": "^27.0.6",
    "dotenv": "^16.0.1",
    "jest": "^27.5.1",
    "jest-cli": "^27.5.1",
    "jest-jasmine2": "^27.2.3",
    "jest-puppeteer": "^6.1.0",
    "prettier": "2.5.1",
    "puppeteer": "^14.1.2" 
}

jest-puppeteer.config: jest-puppeteer.config:

module.exports = {
    launch: {
        headless: true,
        slowMo: 0,
        defaultViewport: null,
        args: ["--window-size=1920,1080",
        "--incognito",
        "--start-maximized",
        "--disable-extensions",
        "--no-sandbox",
        "--disable-setuid-sandbox",
        "--no-first-run",
        "--no-zygote"],
        setDefaultNavigationTimeout: 8000000,
        setDefaultTimeout: 8000000,
    },
    browserContext: "default",
};

My docker file:我的 docker 文件:

FROM docker-remote.artifactory.oci.oraclecorp.com/oraclelinux:7-slim
 COPY --from=odo-docker-signed-local.artifactory.oci.oraclecorp.com/odo/base-image-support:ol7x-1.6 / /
RUN yum-config-manager --add-repo https://artifactory.oci.oraclecorp.com/io-ol7-nodejs16-yum-local/ \
    --add-repo https://artifactory.oci.oraclecorp.com/io-ol7-oracle-instant-client-yum-local/ \

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
    ORACLE_NPM=https://artifactory.oci.oraclecorp.com/api/npm/npm-remote/
RUN yum -y update \
    && yum -y install nodejs-16.14.2-1.0.1.el7.x86_64 chromium-102.0.5005.115-1.el7.x86_64 
    
RUN groupadd -r pptruser  \
    && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && mkdir -p /home/pptruser/app \   
    && chown -R pptruser:pptruser /home/pptruser
WORKDIR /home/pptruser/app
COPY --chown=pptruser:pptruser . .
CMD ["npm","run-script smoke"]

The way we solved this was to download Chromium https://download-chromium.appspot.com/ and unzip into a specific folder: .\node_modules\puppeteer.local-chromium\win64-722234我们解决这个问题的方法是下载 Chromium https://download-chromium.appspot.com/并解压缩到特定文件夹: .\node_modules\puppeteer.local-chromium\win64-722234

Some other answers include specifying the path to your chromium like so:其他一些答案包括指定铬的路径,如下所示:

const launchOptions = {
    // other options (headless, args, etc)
    executablePath: '/home/jack/repos/my-repo/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jest 无法从 node_modules 中找到模块“得到” - Jest cannot find module 'got' from node_modules Jest Typescript 带有 ES 模块 in node_modules 错误 - 必须使用导入来加载 ES 模块: - Jest Typescript with ES Module in node_modules error - Must use import to load ES Module: 错误 node_modules/jest-diff/build/diffLines.d.ts(8,13):错误 TS1005:'=' 预期。 在嵌套 js 中 - error node_modules/jest-diff/build/diffLines.d.ts(8,13): error TS1005: '=' expected. in nest js 开玩笑 - 找不到模块'.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault' - Jest - Cannot find module '.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault' 在 docker 容器中运行节点测试时出错 - Error running node test with jest in docker container 错误 [ERR_REQUIRE_ESM]:不支持来自 /app/commands/Image/meme.js 的 ES 模块 /app/node_modules/got/dist/source/index.js 的 require() - Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/got/dist/source/index.js from /app/commands/Image/meme.js not supported Google Cloud Datastore 开玩笑 nodejs node_modules - Google Cloud Datastore jest nodejs node_modules 在玩笑中运行测试时,node_modules 导入未定义 - When runing tests in jest, node_modules imports gets undefined 在GitLab CI中运行./node_modules/.bin/cucumber-js时出错 - Error running ./node_modules/.bin/cucumber-js in GitLab CI 转译验证器 esm node_modules 文件 jest - Transpile validator esm node_modules files jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM