Dar*_*ony 3 cypress cypress-cucumber-preprocessor
在我将 Cypress 迁移到版本 10 后,Cucumber 预处理器停止工作。我找到了一些实现的解决方案,并且还安装了最新的@badeball/cypress-cucumber-preprocessor。
现在我不知道如何设置 cypress.config.js 文件,因为原始的插件文件夹已被弃用。
在插件文件夹下的旧 index.js 中,我有:
const cucumber = require("cypress-cucumber-preprocessor").default;
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("file:preprocessor", cucumber());
...
Run Code Online (Sandbox Code Playgroud)
现在插件设置应该位于 cypress-config.js 中:
e2e: {
baseUrl: 'http://localhost:4200',
specPattern: 'cypress/e2e/features',
setupNodeEvents(on, config) {
const addCucumberPreprocessorPlugin =
require('@badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin;
on('file:preprocessor', addCucumberPreprocessorPlugin(on, config));
}
},
Run Code Online (Sandbox Code Playgroud)
但现在我有一个错误,因为on('file:preprocessor', addCucumberPreprocessorPlugin());addCucumberPreprocessorPlugin 不是一个函数。我知道不是,但是如何为黄瓜正确配置此部分?我没有找到任何有关此的信息。
如果我只是删除on('file:preprocessor', addCucumberPreprocessorPlugin(on, config));,在执行功能测试文件后,会出现以下错误:
您可能需要适当的加载程序来处理此文件类型,当前没有配置加载程序来处理此文件
我使用的模式是
import { defineConfig } from "cypress";
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
async function setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);
// webpack config goes here if required
return config;
}
module.exports = defineConfig({
e2e: {
specPattern: "**/*.feature",
supportFile: false,
setupNodeEvents,
},
});
Run Code Online (Sandbox Code Playgroud)
您可能还需要一些 webpack 配置,存储库此处有一些示例
这是另一个对我有用的配置
const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild");
async function setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
createBundler({
plugins: [createEsbuildPlugin.default(config)],
})
);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
module.exports = defineConfig({
e2e: {
specPattern: "**/*.feature",
supportFile: false,
setupNodeEvents,
},
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7368 次 |
| 最近记录: |