gpt4 book ai didi

angular - 带有 cucumber 的 Angular 中的 Cypress > 未定义进程

转载 作者:行者123 更新时间:2023-12-05 01:26:02 25 4
gpt4 key购买 nike

我尝试在使用 Cucumber 和 TypeScript 的 Angular 12 项目中使用 Cypress 进行端到端测试。

Cypress 本身通过 npx cypress open 成功启动,我创建的功能文件显示如下: cypress with custom feature file

当我开始测试此功能时,我收到以下错误: error in cypress browser

我发现了一个类似的问题 here但没有我可以应用的解决方案。我相信发生此错误是因为我使用的是 cypress-own 浏览器并且 process 变量在那里不可用。我也看过这个 repository但未能找到任何可以解决此问题的方法。

这个项目的package.json是这样的:

{   "name": "randomAppName",   "version": "0.0.0",   "scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"i18n": "ng extract-i18n --output-path src/assets/i18n",
"lint": "eslint . --ext .ts,.js",
"lint-fix": "eslint . --ext .ts,.js" }, "private": true, "dependencies": {
"@angular/animations": "~12.2.0",
"@angular/cdk": "^12.2.5",
"@angular/common": "~12.2.0",
"@angular/compiler": "~12.2.0",
"@angular/core": "~12.2.0",
"@angular/forms": "~12.2.0",
"@angular/material": "^12.2.5",
"@angular/platform-browser": "~12.2.0",
"@angular/platform-browser-dynamic": "~12.2.0",
"@angular/router": "~12.2.0",
"@ngrx/effects": "^12.4.0",
"@ngrx/store": "^12.4.0",
"@ngrx/store-devtools": "^12.4.0",
"moment": "^2.29.1",
"ngrx-forms": "^6.3.5",
"path-browserify": "^1.0.1",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4" }, "cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true }, "devDependencies": {
"@4tw/cypress-drag-drop": "^1.8.0",
"@angular-devkit/build-angular": "~12.2.5",
"@angular-eslint/builder": "12.7.0",
"@angular-eslint/eslint-plugin": "12.7.0",
"@angular-eslint/eslint-plugin-template": "12.7.0",
"@angular-eslint/schematics": "12.7.0",
"@angular-eslint/template-parser": "12.7.0",
"@angular/cdk": "^12.0.1",
"@angular/cli": "~12.2.5",
"@angular/common": "^12.0.1",
"@angular/compiler-cli": "~12.2.0",
"@angular/core": "^12.0.1",
"@angular/localize": "^12.2.5",
"@cucumber/cucumber": "^7.2.1",
"@cypress/browserify-preprocessor": "^3.0.1",
"@cypress/webpack-preprocessor": "^5.9.0",
"@jscutlery/cypress-harness": "^0.3.4",
"@types/jasmine": "~3.8.0",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "4.28.2",
"@typescript-eslint/parser": "4.28.2",
"cucumber": "^6.0.5",
"cucumber-pretty": "^6.0.0",
"cucumber-tsflow": "^4.0.0-rc.1",
"cypress": "^8.4.0",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress-mouse-position": "^1.0.0",
"cypress-pipe": "^2.0.0",
"cypress-xpath": "^1.6.2",
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.25.2",
"jasmine-core": "~3.8.0",
"jest": "^27.2.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"prettier": "^2.5.1",
"rxjs": "^6.6.7",
"ts-loader": "^9.2.6",
"ts-node": "^9.1.1",
"tsify": "^4.0.1",
"typescript": "~4.3.5",
"webpack": "^5.65.0",
"zone.js": "^0.11.4" }, "browser": {
"fs": false,
"os": false,
"path": false } }

webpack.config.js 如下所示:

module.exports = {
resolve: {
modules: ["node_modules"],
extensions: ["*", ".js", ".jsx", ".json"],
symlinks: false,
cacheWithContext: false,
fallback: { path: require.resolve("path-browserify") },
},
node: {},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
{
test: /\.feature$/,
use: [
{
loader: "cypress-cucumber-preprocessor/loader",
},
],
},
],
},
};

请告诉我,如果需要任何其他信息,我很乐意提供。

最佳答案

processundefined 因为在您的案例中,代码正在浏览器中执行。

您可能使用了与 webpack 4 一起工作的配置,它为 path(您已经包含了回退)或在本例中为 process 提供了模拟 api。 Webpack 5 Release Notes: node.process removed

看起来 Cucumber 解析器实际上是通过将 Cucumber 代码发送到浏览器包而在浏览器上下文中使用此加载器执行的。

如果没有特定原因,我建议根本不要使用 webpack。您甚至不需要使用最新的 cypers 版本来编译 typescript 。相反,我建议使用 cypress-cucumber-preprocessor readme 中建议的设置:

如果需要 webpack,您可以尝试模拟流程变量。我验证了将 webpack 5 与 original example repository 一起使用时,将以下内容添加到 support/index.js 是否有效:

window.process = {
argv: [],
env: {},
};

关于angular - 带有 cucumber 的 Angular 中的 Cypress > 未定义进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70519821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com