[英]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#loaders见https://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.