簡體   English   中英

賽普拉斯在 Angular 和 cucumber > 進程未定義

[英]Cypress in Angular with cucumber > process is not defined

我嘗試在 Cucumber 和 TypeScript 的 Angular 12 項目中使用賽普拉斯進行 e2e 測試。

Cypress 本身通過npx cypress open成功啟動,我創建的功能文件如下所示: 帶有自定義功能文件的柏樹

當我開始測試此功能時,我收到以下錯誤: 賽普拉斯瀏覽器中的錯誤

我在這里發現了類似的問題,但沒有可以應用的解決方案。 我相信會發生此錯誤,因為我使用的是賽普拉斯自己的瀏覽器,並且流程變量在那里不可用。 我還查看了這個存儲庫,但沒有找到任何可以解決這個問題的東西。

該項目的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",
          },
        ],
      },
    ],
  },
};

請讓我知道,如果需要任何其他信息,我將很樂意提供。

process undefined ,因為在您的情況下,代碼正在瀏覽器中執行。

您可能使用了與 webpack 4 一起使用的配置,該配置為path提供了模擬 api(您已經包含了后備)或在本例中為process Webpack 5 發行說明:node.process 已刪除

看起來 cucumber 解析器實際上是在瀏覽器上下文中使用此加載器通過將 cucumber 代碼發送到瀏覽器包來執行的。

如果沒有特別的理由,我建議不要使用 webpack。 您甚至不需要使用最新的 cyperss 版本編譯 typescript。 相反,我建議使用cypress-cucumber-preprocessor 自述文件中建議的設置:

如果需要 webpack,您可以嘗試模擬流程變量。 我驗證了在將 webpack 5 與原始示例存儲庫一起使用時,將以下內容添加到support/index.js是有效的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM