首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与黄瓜成角的柏树不确定

与黄瓜成角的柏树不确定
EN

Stack Overflow用户
提问于 2021-12-29 13:04:56
回答 1查看 964关注 0票数 3

我尝试使用Cypress进行e2e测试,在一个与Cucumber和TypeScript一起进行的Range12项目中。

Cypress本身通过npx cypress open成功启动,我创建的特性文件显示:

当我开始对这个特性进行测试时,我会收到以下错误:

我发现了一个类似的问题,这里,但没有解决方案,我可以申请。我认为发生此错误是因为我使用的是柏树本身的浏览器,并且进程变量在那里不可用。我也看了一下这个存储库,但是没有找到任何可以解决这个问题的方法。

该项目的package.json如下所示:

代码语言:javascript
复制
{   "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看起来如下:

代码语言:javascript
复制
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",
          },
        ],
      },
    ],
  },
};

请让我知道,如果需要更多的信息,我将乐意提供。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-29 17:44:31

processundefined,因为在您的情况下,代码是在浏览器中执行的。

您可能使用了与webpack 4一起工作的配置,该配置为path提供了模拟apis (您已经准备好了退路),或者在本例中使用processWebpack 5发行说明: node.process删除

看起来,黄瓜解析器实际上是在浏览器上下文中使用这个加载程序通过向浏览器包发射黄瓜代码来执行的。

如果没有具体的理由,我建议不要使用webpack。您甚至不需要用最近的cyperss版本来转换类型记录。相反,我建议使用cypress-黄瓜-预处理自述中建议的设置

如果需要webpack,您可以尝试模拟流程变量。我验证了在将webpack 5与support/index.js一起使用时,向原始示例存储库添加以下内容是有效的

代码语言:javascript
复制
window.process = {
 argv: [],
 env: {},
};
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70519821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档