简体   繁体   English

cypress-cucumber-preprocessor 不解析功能文件

[英]cypress-cucumber-preprocessor does not parse feature files

I have been trying to use cypress-cucumber-preprocessor with cypress to add feature of BDD.我一直在尝试使用 cypress-cucumber-preprocessor 和 cypress 来添加 BDD 的功能。

I have followed the installation steps as mentioned in this link but while running the tests I am getting the below error.我已按照此链接中提到的安装步骤进行操作,但在运行测试时出现以下错误。 It does not parse the feature files.它不解析功能文件。

Error: Webpack Compilation Error

./cypress/e2e/login.feature 1:15 Module parse failed: Unexpected token (1:15) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. ./cypress/e2e/login.feature 1:15 模块解析失败:意外令牌 (1:15) 您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件。 See https://webpack.js.org/concepts#loadershttps://webpack.js.org/concepts#loaders

I was having the same issue and it was because I had installed an old version of the package.我遇到了同样的问题,这是因为我安装了旧版本的软件包。 Here's what you need to do:这是您需要做的:

# if you have the old version installed
npm uninstall cypress-cucumber-preprocessor

npm install @badeball/cypress-cucumber-preprocessor

You can find the quick start document at the repository for the package.您可以在包的存储库中找到快速入门文档 I am trying to use Vue3 with Webpack, so I followed the webpack specific example provided which had me install the Cypress Webpack preprocessor:我正在尝试将 Vue3 与 Webpack 一起使用,因此我遵循了提供的 webpack 特定示例,该示例让我安装了 Cypress Webpack 预处理器:

npm install @cypress/webpack-preprocessor

This is where I had to do something differently.这是我必须做一些不同的事情的地方。 This repository is in Typescript but my current repository is not.此存储库在 Typescript 中,但我当前的存储库不是。 So I converted the TypeScript cypress.config.ts file to a vanilla JavaScript configuration.所以我将TypeScript cypress.config.ts 文件转换为 vanilla JavaScript 配置。 This is what ended up working for me:这最终为我工作:

// ./cypress.config.js
const { defineConfig } = require('cypress');
const webpackPreprocessor = require('@cypress/webpack-preprocessor');
const { addCucumberPreprocessorPlugin } = require('@badeball/cypress-cucumber-preprocessor');

async function setupNodeEvents(on, config) {
  await addCucumberPreprocessorPlugin(on, config);

  const options = {
    webpackOptions: {
      module: {
        rules: [
          {
            test: /\.feature$/,
            use: [
              {
                loader: '@badeball/cypress-cucumber-preprocessor/webpack',
                options: config,
              },
            ],
          },
        ],
      },
    },

  };

  on('file:preprocessor', webpackPreprocessor(options));

  return config;
}

module.exports = {
  default: defineConfig({
    e2e: {
      specPattern: '**/*.feature',
      supportFile: false,
      setupNodeEvents,
    },
  }),
  setupNodeEvents,
};

Good luck—let me know if this needs clarification.祝你好运——让我知道这是否需要澄清。

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

相关问题 Cypress 测试 - 在 typescript 中运行 cypress 测试时,Cucumber 功能文件给出错误“您可能需要适当的加载程序来处理此文件” - Cypress Test - Cucumber feature files giving error "You may need an appropriate loader to handle this file" while running cypress tests in typescript 使用 Cypress-webpack-preprocessor 的 Webpack 编译错误 - Webpack compilation error with Cypress-webpack-preprocessor Webpack Cypress 10 编译错误和 Angular 中的 Cucumber - Webpack Compilation Error with Cypress 10 and Cucumber in Angular 赛普拉斯文件时意外的令牌链接运算符表达式:预处理器读取分叉 - Unexpected token chaining operator expression when cypress file:preprocessor reads a fork 为什么 webpack 尝试解析我的 readme.md 文件 - Why does webpack try to parse my readme.md files 赛普拉斯无头 - 没有配置加载程序来处理 png 文件 - Cypress headless - no loaders are configured to process png files JavaScript(ES2015)是否支持省略括号的预处理器? - Does JavaScript(ES2015) have preprocessor support for omit braces? Webpack [contenthash] 在文件中解析 - Webpack [contenthash] parse in files 在 Visual Studio 中捆绑打字稿文件而不​​会失去 Browserlink 功能 - Bundle typescript files in Visual Studio without loosing Browserlink feature Webpack 2无法解析CSS文件 - Webpack 2 doesn't parse CSS files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM