Cypress-webpack-preprocessor 的 Webpack 编译错误

Har*_*ana 5 npm webpack cypress

我无法运行 cypress 测试并出现以下错误:

当我运行 cypress run 时:

它给出了以下 Webpack 编译错误

Webpack Compilation Error
./cypress/integration/features/Pagination.feature
 Module not found: Error: Can't resolve 
'C:UsersCypressProjectode_modulescypress-cucumber-preprocessorlibesolveStepDefinition' in 'C:\Users\CypressProject\cypress\integration\features'
Run Code Online (Sandbox Code Playgroud)

不知何故,上述路径中也不包含反斜杠

我的 webpack 配置文件如下:

module.exports = {
resolve: {
  extensions: [".ts", ".js"]
},

node: { fs: "empty", child_process: "empty", readline: "empty" },
module: {
  rules: [
    {
      test: /\.ts$/,
      exclude: [/node_modules/],
      use: [
        {
          loader: "ts-loader"
        }
      ]
    },
    {
      test: /\.feature$/,
      use: [
        {
          loader: "cypress-cucumber-preprocessor/loader"
        }
      ]
    }
  ]
}
};
Run Code Online (Sandbox Code Playgroud)

我的插件文件:

const wp = require('@cypress/webpack-preprocessor')

const fs = require('fs-extra')
const path = require('path')

function getConfigurationByFile (file) {
  const pathToConfigFile = path.resolve('./cypress/', 'config', `${file}.json`)
  return fs.readJson(pathToConfigFile)
}

module.exports = (on,config) => {
    const file = process.env.ENV_FILE//config.env.envFile
  const options = {     
    webpackOptions: require("../webpack.config.js")
  };
  on('file:preprocessor', wp(options))
  if(file==null){
  return getConfigurationByFile('local');
  }
  else{
    return getConfigurationByFile(file);
  }
}
Run Code Online (Sandbox Code Playgroud)

有人有想法解决吗?

小智 1

你应该在里面设置你的step_definition路径package.json

"cypress-cucumber-preprocessor": {
    "step_definitions": "path/to/steps_definition"
}
Run Code Online (Sandbox Code Playgroud)