有什么方法可以记录cumber.js步骤定义代码中的步骤吗?
我试图用jsduck @class来模拟它:

/**
 * @class Global.steps.common
 * Common steps.
 */
var steps = module.exports = function() {
    /**
     * Step 1 description.
     */
    this.Given(/^StepDef1$/, function(next) {
        ...
    });

    /**
     * Step 2 description.
     */
    this.Given(/^StepDef2$/, function(next) {
        ...
    });
});


但是jsduck仅能识别最后一步的描述。

最佳答案

您将遇到的主要问题是步骤的名称。使用Cucumber,您希望使用较长的纯文本,例如/Given I have entered (.*) into the calculator/,而文档工具则希望您主要记录使用诸如addNumber之类名称的各种标识符(我不太确定JSDoc,但是JSDuck对类和属性名称中允许使用的字符)。

jsduck只识别最后一步的具体问题是由于JSDuck试图自动检测这些doc-block描述的项目名称,将它们都检测为Given,并且不允许这样做。多个具有相同名称的属性,只有最后一个将在最终输出中呈现。

因此,您可以做的就是给您的属性起一个这样的名称:

/**
 * @property Given_I_have_entered_X_into_the_calculator
 * Step 1 description.
 */
this.Given(/^Given I have entered (.*) into the calculator$/, function(next) {
    ...
});


这当然很繁琐。您可以通过extending JSDuck with your own custom tags对此进行改进,因此可以编写:

/**
 * @Given I have entered ? into the calculator
 * Step 1 description.
 */
this.Given(/^Given I have entered (.*) into the calculator$/, function(next) {
    ...
});


不幸的是,JSDuck的自定义标签系统受到限制,因此您无法轻松地从代码中的正则表达式自动检测名称。但是,如果您分叉JSDuck并扩展其内部结构,则可能会发生。

07-24 20:26