我正在使用 grunt-triggered Cucumber JS 任务尝试一些带有 nodeJS 的 BDD,它工作正常,除了我不想看到完整的 JS 异常堆栈以进行我知道当然会失败的测试。相反,我宁愿只看到异常的(更有用的)头部。这可能看起来微不足道,但我相信最好通过这些工具的快速反馈来实现 BDD。例如,以下是模块中基本缺失方法的完整堆栈跟踪:
TypeError: Object #<Object> has no method 'delete'
at World.<anonymous> ($HOME/features/step_definitions/delete-item.steps.js:20:21)
at Object.invoke ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:84:14)
at Object.execute ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:157:22)
at Object.acceptVisitor ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:149:12)
at Object.executeStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:178:12)
at Object.processStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:173:14)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:66:16
at callUserFunctionAndBroadcastAfterEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:90:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at onRuntimeListenersComplete ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:113:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:16:7
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:15:18)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:118:51
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at Object.broadcastEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:109:7)
at Object.broadcastBeforeEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:100:12)
at Object.broadcastEventAroundUserFunction ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:84:12)
at Object.visitStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:63:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:95:17
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at onRuntimeListenersComplete ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:113:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:16:7
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:15:18)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:118:51
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at Object.broadcastEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:109:7)
at Object.broadcastAfterEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:105:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:95:32
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at onRuntimeListenersComplete ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:113:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at handleStepResult ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:27:5)
at hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:6:9)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:16:7
at handleStepResult ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/stats_journal.js:39:5)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:6:9)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:15:18)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:118:51
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at Object.broadcastEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:109:7)
at Object.visitStepResult ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:79:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:150:17
at codeCallback ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:61:11)
at World.<anonymous> ($HOME/features/step_definitions/delete-item.steps.js:16:3)
at Object.invoke ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:84:14)
at Object.execute ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:157:22)
at Object.acceptVisitor ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:149:12)
at Object.executeStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:178:12)
at Object.processStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:173:14)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:66:16
at callUserFunctionAndBroadcastAfterEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:90:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at onRuntimeListenersComplete ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:113:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:16:7
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:15:18)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:118:51
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at Object.broadcastEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:109:7)
at Object.broadcastBeforeEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:100:12)
at Object.broadcastEventAroundUserFunction ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:84:12)
at Object.visitStep ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:63:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:95:17
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at Object.instructVisitorToVisitSteps ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:94:13)
at Object.instructVisitorToVisitScenarioSteps ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:90:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:75:14
at Object.instructVisitorToVisitBackgroundSteps ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:85:9)
at Object.acceptVisitor ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/scenario.js:74:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:48:41
at callUserFunction ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/library/hooker.js:41:11)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at Object.triggerBeforeHooks ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/library/hooker.js:63:19)
at callBeforeHooks ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/library/hooker.js:37:16)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at hookedUpFunction ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/library/hooker.js:27:21)
at callUserFunctionAndBroadcastAfterEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:90:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at onRuntimeListenersComplete ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:113:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:14:11)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:20:11
at hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:8:9)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:16:7
at handleBeforeScenarioEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/stats_journal.js:24:5)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener.js:6:9)
at Object.hear ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/listener/summary_formatter.js:15:18)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:118:51
at processItem ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:19:9)
at iterate ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:12:11)
at Object.forEach ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/type/collection.js:23:7)
at broadcastToListeners ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:117:19)
at Object.broadcastEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:109:7)
at Object.broadcastBeforeEvent ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:100:12)
at Object.broadcastEventAroundUserFunction ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:84:12)
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:52:14
at $HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/library.js:71:11
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
然后是更有用但仍然不明确的:
Failing scenarios:
$HOME/features/delete-item.feature:6 # Scenario: Item removed from portfolio
$HOME/features/delete-item.feature:11 # Scenario: Item not accessible from portfolio
4 scenarios (2 failed, 2 passed)
12 steps (2 failed, 2 skipped, 8 passed)
实际上,在大多数情况下,我唯一关心的是前四行:
TypeError: Object #<Object> has no method 'delete'
at World.<anonymous> ($HOME/features/step_definitions/delete-item.steps.js:20:21)
at Object.invoke ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:84:14)
at Object.execute ($HOME/node_modules/grunt-cucumber/node_modules/cucumber/lib/cucumber/ast/step.js:157:22)
有任何想法吗?