如何从同一级别的另一个项目调用 Cucumber stepDefinitions?

how to call Cucumber stepDefinitions from another project from the same level?

我有一个包含所有测试项目的项目 integration_test。 我正在使用 cucumberjs/typescript/nodejs.

在 Project1 中实现了登录,我只想从 Project2 和 Project3 调用场景。登录步骤使用 Project1 的登录实现。

如果登录步骤在项目 1 中实现,package.json 中的脚本应该如何来自项目 2?

package.json 项目 2 中的当前脚本:

"test:project2": cucumber-js ./tests/ --require '.tests/**/*.ts' --exit"

见下面的文件夹结构:

   integration_test
          Project1
             -tests
               -features
               -step_definitions
             -package.json
             -cucumber.js
          Project2
            -tests
               -features
               -step_definitions
             -package.json
             -cucumber.js
          Project3
             -tests
               -features
               -step_definitions
             -package.json
             -cucumber.js

cucumber.js 包含:

let common = [
  'features/**/*.feature', // Specify our feature files
  '--require-module ts-node/register', // Load TypeScript module
  '--format node_modules/cucumber-pretty' // Load custom formatter
].join(' ');

您可以使用 cucumberjs 'require' 选项使这个用例成功。只需使用以下内容定义您的 cucumber.js 文件:

let common = [
  './**/tests/features/', // Specify our feature files
    '--require ./../**/tests/step_definitions/**/', // Load step definitions
    '--require ./support/', // Load hooks
].join(' ');

通过这种方式,cucumberjs 加载所有列出的项目中定义的所有步骤定义..