@lynxwall/cucumber-tsflow 7.1.2 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +154 -61
  2. package/lib/api/convert-configuration.d.ts +7 -0
  3. package/lib/api/convert-configuration.js +65 -0
  4. package/lib/api/convert-configuration.js.map +1 -0
  5. package/lib/api/index.d.ts +1 -0
  6. package/lib/api/index.js +1 -0
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/load-configuration.d.ts +3 -2
  9. package/lib/api/load-configuration.js +78 -18
  10. package/lib/api/load-configuration.js.map +1 -1
  11. package/lib/api/run-cucumber.d.ts +5 -1
  12. package/lib/api/run-cucumber.js +12 -0
  13. package/lib/api/run-cucumber.js.map +1 -1
  14. package/lib/api/wrapper.mjs +1 -0
  15. package/lib/bindings/binding-context.d.ts +54 -3
  16. package/lib/bindings/binding-context.js +80 -5
  17. package/lib/bindings/binding-context.js.map +1 -1
  18. package/lib/bindings/binding-decorator.js +85 -36
  19. package/lib/bindings/binding-decorator.js.map +1 -1
  20. package/lib/bindings/binding-registry.js +10 -0
  21. package/lib/bindings/binding-registry.js.map +1 -1
  22. package/lib/bindings/hook-decorators.js +44 -19
  23. package/lib/bindings/hook-decorators.js.map +1 -1
  24. package/lib/bindings/step-decorators.js +120 -51
  25. package/lib/bindings/step-decorators.js.map +1 -1
  26. package/lib/bindings/types.js.map +1 -1
  27. package/lib/cli/argv-parser.d.ts +1 -0
  28. package/lib/cli/argv-parser.js +2 -2
  29. package/lib/cli/argv-parser.js.map +1 -1
  30. package/lib/cli/index.js +1 -4
  31. package/lib/cli/index.js.map +1 -1
  32. package/lib/runtime/make-runtime.d.ts +3 -2
  33. package/lib/runtime/make-runtime.js.map +1 -1
  34. package/lib/runtime/message-collector.d.ts +1 -1
  35. package/lib/runtime/message-collector.js.map +1 -1
  36. package/lib/runtime/parallel/adapter.d.ts +3 -2
  37. package/lib/runtime/parallel/adapter.js +2 -1
  38. package/lib/runtime/parallel/adapter.js.map +1 -1
  39. package/lib/runtime/parallel/run-worker.js +3 -2
  40. package/lib/runtime/parallel/run-worker.js.map +1 -1
  41. package/lib/runtime/parallel/worker.d.ts +3 -2
  42. package/lib/runtime/parallel/worker.js +4 -2
  43. package/lib/runtime/parallel/worker.js.map +1 -1
  44. package/lib/runtime/test-case-runner.d.ts +2 -1
  45. package/lib/runtime/test-case-runner.js +8 -5
  46. package/lib/runtime/test-case-runner.js.map +1 -1
  47. package/lib/runtime/{parallel/types.d.ts → types.d.ts} +12 -1
  48. package/lib/runtime/types.js.map +1 -0
  49. package/lib/transpilers/esbuild-transpiler.d.ts +1 -1
  50. package/lib/transpilers/esbuild-transpiler.js.map +1 -1
  51. package/lib/transpilers/esbuild.js +18 -1
  52. package/lib/transpilers/esbuild.js.map +1 -1
  53. package/lib/transpilers/esm/esbuild-transpiler-cjs.js +2174 -0
  54. package/lib/transpilers/esm/esbuild-transpiler.mjs +19 -0
  55. package/lib/transpilers/esm/esbuild.mjs +141 -0
  56. package/lib/transpilers/esm/esmbuild-transpiler.d.ts +4 -0
  57. package/lib/transpilers/esm/esmbuild-transpiler.js +19 -0
  58. package/lib/transpilers/esm/esmbuild-transpiler.js.map +1 -0
  59. package/lib/transpilers/esm/esmbuild.d.ts +12 -0
  60. package/lib/transpilers/esm/esmbuild.js +72 -0
  61. package/lib/transpilers/esm/esmbuild.js.map +1 -0
  62. package/lib/transpilers/esm/esmnode.js +8 -0
  63. package/lib/transpilers/esm/esmnode.js.map +1 -0
  64. package/lib/transpilers/esm/esmvue.js +29 -0
  65. package/lib/transpilers/esm/esmvue.js.map +1 -0
  66. package/lib/transpilers/esm/esnode-loader.mjs +9 -0
  67. package/lib/transpilers/esm/esvue-loader.mjs +9 -0
  68. package/lib/transpilers/esm/loader-utils.mjs +278 -0
  69. package/lib/transpilers/esm/tsnode-esm.js +25 -0
  70. package/lib/transpilers/esm/tsnode-esm.js.map +1 -0
  71. package/lib/{esnode.js → transpilers/esm/tsnode-exp-esm.js} +8 -6
  72. package/lib/transpilers/esm/tsnode-exp-esm.js.map +1 -0
  73. package/lib/transpilers/esm/tsnode-loader.mjs +107 -0
  74. package/lib/transpilers/esm/tsnode-service.mjs +40 -0
  75. package/lib/transpilers/esm/tsvue-esm.d.ts +1 -0
  76. package/lib/{tsvue.js → transpilers/esm/tsvue-esm.js} +8 -5
  77. package/lib/transpilers/esm/tsvue-esm.js.map +1 -0
  78. package/lib/transpilers/esm/tsvue-exp-esm.d.ts +1 -0
  79. package/lib/transpilers/esm/tsvue-exp-esm.js +40 -0
  80. package/lib/transpilers/esm/tsvue-exp-esm.js.map +1 -0
  81. package/lib/transpilers/esm/vue-jsdom-setup.mjs +19 -0
  82. package/lib/transpilers/esm/vue-loader.mjs +113 -0
  83. package/lib/transpilers/esm/vue-sfc-compiler.mjs +216 -0
  84. package/lib/transpilers/esnode.d.ts +1 -0
  85. package/lib/transpilers/esnode.js +8 -0
  86. package/lib/transpilers/esnode.js.map +1 -0
  87. package/lib/transpilers/esvue.d.ts +1 -0
  88. package/lib/transpilers/esvue.js +29 -0
  89. package/lib/transpilers/esvue.js.map +1 -0
  90. package/lib/transpilers/tsnode-exp.d.ts +1 -0
  91. package/lib/transpilers/tsnode-exp.js +19 -0
  92. package/lib/transpilers/tsnode-exp.js.map +1 -0
  93. package/lib/transpilers/tsnode.d.ts +1 -0
  94. package/lib/{tsnode.js → transpilers/tsnode.js} +5 -2
  95. package/lib/transpilers/tsnode.js.map +1 -0
  96. package/lib/transpilers/tsvue-exp.d.ts +1 -0
  97. package/lib/transpilers/tsvue-exp.js +40 -0
  98. package/lib/transpilers/tsvue-exp.js.map +1 -0
  99. package/lib/transpilers/tsvue.d.ts +1 -0
  100. package/lib/{esvue.js → transpilers/tsvue.js} +9 -7
  101. package/lib/transpilers/tsvue.js.map +1 -0
  102. package/lib/transpilers/vue-sfc/index.js.map +1 -1
  103. package/lib/tsconfig.node.tsbuildinfo +1 -1
  104. package/lib/version.d.ts +1 -1
  105. package/lib/version.js +1 -1
  106. package/lib/version.js.map +1 -1
  107. package/package.json +38 -25
  108. package/lib/esnode.js.map +0 -1
  109. package/lib/esvue.js.map +0 -1
  110. package/lib/runtime/parallel/types.js.map +0 -1
  111. package/lib/tsnode.js.map +0 -1
  112. package/lib/tsvue.js.map +0 -1
  113. /package/lib/runtime/{parallel/types.js → types.js} +0 -0
  114. /package/lib/{esnode.d.ts → transpilers/esm/esmnode.d.ts} +0 -0
  115. /package/lib/{esvue.d.ts → transpilers/esm/esmvue.d.ts} +0 -0
  116. /package/lib/{tsnode.d.ts → transpilers/esm/tsnode-esm.d.ts} +0 -0
  117. /package/lib/{tsvue.d.ts → transpilers/esm/tsnode-exp-esm.d.ts} +0 -0
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.binding = binding;
7
7
  const cucumber_1 = require("@cucumber/cucumber");
8
8
  const binding_context_1 = require("./binding-context");
9
- const index_1 = __importDefault(require("@cucumber/cucumber/lib/support_code_library_builder/index"));
10
9
  const binding_registry_1 = require("./binding-registry");
11
10
  const step_binding_1 = require("./step-binding");
12
11
  const cucumber_2 = require("@cucumber/cucumber");
@@ -29,36 +28,60 @@ const stepPatternRegistrations = new Map();
29
28
  * An instance of the decorated class will be created for each scenario.
30
29
  */
31
30
  function binding(requiredContextTypes) {
32
- return function classDecorator(target, context) {
33
- const bindingRegistry = binding_registry_1.BindingRegistry.instance;
34
- bindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);
35
- const lib = index_1.default;
36
- defineParameters();
37
- // the class decorator is called last when decorators on a type are initialized. All other decorators
38
- // are added to DecoratorContext.metadata before this is called.
39
- // This will get all those bindings and then clear metadata for the next type that's loaded.
40
- const allBindings = (0, binding_context_1.getStepBindings)(context);
41
- allBindings.forEach(stepBinding => {
42
- // Set the class prototype and then register the binding with the prototype
43
- stepBinding.classPrototype = target.prototype;
44
- bindingRegistry.registerStepBinding(stepBinding);
45
- if (stepBinding.bindingType & step_binding_1.StepBindingFlags.StepDefinitions) {
46
- let stepBindingFlags = stepPatternRegistrations.get(stepBinding.stepPattern.toString());
47
- if (stepBindingFlags === undefined) {
48
- stepBindingFlags = step_binding_1.StepBindingFlags.none;
31
+ if (global.experimentalDecorators) {
32
+ return (target) => {
33
+ const bindingRegistry = binding_registry_1.BindingRegistry.instance;
34
+ bindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);
35
+ defineParameters();
36
+ // the class decorator is called last when decorators on a type are initialized. All other decorators
37
+ // are added to DecoratorContext.metadata before this is called.
38
+ // This will get all those bindings and then clear metadata for the next type that's loaded.
39
+ const allBindings = (0, binding_context_1.getStepBindingsExp)();
40
+ allBindings.forEach(stepBinding => {
41
+ // For static methods, we need to set the classPrototype to the class itself, not the prototype
42
+ if (stepBinding.stepIsStatic) {
43
+ stepBinding.classPrototype = target;
49
44
  }
50
- if (stepBindingFlags & stepBinding.bindingType) {
51
- return;
45
+ else {
46
+ stepBinding.classPrototype = target.prototype;
52
47
  }
53
- bindStepDefinition(stepBinding);
54
- stepPatternRegistrations.set(stepBinding.stepPattern.toString(), stepBindingFlags | stepBinding.bindingType);
55
- }
56
- else if (stepBinding.bindingType & step_binding_1.StepBindingFlags.Hooks) {
57
- bindHook(stepBinding);
58
- }
59
- });
60
- return target;
61
- };
48
+ bindingRegistry.registerStepBinding(stepBinding);
49
+ // Register with cucumber
50
+ addStepBinding(stepBinding);
51
+ });
52
+ };
53
+ }
54
+ else {
55
+ return function classDecorator(target, context) {
56
+ const bindingRegistry = binding_registry_1.BindingRegistry.instance;
57
+ bindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);
58
+ defineParameters();
59
+ // the class decorator is called last when decorators on a type are initialized. All other decorators
60
+ // are added to DecoratorContext.metadata before this is called.
61
+ // This will get all those bindings and then clear metadata for the next type that's loaded.
62
+ const allBindings = (0, binding_context_1.getStepBindings)(context);
63
+ allBindings.forEach(stepBinding => {
64
+ // Set the class prototype and then register the binding with the prototype
65
+ stepBinding.classPrototype = target.prototype;
66
+ bindingRegistry.registerStepBinding(stepBinding);
67
+ // add the step binding to the binding registry
68
+ addStepBinding(stepBinding);
69
+ });
70
+ // Process pending step bindings after class is decorated
71
+ context.addInitializer(function () {
72
+ // Get all the collected bindings
73
+ const allBindings = (0, binding_context_1.getCollectedBindings)();
74
+ allBindings.forEach(stepBinding => {
75
+ // Set the class prototype and register
76
+ stepBinding.classPrototype = target.prototype;
77
+ bindingRegistry.registerStepBinding(stepBinding);
78
+ // Register with cucumber - call the local addStepBinding function
79
+ addStepBinding(stepBinding);
80
+ });
81
+ });
82
+ return target;
83
+ };
84
+ }
62
85
  }
63
86
  /**
64
87
  * Called only once to register new parameters. This has to be
@@ -73,6 +96,27 @@ const defineParameters = underscore_1.default.once(() => {
73
96
  transformer: s => (s === 'true' ? true : false)
74
97
  });
75
98
  });
99
+ /**
100
+ * Common helper used to add StepBindings to the binding registry
101
+ * @param stepBinding
102
+ * @returns
103
+ */
104
+ function addStepBinding(stepBinding) {
105
+ if (stepBinding.bindingType & step_binding_1.StepBindingFlags.StepDefinitions) {
106
+ let stepBindingFlags = stepPatternRegistrations.get(stepBinding.stepPattern.toString());
107
+ if (stepBindingFlags === undefined) {
108
+ stepBindingFlags = step_binding_1.StepBindingFlags.none;
109
+ }
110
+ if (stepBindingFlags & stepBinding.bindingType) {
111
+ return;
112
+ }
113
+ bindStepDefinition(stepBinding);
114
+ stepPatternRegistrations.set(stepBinding.stepPattern.toString(), stepBindingFlags | stepBinding.bindingType);
115
+ }
116
+ else if (stepBinding.bindingType & step_binding_1.StepBindingFlags.Hooks) {
117
+ bindHook(stepBinding);
118
+ }
119
+ }
76
120
  /**
77
121
  * Binds a step definition to Cucumber.
78
122
  *
@@ -131,16 +175,21 @@ function bindStepDefinition(stepBinding) {
131
175
  * @param stepBinding The [[StepBinding]] that represents a 'before', or 'after', step definition.
132
176
  */
133
177
  function bindHook(stepBinding) {
134
- // beforeAll and afterAll are called before and after all tests.
135
- // these can be class instance or static functions
136
178
  const globalHookFunction = function () {
137
- // if the function is static we need to add it to the associated class first
138
- if (stepBinding.stepIsStatic && !stepBinding.classPrototype[stepBinding.classPropertyKey]) {
139
- stepBinding.classPrototype[stepBinding.classPropertyKey] = stepBinding.stepFunction;
179
+ // Check if it's a static method
180
+ if (stepBinding.stepIsStatic || !stepBinding.classPrototype[stepBinding.classPropertyKey]) {
181
+ const constructor = stepBinding.classPrototype.constructor;
182
+ if (constructor && constructor[stepBinding.classPropertyKey]) {
183
+ return constructor[stepBinding.classPropertyKey].apply(constructor);
184
+ }
185
+ }
186
+ // For non-static methods
187
+ if (stepBinding.classPrototype[stepBinding.classPropertyKey]) {
188
+ return stepBinding.classPrototype[stepBinding.classPropertyKey].apply(stepBinding.classPrototype);
140
189
  }
141
- return stepBinding.classPrototype[stepBinding.classPropertyKey].apply();
190
+ throw new Error(`Method ${String(stepBinding.classPropertyKey)} not found on class ${stepBinding.classPrototype?.constructor?.name}`);
142
191
  };
143
- // Main binding for all other steps
192
+ // Main binding for all other hooks (before, after, beforeStep, afterStep)
144
193
  const hookFunction = function (arg) {
145
194
  const scenarioContext = global.messageCollector.getHookScenarioContext(arg);
146
195
  if (scenarioContext) {
@@ -1 +1 @@
1
- {"version":3,"file":"binding-decorator.js","sourceRoot":"","sources":["../../src/bindings/binding-decorator.ts"],"names":[],"mappings":";;;;;AA0CA,0BAgCC;AA1ED,iDAW4B;AAC5B,uDAAoD;AACpD,sGAAkG;AAClG,yDAAkE;AAClE,iDAA+D;AAE/D,iDAAyD;AACzD,4DAA2B;AAM3B;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAiC,CAAC;AAE1E;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,oBAAoC;IAC3D,OAAO,SAAS,cAAc,CAAC,MAAgB,EAAE,OAA8B;QAC9E,MAAM,eAAe,GAAG,kCAAe,CAAC,QAAQ,CAAC;QACjD,eAAe,CA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EAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;YACtC,MAAM;QACP,CAAC;QACD,KAAK,+BAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7B,MAAM,OAAO,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;YACnG,IAAA,gBAAK,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAC7B,MAAM;QACP,CAAC;QACD,KAAK,+BAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;YACjC,MAAM,OAAO,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;YACnG,IAAA,oBAAS,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACjC,MAAM;QACP,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import {\r\n\tAfter,\r\n\tAfterStep,\r\n\tAfterAll,\r\n\tBefore,\r\n\tBeforeStep,\r\n\tBeforeAll,\r\n\tGiven,\r\n\tThen,\r\n\tWhen,\r\n\tWorld\r\n} from '@cucumber/cucumber';\r\nimport { getStepBindings } from './binding-context';\r\nimport supportCodeLibraryBuilder from '@cucumber/cucumber/lib/support_code_library_builder/index';\r\nimport { BindingRegistry, DEFAULT_TAG } from './binding-registry';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport { ContextType, StepPattern } from './types';\r\nimport { defineParameterType } from '@cucumber/cucumber';\r\nimport _ from 'underscore';\r\n\r\ninterface WritableWorld extends World {\r\n\t[key: string]: any;\r\n}\r\n\r\n/**\r\n * A set of step patterns that have been registered with Cucumber.\r\n *\r\n * In order to support scoped (or tagged) step definitions, we must ensure that any step binding is\r\n * only registered with Cucumber once. The binding function for that step pattern then becomes\r\n * responsible for looking up and execuing the step binding based on the context that is in scope at\r\n * the point of invocation.\r\n */\r\nconst stepPatternRegistrations = new Map<StepPattern, StepBindingFlags>();\r\n\r\n/**\r\n * A class decorator that marks the associated class as a CucumberJS binding.\r\n *\r\n * @param requiredContextTypes An optional array of Types that will be created and passed into the created\r\n * object for each scenario.\r\n *\r\n * An instance of the decorated class will be created for each scenario.\r\n */\r\nexport function binding(requiredContextTypes?: ContextType[]): any {\r\n\treturn function classDecorator(target: Function, context: ClassDecoratorContext) {\r\n\t\tconst bindingRegistry = BindingRegistry.instance;\r\n\t\tbindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);\r\n\t\tconst lib = supportCodeLibraryBuilder;\r\n\t\tdefineParameters();\r\n\r\n\t\t// the class decorator is called last when decorators on a type are initialized. All other decorators\r\n\t\t// are added to DecoratorContext.metadata before this is called.\r\n\t\t// This will get all those bindings and then clear metadata for the next type that's loaded.\r\n\t\tconst allBindings: StepBinding[] = getStepBindings(context);\r\n\t\tallBindings.forEach(stepBinding => {\r\n\t\t\t// Set the class prototype and then register the binding with the prototype\r\n\t\t\tstepBinding.classPrototype = target.prototype;\r\n\t\t\tbindingRegistry.registerStepBinding(stepBinding);\r\n\r\n\t\t\tif (stepBinding.bindingType & StepBindingFlags.StepDefinitions) {\r\n\t\t\t\tlet stepBindingFlags = stepPatternRegistrations.get(stepBinding.stepPattern.toString());\r\n\t\t\t\tif (stepBindingFlags === undefined) {\r\n\t\t\t\t\tstepBindingFlags = StepBindingFlags.none;\r\n\t\t\t\t}\r\n\t\t\t\tif (stepBindingFlags & stepBinding.bindingType) {\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tbindStepDefinition(stepBinding);\r\n\t\t\t\tstepPatternRegistrations.set(stepBinding.stepPattern.toString(), stepBindingFlags | stepBinding.bindingType);\r\n\t\t\t} else if (stepBinding.bindingType & StepBindingFlags.Hooks) {\r\n\t\t\t\tbindHook(stepBinding);\r\n\t\t\t}\r\n\t\t});\r\n\t\treturn target;\r\n\t};\r\n}\r\n\r\n/**\r\n * Called only once to register new parameters. This has to be\r\n * executed here during binding initialization for cucumber to\r\n * to use it when matching expressions. Attempting to add it\r\n * before the test run doesn't work\r\n */\r\nconst defineParameters = _.once(() => {\r\n\tdefineParameterType({\r\n\t\tname: 'boolean',\r\n\t\tregexp: /true|false/,\r\n\t\ttransformer: s => (s === 'true' ? true : false)\r\n\t});\r\n});\r\n\r\n/**\r\n * Binds a step definition to Cucumber.\r\n *\r\n * @param stepBinding The [[StepBinding]] that represents a 'given', 'when', or 'then' step definition.\r\n */\r\nfunction bindStepDefinition(stepBinding: StepBinding): void {\r\n\tconst stepFunction = function (this: WritableWorld): any {\r\n\t\tconst bindingRegistry = BindingRegistry.instance;\r\n\r\n\t\tconst scenarioContext = global.messageCollector.getStepScenarioContext(stepBinding);\r\n\t\tif (scenarioContext) {\r\n\t\t\tconst matchingStepBindings = bindingRegistry.getStepBindings(\r\n\t\t\t\tstepBinding.stepPattern.toString(),\r\n\t\t\t\tscenarioContext.scenarioInfo.tags\r\n\t\t\t);\r\n\r\n\t\t\tif (matchingStepBindings.length > 1) {\r\n\t\t\t\tlet message = `Ambiguous step definitions for '${matchingStepBindings[0].stepPattern}':\\n`;\r\n\r\n\t\t\t\tmatchingStepBindings.forEach(matchingStepBinding => {\r\n\t\t\t\t\tmessage =\r\n\t\t\t\t\t\tmessage +\r\n\t\t\t\t\t\t`\\t\\t${String(matchingStepBinding.classPropertyKey)} (${matchingStepBinding.callsite.toString()})\\n`;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tthrow new Error(message);\r\n\t\t\t} else if (matchingStepBindings.length === 0) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Cannot find matched step definition for ${stepBinding.stepPattern.toString()} with tag ${\r\n\t\t\t\t\t\tscenarioContext.scenarioInfo.tags\r\n\t\t\t\t\t} in binding registry`\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst contextTypes = bindingRegistry.getContextTypesForClass(matchingStepBindings[0].classPrototype);\r\n\t\t\tconst bindingObject = scenarioContext.getOrActivateBindingClass(\r\n\t\t\t\tmatchingStepBindings[0].classPrototype,\r\n\t\t\t\tcontextTypes,\r\n\t\t\t\tthis\r\n\t\t\t);\r\n\t\t\tbindingObject._worldObj = this;\r\n\r\n\t\t\treturn (bindingObject[matchingStepBindings[0].classPropertyKey] as Function).apply(\r\n\t\t\t\tbindingObject,\r\n\t\t\t\targuments as any\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tthrow new Error('Unable to find the Scenario Context for a Step!');\r\n\t\t}\r\n\t};\r\n\r\n\tObject.defineProperty(stepFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\r\n\t// initialize options used on all step bindings\r\n\tconst options = {\r\n\t\tcucumberKey: stepBinding.cucumberKey,\r\n\t\ttimeout: stepBinding.timeout,\r\n\t\twrapperOptions: stepBinding.wrapperOption\r\n\t};\r\n\t// call appropriate step\r\n\tif (stepBinding.bindingType & StepBindingFlags.given) {\r\n\t\tGiven(stepBinding.stepPattern, options, stepFunction);\r\n\t} else if (stepBinding.bindingType & StepBindingFlags.when) {\r\n\t\tWhen(stepBinding.stepPattern, options, stepFunction);\r\n\t} else if (stepBinding.bindingType & StepBindingFlags.then) {\r\n\t\tThen(stepBinding.stepPattern, options, stepFunction);\r\n\t}\r\n}\r\n\r\n/**\r\n * Binds a hook to Cucumber.\r\n *\r\n * @param stepBinding The [[StepBinding]] that represents a 'before', or 'after', step definition.\r\n */\r\nfunction bindHook(stepBinding: StepBinding): void {\r\n\t// beforeAll and afterAll are called before and after all tests.\r\n\t// these can be class instance or static functions\r\n\tconst globalHookFunction = function (this: any): any {\r\n\t\t// if the function is static we need to add it to the associated class first\r\n\t\tif (stepBinding.stepIsStatic && !stepBinding.classPrototype[stepBinding.classPropertyKey]) {\r\n\t\t\tstepBinding.classPrototype[stepBinding.classPropertyKey] = stepBinding.stepFunction;\r\n\t\t}\r\n\t\treturn stepBinding.classPrototype[stepBinding.classPropertyKey].apply() as () => void;\r\n\t};\r\n\t// Main binding for all other steps\r\n\tconst hookFunction = function (this: any, arg: any): any {\r\n\t\tconst scenarioContext = global.messageCollector.getHookScenarioContext(arg);\r\n\t\tif (scenarioContext) {\r\n\t\t\tconst contextTypes = BindingRegistry.instance.getContextTypesForClass(stepBinding.classPrototype);\r\n\t\t\tconst bindingObject = scenarioContext.getOrActivateBindingClass(stepBinding.classPrototype, contextTypes, this);\r\n\t\t\tbindingObject._worldObj = this;\r\n\t\t\treturn (bindingObject[stepBinding.classPropertyKey] as Function).apply(bindingObject, arguments as any);\r\n\t\t} else {\r\n\t\t\tthrow new Error('Unable to find the Scenario Context for Hook!');\r\n\t\t}\r\n\t};\r\n\t// length values need to be added to our binding functions.\r\n\t// These are used in cucumber to determine if the function is\r\n\t// a callback or promise.\r\n\tObject.defineProperty(globalHookFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\tObject.defineProperty(hookFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\r\n\tconst tags = stepBinding.tags === DEFAULT_TAG ? undefined : stepBinding.tags;\r\n\r\n\t// This binds the appropriate function above to the associated\r\n\t// cucumber step functions.\r\n\tswitch (stepBinding.bindingType) {\r\n\t\tcase StepBindingFlags.beforeAll: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };\r\n\t\t\tBeforeAll(options, globalHookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.before: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tBefore(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.beforeStep: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tBeforeStep(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.afterAll: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };\r\n\t\t\tAfterAll(options, globalHookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.after: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tAfter(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.afterStep: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tAfterStep(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n"]}
1
+ {"version":3,"file":"binding-decorator.js","sourceRoot":"","sources":["../../src/bindings/binding-decorator.ts"],"names":[],"mappings":";;;;;AAyCA,0BA8DC;AAvGD,iDAW4B;AAC5B,uDAA8F;AAC9F,yDAAkE;AAClE,iDAA+D;AAE/D,iDAAyD;AACzD,4DAA2B;AAM3B;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAiC,CAAC;AAE1E;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,oBAAoC;IAC3D,IAAI,MAAM,CAAC,sBAAsB,EAAE,CAAC;QACnC,OAAO,CAAI,MAAmC,EAAE,EAAE;YACjD,MAAM,eAAe,GAAG,kCAAe,CAAC,QAAQ,CAAC;YACjD,eAAe,CAAC,4BAA4B,CAAC,MAAM,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;YACrF,gBAAgB,EAAE,CAAC;YAEnB,qGAAqG;YACrG,gEAAgE;YAChE,4FAA4F;YAC5F,MAAM,WAAW,GAAkB,IAAA,oCAAkB,GAAE,CAAC;YACxD,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;gBACjC,+FAA+F;gBAC/F,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;oBAC9B,W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,OAAO,EAAE,CAAC;YACvF,IAAA,mBAAQ,EAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;YACtC,MAAM;QACP,CAAC;QACD,KAAK,+BAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7B,MAAM,OAAO,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;YACnG,IAAA,gBAAK,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAC7B,MAAM;QACP,CAAC;QACD,KAAK,+BAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;YACjC,MAAM,OAAO,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;YACnG,IAAA,oBAAS,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACjC,MAAM;QACP,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import {\r\n\tAfter,\r\n\tAfterStep,\r\n\tAfterAll,\r\n\tBefore,\r\n\tBeforeStep,\r\n\tBeforeAll,\r\n\tGiven,\r\n\tThen,\r\n\tWhen,\r\n\tWorld\r\n} from '@cucumber/cucumber';\r\nimport { getStepBindings, getStepBindingsExp, getCollectedBindings } from './binding-context';\r\nimport { BindingRegistry, DEFAULT_TAG } from './binding-registry';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport { ContextType, StepPattern } from './types';\r\nimport { defineParameterType } from '@cucumber/cucumber';\r\nimport _ from 'underscore';\r\n\r\ninterface WritableWorld extends World {\r\n\t[key: string]: any;\r\n}\r\n\r\n/**\r\n * A set of step patterns that have been registered with Cucumber.\r\n *\r\n * In order to support scoped (or tagged) step definitions, we must ensure that any step binding is\r\n * only registered with Cucumber once. The binding function for that step pattern then becomes\r\n * responsible for looking up and execuing the step binding based on the context that is in scope at\r\n * the point of invocation.\r\n */\r\nconst stepPatternRegistrations = new Map<StepPattern, StepBindingFlags>();\r\n\r\n/**\r\n * A class decorator that marks the associated class as a CucumberJS binding.\r\n *\r\n * @param requiredContextTypes An optional array of Types that will be created and passed into the created\r\n * object for each scenario.\r\n *\r\n * An instance of the decorated class will be created for each scenario.\r\n */\r\nexport function binding(requiredContextTypes?: ContextType[]): any {\r\n\tif (global.experimentalDecorators) {\r\n\t\treturn <T>(target: { new (...args: any[]): T }) => {\r\n\t\t\tconst bindingRegistry = BindingRegistry.instance;\r\n\t\t\tbindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);\r\n\t\t\tdefineParameters();\r\n\r\n\t\t\t// the class decorator is called last when decorators on a type are initialized. All other decorators\r\n\t\t\t// are added to DecoratorContext.metadata before this is called.\r\n\t\t\t// This will get all those bindings and then clear metadata for the next type that's loaded.\r\n\t\t\tconst allBindings: StepBinding[] = getStepBindingsExp();\r\n\t\t\tallBindings.forEach(stepBinding => {\r\n\t\t\t\t// For static methods, we need to set the classPrototype to the class itself, not the prototype\r\n\t\t\t\tif (stepBinding.stepIsStatic) {\r\n\t\t\t\t\tstepBinding.classPrototype = target;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tstepBinding.classPrototype = target.prototype;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tbindingRegistry.registerStepBinding(stepBinding);\r\n\r\n\t\t\t\t// Register with cucumber\r\n\t\t\t\taddStepBinding(stepBinding);\r\n\t\t\t});\r\n\t\t};\r\n\t} else {\r\n\t\treturn function classDecorator(target: Function, context: ClassDecoratorContext) {\r\n\t\t\tconst bindingRegistry = BindingRegistry.instance;\r\n\t\t\tbindingRegistry.registerContextTypesForClass(target.prototype, requiredContextTypes);\r\n\t\t\tdefineParameters();\r\n\r\n\t\t\t// the class decorator is called last when decorators on a type are initialized. All other decorators\r\n\t\t\t// are added to DecoratorContext.metadata before this is called.\r\n\t\t\t// This will get all those bindings and then clear metadata for the next type that's loaded.\r\n\t\t\tconst allBindings: StepBinding[] = getStepBindings(context);\r\n\t\t\tallBindings.forEach(stepBinding => {\r\n\t\t\t\t// Set the class prototype and then register the binding with the prototype\r\n\t\t\t\tstepBinding.classPrototype = target.prototype;\r\n\t\t\t\tbindingRegistry.registerStepBinding(stepBinding);\r\n\r\n\t\t\t\t// add the step binding to the binding registry\r\n\t\t\t\taddStepBinding(stepBinding);\r\n\t\t\t});\r\n\r\n\t\t\t// Process pending step bindings after class is decorated\r\n\t\t\tcontext.addInitializer(function () {\r\n\t\t\t\t// Get all the collected bindings\r\n\t\t\t\tconst allBindings = getCollectedBindings();\r\n\r\n\t\t\t\tallBindings.forEach(stepBinding => {\r\n\t\t\t\t\t// Set the class prototype and register\r\n\t\t\t\t\tstepBinding.classPrototype = target.prototype;\r\n\t\t\t\t\tbindingRegistry.registerStepBinding(stepBinding);\r\n\r\n\t\t\t\t\t// Register with cucumber - call the local addStepBinding function\r\n\t\t\t\t\taddStepBinding(stepBinding);\r\n\t\t\t\t});\r\n\t\t\t});\r\n\r\n\t\t\treturn target;\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Called only once to register new parameters. This has to be\r\n * executed here during binding initialization for cucumber to\r\n * to use it when matching expressions. Attempting to add it\r\n * before the test run doesn't work\r\n */\r\nconst defineParameters = _.once(() => {\r\n\tdefineParameterType({\r\n\t\tname: 'boolean',\r\n\t\tregexp: /true|false/,\r\n\t\ttransformer: s => (s === 'true' ? true : false)\r\n\t});\r\n});\r\n\r\n/**\r\n * Common helper used to add StepBindings to the binding registry\r\n * @param stepBinding\r\n * @returns\r\n */\r\nfunction addStepBinding(stepBinding: StepBinding): void {\r\n\tif (stepBinding.bindingType & StepBindingFlags.StepDefinitions) {\r\n\t\tlet stepBindingFlags = stepPatternRegistrations.get(stepBinding.stepPattern.toString());\r\n\t\tif (stepBindingFlags === undefined) {\r\n\t\t\tstepBindingFlags = StepBindingFlags.none;\r\n\t\t}\r\n\t\tif (stepBindingFlags & stepBinding.bindingType) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tbindStepDefinition(stepBinding);\r\n\t\tstepPatternRegistrations.set(stepBinding.stepPattern.toString(), stepBindingFlags | stepBinding.bindingType);\r\n\t} else if (stepBinding.bindingType & StepBindingFlags.Hooks) {\r\n\t\tbindHook(stepBinding);\r\n\t}\r\n}\r\n\r\n/**\r\n * Binds a step definition to Cucumber.\r\n *\r\n * @param stepBinding The [[StepBinding]] that represents a 'given', 'when', or 'then' step definition.\r\n */\r\nfunction bindStepDefinition(stepBinding: StepBinding): void {\r\n\tconst stepFunction = function (this: WritableWorld): any {\r\n\t\tconst bindingRegistry = BindingRegistry.instance;\r\n\r\n\t\tconst scenarioContext = global.messageCollector.getStepScenarioContext(stepBinding);\r\n\r\n\t\tif (scenarioContext) {\r\n\t\t\tconst matchingStepBindings = bindingRegistry.getStepBindings(\r\n\t\t\t\tstepBinding.stepPattern.toString(),\r\n\t\t\t\tscenarioContext.scenarioInfo.tags\r\n\t\t\t);\r\n\r\n\t\t\tif (matchingStepBindings.length > 1) {\r\n\t\t\t\tlet message = `Ambiguous step definitions for '${matchingStepBindings[0].stepPattern}':\\n`;\r\n\r\n\t\t\t\tmatchingStepBindings.forEach(matchingStepBinding => {\r\n\t\t\t\t\tmessage =\r\n\t\t\t\t\t\tmessage +\r\n\t\t\t\t\t\t`\\t\\t${String(matchingStepBinding.classPropertyKey)} (${matchingStepBinding.callsite.toString()})\\n`;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tthrow new Error(message);\r\n\t\t\t} else if (matchingStepBindings.length === 0) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Cannot find matched step definition for ${stepBinding.stepPattern.toString()} with tag ${\r\n\t\t\t\t\t\tscenarioContext.scenarioInfo.tags\r\n\t\t\t\t\t} in binding registry`\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst contextTypes = bindingRegistry.getContextTypesForClass(matchingStepBindings[0].classPrototype);\r\n\t\t\tconst bindingObject = scenarioContext.getOrActivateBindingClass(\r\n\t\t\t\tmatchingStepBindings[0].classPrototype,\r\n\t\t\t\tcontextTypes,\r\n\t\t\t\tthis\r\n\t\t\t);\r\n\t\t\tbindingObject._worldObj = this;\r\n\r\n\t\t\treturn (bindingObject[matchingStepBindings[0].classPropertyKey] as Function).apply(\r\n\t\t\t\tbindingObject,\r\n\t\t\t\targuments as any\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tthrow new Error('Unable to find the Scenario Context for a Step!');\r\n\t\t}\r\n\t};\r\n\r\n\tObject.defineProperty(stepFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\r\n\t// initialize options used on all step bindings\r\n\tconst options = {\r\n\t\tcucumberKey: stepBinding.cucumberKey,\r\n\t\ttimeout: stepBinding.timeout,\r\n\t\twrapperOptions: stepBinding.wrapperOption\r\n\t};\r\n\t// call appropriate step\r\n\tif (stepBinding.bindingType & StepBindingFlags.given) {\r\n\t\tGiven(stepBinding.stepPattern, options, stepFunction);\r\n\t} else if (stepBinding.bindingType & StepBindingFlags.when) {\r\n\t\tWhen(stepBinding.stepPattern, options, stepFunction);\r\n\t} else if (stepBinding.bindingType & StepBindingFlags.then) {\r\n\t\tThen(stepBinding.stepPattern, options, stepFunction);\r\n\t}\r\n}\r\n\r\n/**\r\n * Binds a hook to Cucumber.\r\n *\r\n * @param stepBinding The [[StepBinding]] that represents a 'before', or 'after', step definition.\r\n */\r\nfunction bindHook(stepBinding: StepBinding): void {\r\n\tconst globalHookFunction = function (this: any): any {\r\n\t\t// Check if it's a static method\r\n\t\tif (stepBinding.stepIsStatic || !stepBinding.classPrototype[stepBinding.classPropertyKey]) {\r\n\t\t\tconst constructor = stepBinding.classPrototype.constructor;\r\n\r\n\t\t\tif (constructor && constructor[stepBinding.classPropertyKey]) {\r\n\t\t\t\treturn constructor[stepBinding.classPropertyKey].apply(constructor);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// For non-static methods\r\n\t\tif (stepBinding.classPrototype[stepBinding.classPropertyKey]) {\r\n\t\t\treturn stepBinding.classPrototype[stepBinding.classPropertyKey].apply(stepBinding.classPrototype);\r\n\t\t}\r\n\r\n\t\tthrow new Error(\r\n\t\t\t`Method ${String(stepBinding.classPropertyKey)} not found on class ${stepBinding.classPrototype?.constructor?.name}`\r\n\t\t);\r\n\t};\r\n\t// Main binding for all other hooks (before, after, beforeStep, afterStep)\r\n\tconst hookFunction = function (this: any, arg: any): any {\r\n\t\tconst scenarioContext = global.messageCollector.getHookScenarioContext(arg);\r\n\t\tif (scenarioContext) {\r\n\t\t\tconst contextTypes = BindingRegistry.instance.getContextTypesForClass(stepBinding.classPrototype);\r\n\t\t\tconst bindingObject = scenarioContext.getOrActivateBindingClass(stepBinding.classPrototype, contextTypes, this);\r\n\t\t\tbindingObject._worldObj = this;\r\n\t\t\treturn (bindingObject[stepBinding.classPropertyKey] as Function).apply(bindingObject, arguments as any);\r\n\t\t} else {\r\n\t\t\tthrow new Error('Unable to find the Scenario Context for Hook!');\r\n\t\t}\r\n\t};\r\n\t// length values need to be added to our binding functions.\r\n\t// These are used in cucumber to determine if the function is\r\n\t// a callback or promise.\r\n\tObject.defineProperty(globalHookFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\tObject.defineProperty(hookFunction, 'length', {\r\n\t\tvalue: stepBinding.stepArgsLength\r\n\t});\r\n\r\n\tconst tags = stepBinding.tags === DEFAULT_TAG ? undefined : stepBinding.tags;\r\n\r\n\t// This binds the appropriate function above to the associated\r\n\t// cucumber step functions.\r\n\tswitch (stepBinding.bindingType) {\r\n\t\tcase StepBindingFlags.beforeAll: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };\r\n\t\t\tBeforeAll(options, globalHookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.before: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tBefore(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.beforeStep: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tBeforeStep(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.afterAll: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };\r\n\t\t\tAfterAll(options, globalHookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.after: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tAfter(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tcase StepBindingFlags.afterStep: {\r\n\t\t\tconst options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };\r\n\t\t\tAfterStep(options, hookFunction);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n"]}
@@ -113,6 +113,16 @@ class BindingRegistry {
113
113
  targetBinding.stepBindings.push(stepBinding);
114
114
  }
115
115
  function isSameStepBinding(a, b) {
116
+ // For hooks, we need to check the binding type and method name too
117
+ if (a.bindingType & step_binding_1.StepBindingFlags.Hooks) {
118
+ return (a.callsite.filename === b.callsite.filename &&
119
+ a.callsite.lineNumber === b.callsite.lineNumber &&
120
+ String(a.tags) === String(b.tags) &&
121
+ String(a.stepPattern) === String(b.stepPattern) &&
122
+ a.bindingType === b.bindingType &&
123
+ a.classPropertyKey === b.classPropertyKey);
124
+ }
125
+ // For step definitions, the existing check is fine
116
126
  return (a.callsite.filename === b.callsite.filename &&
117
127
  a.callsite.lineNumber === b.callsite.lineNumber &&
118
128
  String(a.tags) === String(b.tags) &&
@@ -1 +1 @@
1
- {"version":3,"file":"binding-registry.js","sourceRoot":"","sources":["../../src/bindings/binding-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AC;wBACF,MAAM;oBACP,KAAK,+BAAgB,CAAC,KAAK;wBAC1B,kBAAkB,GAAG,OAAO,CAAC,4BAA4B,CAAC,IAAI,CAC7D,CAAC,CAAC,EAAE,CAAE,CAAC,CAAC,OAAe,CAAC,WAAW,KAAK,WAAW,CAAC,WAAW,CAC/D,CAAC;wBACF,MAAM;oBACP,KAAK,+BAAgB,CAAC,QAAQ;wBAC7B,kBAAkB,GAAG,OAAO,CAAC,2BAA2B,CAAC,IAAI,CAC5D,CAAC,CAAC,EAAE,CAAE,CAAC,CAAC,OAAe,CAAC,WAAW,KAAK,WAAW,CAAC,WAAW,CAC/D,CAAC;wBACF,MAAM;gBACR,CAAC;gBACD,IAAI,kBAAkB,EAAE,CAAC;oBACxB,kBAAkB,CAAC,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC;oBAC1D,kBAAkB,CAAC,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACxD,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC;IAEF;;;;;;;OAOG;IACK,yBAAyB,CAAC,IAAe,EAAE,MAAmC;QACrF,MAAM,oBAAoB,GAAgC,oBAAC,CAAC,OAAO,CAAC,oBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEzG,OAAO,oBAAC,CAAC,MAAM,CAAC,oBAAoB,EAAE,WAAW,CAAC,EAAE,CAAC,WAAW,KAAK,SAAS,CAAkB,CAAC;IAClG,CAAC;CACD;AA7QD,0CA6QC","sourcesContent":["import { SupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types';\r\nimport _ from 'underscore';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport { ContextType, StepPattern, TagName } from './types';\r\nimport logger from '../utils/logger';\r\n\r\n/**\r\n * Describes the binding metadata that is associated with a binding class.\r\n */\r\ninterface ClassBinding {\r\n\t/**\r\n\t * A reference to the step bindings that are associated with the binding class.\r\n\t */\r\n\tstepBindings: StepBinding[];\r\n\r\n\t/**\r\n\t * The context types that are to be injected into the binding class during execution.\r\n\t */\r\n\tcontextTypes: ContextType[];\r\n}\r\n\r\n/**\r\n * Represents the default step pattern.\r\n */\r\nexport const DEFAULT_STEP_PATTERN = '/.*/';\r\n\r\n/**\r\n * Represents the default tag.\r\n */\r\nexport const DEFAULT_TAG = '*';\r\n\r\n/**\r\n * A metadata registry that captures information about bindings and their bound step bindings.\r\n */\r\nexport class BindingRegistry {\r\n\tprivate _stepBindings = new Map<StepPattern, Map<TagName, StepBinding[]>>();\r\n\tprivate _classBindings = new Map<any, ClassBinding>();\r\n\r\n\t/**\r\n\t * Gets the binding registry singleton.\r\n\t *\r\n\t * @returns A [[BindingRegistry]].\r\n\t */\r\n\tpublic static get instance(): BindingRegistry {\r\n\t\tconst BINDING_REGISTRY_SLOTNAME = '__CUCUMBER_TSFLOW_BINDINGREGISTRY';\r\n\r\n\t\tconst registry = (global as any)[BINDING_REGISTRY_SLOTNAME];\r\n\r\n\t\tif (!registry) {\r\n\t\t\t(global as any)[BINDING_REGISTRY_SLOTNAME] = new BindingRegistry();\r\n\t\t}\r\n\r\n\t\treturn registry || (global as any)[BINDING_REGISTRY_SLOTNAME];\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the binding registry with information about the context types required by a\r\n\t * binding class.\r\n\t *\r\n\t * @param classPrototype The class representing the binding (constructor function).\r\n\t * @param contextTypes An array of [[ContextType]] that define the types of objects that\r\n\t * should be injected into the binding class during a scenario execution.\r\n\t */\r\n\tpublic registerContextTypesForClass(classPrototype: any, contextTypes?: ContextType[]): void {\r\n\t\tif (!contextTypes) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tlet targetDecorations = this._classBindings.get(classPrototype);\r\n\r\n\t\tif (!targetDecorations) {\r\n\t\t\ttargetDecorations = {\r\n\t\t\t\tstepBindings: [],\r\n\t\t\t\tcontextTypes: []\r\n\t\t\t};\r\n\r\n\t\t\tthis._classBindings.set(classPrototype, targetDecorations);\r\n\t\t}\r\n\r\n\t\ttargetDecorations.contextTypes = contextTypes;\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the context types that have been registered for a given binding class.\r\n\t *\r\n\t * @param classPrototype The class representing the binding (constructor function).\r\n\t *\r\n\t * @returns An array of [[ContextType]] that have been registered for the specified\r\n\t * binding class.\r\n\t */\r\n\tpublic getContextTypesForClass(classPrototype: any): ContextType[] {\r\n\t\tconst targetBinding = this._classBindings.get(classPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\treturn targetBinding.contextTypes;\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the binding registry indexes with a step binding.\r\n\t *\r\n\t * @param stepBinding The step binding that is to be registered with the binding registry.\r\n\t */\r\n\tpublic registerStepBinding(stepBinding: StepBinding): void {\r\n\t\tif (!stepBinding.tags) {\r\n\t\t\tstepBinding.tags = DEFAULT_TAG;\r\n\t\t}\r\n\r\n\t\tif (stepBinding.tags !== DEFAULT_TAG && !stepBinding.tags.startsWith('@')) {\r\n\t\t\t// tslint:disable-next-line:no-console\r\n\t\t\tlogger.debug('tag should start with @; tsflow has stopped to automatically prepend @ for you.');\r\n\t\t}\r\n\r\n\t\tconst stepPattern: StepPattern = stepBinding.stepPattern\r\n\t\t\t? stepBinding.stepPattern.toString()\r\n\t\t\t: DEFAULT_STEP_PATTERN;\r\n\r\n\t\tlet tagMap = this._stepBindings.get(stepPattern);\r\n\r\n\t\tif (!tagMap) {\r\n\t\t\ttagMap = new Map<TagName, StepBinding[]>();\r\n\r\n\t\t\tthis._stepBindings.set(stepPattern, tagMap);\r\n\t\t}\r\n\r\n\t\tlet stepBindings = tagMap.get(stepBinding.tags);\r\n\r\n\t\tif (!stepBindings) {\r\n\t\t\tstepBindings = [];\r\n\r\n\t\t\ttagMap.set(stepBinding.tags, stepBindings);\r\n\t\t}\r\n\r\n\t\tif (!stepBindings.some(b => isSameStepBinding(stepBinding, b))) {\r\n\t\t\tstepBindings.push(stepBinding);\r\n\t\t}\r\n\r\n\t\t// Index the step binding for the target\r\n\r\n\t\tlet targetBinding = this._classBindings.get(stepBinding.classPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\ttargetBinding = {\r\n\t\t\t\tstepBindings: [],\r\n\t\t\t\tcontextTypes: []\r\n\t\t\t};\r\n\r\n\t\t\tthis._classBindings.set(stepBinding.classPrototype, targetBinding);\r\n\t\t}\r\n\r\n\t\tif (!targetBinding.stepBindings.some(b => isSameStepBinding(stepBinding, b))) {\r\n\t\t\ttargetBinding.stepBindings.push(stepBinding);\r\n\t\t}\r\n\r\n\t\tfunction isSameStepBinding(a: StepBinding, b: StepBinding) {\r\n\t\t\treturn (\r\n\t\t\t\ta.callsite.filename === b.callsite.filename &&\r\n\t\t\t\ta.callsite.lineNumber === b.callsite.lineNumber &&\r\n\t\t\t\tString(a.tags) === String(b.tags) &&\r\n\t\t\t\tString(a.stepPattern) === String(b.stepPattern)\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the step bindings that have been registered for a given binding class.\r\n\t *\r\n\t * @param targetPrototype The class representing the binding (constructor function).\r\n\t *\r\n\t * @returns An array of [[StepBinding]] objects that have been registered for the specified\r\n\t * binding class.\r\n\t */\r\n\tpublic getStepBindingsForTarget(targetPrototype: any): StepBinding[] {\r\n\t\tconst targetBinding = this._classBindings.get(targetPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\treturn targetBinding.stepBindings;\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the step bindings for a given step pattern and collection of tag names.\r\n\t *\r\n\t * @param stepPattern The step pattern to search.\r\n\t * @param tags An array of [[TagName]] to search.\r\n\t *\r\n\t * @returns An array of [[StepBinding]] that map to the given step pattern and set of tag names.\r\n\t */\r\n\tpublic getStepBindings(stepPattern: StepPattern, tags: TagName[]): StepBinding[] {\r\n\t\tconst tagMap = this._stepBindings.get(stepPattern);\r\n\r\n\t\tif (!tagMap) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\tconst matchingStepBindings = this.mapTagNamesToStepBindings(tags, tagMap);\r\n\r\n\t\tif (matchingStepBindings.length > 0) {\r\n\t\t\treturn matchingStepBindings;\r\n\t\t}\r\n\r\n\t\treturn this.mapTagNamesToStepBindings(['*'], tagMap);\r\n\t}\r\n\r\n\tpublic getStepBindingByCucumberKey(cucumberKey: string): StepBinding | undefined {\r\n\t\tlet result: StepBinding | undefined = undefined;\r\n\t\tfor (const [_, binding] of this._classBindings) {\r\n\t\t\tfor (const stepBinding of binding.stepBindings) {\r\n\t\t\t\tif (stepBinding.cucumberKey === cucumberKey) {\r\n\t\t\t\t\tresult = stepBinding;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (result) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the SupportCodeLibrary from Cucumber with\r\n\t * callsite information from tsflow bindings\r\n\t * @param library\r\n\t * @returns\r\n\t */\r\n\tpublic updateSupportCodeLibrary = (library: SupportCodeLibrary): SupportCodeLibrary => {\r\n\t\tthis._classBindings.forEach(binding => {\r\n\t\t\tbinding.stepBindings.forEach(stepBinding => {\r\n\t\t\t\tlet cucumberDefinition: any | undefined = undefined;\r\n\t\t\t\tswitch (stepBinding.bindingType) {\r\n\t\t\t\t\tcase StepBindingFlags.beforeAll:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestRunHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.before:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestCaseHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.beforeStep:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestStepHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.given:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.when:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.then:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.afterStep:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestStepHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.after:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestCaseHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.afterAll:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestRunHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (cucumberDefinition) {\r\n\t\t\t\t\tcucumberDefinition.line = stepBinding.callsite.lineNumber;\r\n\t\t\t\t\tcucumberDefinition.uri = stepBinding.callsite.filename;\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t});\r\n\t\treturn library;\r\n\t};\r\n\r\n\t/**\r\n\t * Maps an array of tag names to an array of associated step bindings.\r\n\t *\r\n\t * @param tags An array of [[TagName]].\r\n\t * @param tagMap The map of [[TagName]] -> [[StepBinding]] to use when mapping.\r\n\t *\r\n\t * @returns An array of [[StepBinding]].\r\n\t */\r\n\tprivate mapTagNamesToStepBindings(tags: TagName[], tagMap: Map<TagName, StepBinding[]>): StepBinding[] {\r\n\t\tconst matchingStepBindings: (StepBinding | undefined)[] = _.flatten(_.map(tags, tag => tagMap.get(tag)));\r\n\r\n\t\treturn _.reject(matchingStepBindings, stepBinding => stepBinding === undefined) as StepBinding[];\r\n\t}\r\n}\r\n"]}
1
+ {"version":3,"file":"binding-registry.js","sourceRoot":"","sources":["../../src/bindings/binding-registry.ts"],"names":[],"mappings":";;;;;;AACA,4DAA2B;AAC3B,iDAA+D;AAE/D,6DAAqC;AAiBrC;;GAEG;AACU,QAAA,oBAAoB,GAAG,MAAM,CAAC;AAE3C;;GAEG;AACU,QAAA,WAAW,GAAG,GAAG,CAAC;AAE/B;;GAEG;AACH,MAAa,eAAe;IACnB,aAAa,GAAG,IAAI,GAAG,EAA4C,CAAC;IACpE,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;IAEtD;;;;OAIG;IACI,MAAM,KAAK,QAAQ;QAC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AAC,WAAW,KAAK,SAAS,CAAkB,CAAC;IAClG,CAAC;CACD;AAxRD,0CAwRC","sourcesContent":["import { SupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types';\r\nimport _ from 'underscore';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport { ContextType, StepPattern, TagName } from './types';\r\nimport logger from '../utils/logger';\r\n\r\n/**\r\n * Describes the binding metadata that is associated with a binding class.\r\n */\r\ninterface ClassBinding {\r\n\t/**\r\n\t * A reference to the step bindings that are associated with the binding class.\r\n\t */\r\n\tstepBindings: StepBinding[];\r\n\r\n\t/**\r\n\t * The context types that are to be injected into the binding class during execution.\r\n\t */\r\n\tcontextTypes: ContextType[];\r\n}\r\n\r\n/**\r\n * Represents the default step pattern.\r\n */\r\nexport const DEFAULT_STEP_PATTERN = '/.*/';\r\n\r\n/**\r\n * Represents the default tag.\r\n */\r\nexport const DEFAULT_TAG = '*';\r\n\r\n/**\r\n * A metadata registry that captures information about bindings and their bound step bindings.\r\n */\r\nexport class BindingRegistry {\r\n\tprivate _stepBindings = new Map<StepPattern, Map<TagName, StepBinding[]>>();\r\n\tprivate _classBindings = new Map<any, ClassBinding>();\r\n\r\n\t/**\r\n\t * Gets the binding registry singleton.\r\n\t *\r\n\t * @returns A [[BindingRegistry]].\r\n\t */\r\n\tpublic static get instance(): BindingRegistry {\r\n\t\tconst BINDING_REGISTRY_SLOTNAME = '__CUCUMBER_TSFLOW_BINDINGREGISTRY';\r\n\r\n\t\tconst registry = (global as any)[BINDING_REGISTRY_SLOTNAME];\r\n\r\n\t\tif (!registry) {\r\n\t\t\t(global as any)[BINDING_REGISTRY_SLOTNAME] = new BindingRegistry();\r\n\t\t}\r\n\r\n\t\treturn registry || (global as any)[BINDING_REGISTRY_SLOTNAME];\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the binding registry with information about the context types required by a\r\n\t * binding class.\r\n\t *\r\n\t * @param classPrototype The class representing the binding (constructor function).\r\n\t * @param contextTypes An array of [[ContextType]] that define the types of objects that\r\n\t * should be injected into the binding class during a scenario execution.\r\n\t */\r\n\tpublic registerContextTypesForClass(classPrototype: any, contextTypes?: ContextType[]): void {\r\n\t\tif (!contextTypes) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tlet targetDecorations = this._classBindings.get(classPrototype);\r\n\r\n\t\tif (!targetDecorations) {\r\n\t\t\ttargetDecorations = {\r\n\t\t\t\tstepBindings: [],\r\n\t\t\t\tcontextTypes: []\r\n\t\t\t};\r\n\r\n\t\t\tthis._classBindings.set(classPrototype, targetDecorations);\r\n\t\t}\r\n\r\n\t\ttargetDecorations.contextTypes = contextTypes;\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the context types that have been registered for a given binding class.\r\n\t *\r\n\t * @param classPrototype The class representing the binding (constructor function).\r\n\t *\r\n\t * @returns An array of [[ContextType]] that have been registered for the specified\r\n\t * binding class.\r\n\t */\r\n\tpublic getContextTypesForClass(classPrototype: any): ContextType[] {\r\n\t\tconst targetBinding = this._classBindings.get(classPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\treturn targetBinding.contextTypes;\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the binding registry indexes with a step binding.\r\n\t *\r\n\t * @param stepBinding The step binding that is to be registered with the binding registry.\r\n\t */\r\n\tpublic registerStepBinding(stepBinding: StepBinding): void {\r\n\t\tif (!stepBinding.tags) {\r\n\t\t\tstepBinding.tags = DEFAULT_TAG;\r\n\t\t}\r\n\r\n\t\tif (stepBinding.tags !== DEFAULT_TAG && !stepBinding.tags.startsWith('@')) {\r\n\t\t\t// tslint:disable-next-line:no-console\r\n\t\t\tlogger.debug('tag should start with @; tsflow has stopped to automatically prepend @ for you.');\r\n\t\t}\r\n\r\n\t\tconst stepPattern: StepPattern = stepBinding.stepPattern\r\n\t\t\t? stepBinding.stepPattern.toString()\r\n\t\t\t: DEFAULT_STEP_PATTERN;\r\n\r\n\t\tlet tagMap = this._stepBindings.get(stepPattern);\r\n\r\n\t\tif (!tagMap) {\r\n\t\t\ttagMap = new Map<TagName, StepBinding[]>();\r\n\t\t\tthis._stepBindings.set(stepPattern, tagMap);\r\n\t\t}\r\n\r\n\t\tlet stepBindings = tagMap.get(stepBinding.tags);\r\n\r\n\t\tif (!stepBindings) {\r\n\t\t\tstepBindings = [];\r\n\t\t\ttagMap.set(stepBinding.tags, stepBindings);\r\n\t\t}\r\n\r\n\t\tif (!stepBindings.some(b => isSameStepBinding(stepBinding, b))) {\r\n\t\t\tstepBindings.push(stepBinding);\r\n\t\t}\r\n\r\n\t\t// Index the step binding for the target\r\n\t\tlet targetBinding = this._classBindings.get(stepBinding.classPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\ttargetBinding = {\r\n\t\t\t\tstepBindings: [],\r\n\t\t\t\tcontextTypes: []\r\n\t\t\t};\r\n\r\n\t\t\tthis._classBindings.set(stepBinding.classPrototype, targetBinding);\r\n\t\t}\r\n\r\n\t\tif (!targetBinding.stepBindings.some(b => isSameStepBinding(stepBinding, b))) {\r\n\t\t\ttargetBinding.stepBindings.push(stepBinding);\r\n\t\t}\r\n\r\n\t\tfunction isSameStepBinding(a: StepBinding, b: StepBinding) {\r\n\t\t\t// For hooks, we need to check the binding type and method name too\r\n\t\t\tif (a.bindingType & StepBindingFlags.Hooks) {\r\n\t\t\t\treturn (\r\n\t\t\t\t\ta.callsite.filename === b.callsite.filename &&\r\n\t\t\t\t\ta.callsite.lineNumber === b.callsite.lineNumber &&\r\n\t\t\t\t\tString(a.tags) === String(b.tags) &&\r\n\t\t\t\t\tString(a.stepPattern) === String(b.stepPattern) &&\r\n\t\t\t\t\ta.bindingType === b.bindingType &&\r\n\t\t\t\t\ta.classPropertyKey === b.classPropertyKey\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\t// For step definitions, the existing check is fine\r\n\t\t\treturn (\r\n\t\t\t\ta.callsite.filename === b.callsite.filename &&\r\n\t\t\t\ta.callsite.lineNumber === b.callsite.lineNumber &&\r\n\t\t\t\tString(a.tags) === String(b.tags) &&\r\n\t\t\t\tString(a.stepPattern) === String(b.stepPattern)\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the step bindings that have been registered for a given binding class.\r\n\t *\r\n\t * @param targetPrototype The class representing the binding (constructor function).\r\n\t *\r\n\t * @returns An array of [[StepBinding]] objects that have been registered for the specified\r\n\t * binding class.\r\n\t */\r\n\tpublic getStepBindingsForTarget(targetPrototype: any): StepBinding[] {\r\n\t\tconst targetBinding = this._classBindings.get(targetPrototype);\r\n\r\n\t\tif (!targetBinding) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\treturn targetBinding.stepBindings;\r\n\t}\r\n\r\n\t/**\r\n\t * Retrieves the step bindings for a given step pattern and collection of tag names.\r\n\t *\r\n\t * @param stepPattern The step pattern to search.\r\n\t * @param tags An array of [[TagName]] to search.\r\n\t *\r\n\t * @returns An array of [[StepBinding]] that map to the given step pattern and set of tag names.\r\n\t */\r\n\tpublic getStepBindings(stepPattern: StepPattern, tags: TagName[]): StepBinding[] {\r\n\t\tconst tagMap = this._stepBindings.get(stepPattern);\r\n\r\n\t\tif (!tagMap) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\tconst matchingStepBindings = this.mapTagNamesToStepBindings(tags, tagMap);\r\n\r\n\t\tif (matchingStepBindings.length > 0) {\r\n\t\t\treturn matchingStepBindings;\r\n\t\t}\r\n\r\n\t\treturn this.mapTagNamesToStepBindings(['*'], tagMap);\r\n\t}\r\n\r\n\tpublic getStepBindingByCucumberKey(cucumberKey: string): StepBinding | undefined {\r\n\t\tlet result: StepBinding | undefined = undefined;\r\n\r\n\t\tfor (const [_, binding] of this._classBindings) {\r\n\t\t\tfor (const stepBinding of binding.stepBindings) {\r\n\t\t\t\tif (stepBinding.cucumberKey === cucumberKey) {\r\n\t\t\t\t\tresult = stepBinding;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (result) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Updates the SupportCodeLibrary from Cucumber with\r\n\t * callsite information from tsflow bindings\r\n\t * @param library\r\n\t * @returns\r\n\t */\r\n\tpublic updateSupportCodeLibrary = (library: SupportCodeLibrary): SupportCodeLibrary => {\r\n\t\tthis._classBindings.forEach(binding => {\r\n\t\t\tbinding.stepBindings.forEach(stepBinding => {\r\n\t\t\t\tlet cucumberDefinition: any | undefined = undefined;\r\n\t\t\t\tswitch (stepBinding.bindingType) {\r\n\t\t\t\t\tcase StepBindingFlags.beforeAll:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestRunHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.before:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestCaseHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.beforeStep:\r\n\t\t\t\t\t\tcucumberDefinition = library.beforeTestStepHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.given:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.when:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.then:\r\n\t\t\t\t\t\tcucumberDefinition = library.stepDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.afterStep:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestStepHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.after:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestCaseHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase StepBindingFlags.afterAll:\r\n\t\t\t\t\t\tcucumberDefinition = library.afterTestRunHookDefinitions.find(\r\n\t\t\t\t\t\t\ts => (s.options as any).cucumberKey === stepBinding.cucumberKey\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (cucumberDefinition) {\r\n\t\t\t\t\tcucumberDefinition.line = stepBinding.callsite.lineNumber;\r\n\t\t\t\t\tcucumberDefinition.uri = stepBinding.callsite.filename;\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t});\r\n\t\treturn library;\r\n\t};\r\n\r\n\t/**\r\n\t * Maps an array of tag names to an array of associated step bindings.\r\n\t *\r\n\t * @param tags An array of [[TagName]].\r\n\t * @param tagMap The map of [[TagName]] -> [[StepBinding]] to use when mapping.\r\n\t *\r\n\t * @returns An array of [[StepBinding]].\r\n\t */\r\n\tprivate mapTagNamesToStepBindings(tags: TagName[], tagMap: Map<TagName, StepBinding[]>): StepBinding[] {\r\n\t\tconst matchingStepBindings: (StepBinding | undefined)[] = _.flatten(_.map(tags, tag => tagMap.get(tag)));\r\n\r\n\t\treturn _.reject(matchingStepBindings, stepBinding => stepBinding === undefined) as StepBinding[];\r\n\t}\r\n}\r\n"]}
@@ -81,25 +81,50 @@ function checkTag(tag) {
81
81
  return tag;
82
82
  }
83
83
  function createDecoratorFactory(flag, callSite, tag, timeout) {
84
- return function hookDecorator(target, context) {
85
- const stepBinding = {
86
- stepPattern: '',
87
- bindingType: flag,
88
- classPrototype: undefined,
89
- classPropertyKey: context.name,
90
- stepFunction: target,
91
- stepIsStatic: context.static,
92
- stepArgsLength: target.length,
93
- tags: tag,
94
- timeout: timeout,
95
- callsite: callSite,
96
- cucumberKey: (0, short_uuid_1.default)().new()
84
+ if (global.experimentalDecorators) {
85
+ return (target, propertyKey, descriptor) => {
86
+ const stepFunction = descriptor?.value || target[propertyKey];
87
+ const stepBinding = {
88
+ stepPattern: '',
89
+ bindingType: flag,
90
+ classPrototype: target,
91
+ classPropertyKey: propertyKey,
92
+ stepFunction,
93
+ stepIsStatic: false,
94
+ stepArgsLength: stepFunction ? stepFunction.length : 0, // Safe access
95
+ tags: tag,
96
+ timeout: timeout,
97
+ callsite: callSite,
98
+ cucumberKey: (0, short_uuid_1.default)().new()
99
+ };
100
+ if (tag) {
101
+ stepBinding.tags = checkTag(tag);
102
+ }
103
+ (0, binding_context_1.addStepBindingExp)(stepBinding);
104
+ return descriptor;
97
105
  };
98
- if (tag) {
99
- stepBinding.tags = checkTag(tag);
100
- }
101
- (0, binding_context_1.addStepBinding)(context, stepBinding);
102
- return;
103
- };
106
+ }
107
+ else {
108
+ return function hookDecorator(target, context) {
109
+ const stepBinding = {
110
+ stepPattern: '',
111
+ bindingType: flag,
112
+ classPrototype: undefined,
113
+ classPropertyKey: context.name,
114
+ stepFunction: target,
115
+ stepIsStatic: context.static,
116
+ stepArgsLength: target.length,
117
+ tags: tag,
118
+ timeout: timeout,
119
+ callsite: callSite,
120
+ cucumberKey: (0, short_uuid_1.default)().new()
121
+ };
122
+ if (tag) {
123
+ stepBinding.tags = checkTag(tag);
124
+ }
125
+ (0, binding_context_1.collectStepBinding)(stepBinding);
126
+ return;
127
+ };
128
+ }
104
129
  }
105
130
  //# sourceMappingURL=hook-decorators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook-decorators.js","sourceRoot":"","sources":["../../src/bindings/hook-decorators.ts"],"names":[],"mappings":";;;;;AAWA,8BAGC;AAQD,wBAGC;AAQD,gCAGC;AAQD,4BAGC;AAQD,sBAGC;AAQD,8BAGC;AArED,wDAAiD;AACjD,iDAA+D;AAC/D,4DAAmC;AACnC,uDAAmD;AAEnD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAAgB;IACzC,MAAM,QAAQ,GAAG,uBAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,sBAAsB,CAAC,+BAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACzF,CAAC;AACD;;;;;;GAMG;AACH,SAAgB,MAAM,CAAC,IAAa,EAAE,OAAgB;IACrD,MAAM,QAAQ,GAAG,uBAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,sBAAsB,CAAC,+BAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACjF,CAAC;AACD;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAa,EAAE,OAAgB;IACzD,MAAM,QAAQ,GAAG,uBAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,sBAAsB,CAAC,+BAAgB,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACrF,CAAC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,OAAgB;IACxC,MAAM,QAAQ,GAAG,uB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AG,CAAC,CAAC;QAClC,CAAC;QACD,IAAA,gCAAc,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAErC,OAAO;IACR,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { Callsite } from '../utils/our-callsite';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport shortUuid from 'short-uuid';\r\nimport { addStepBinding } from './binding-context';\r\n\r\n/**\r\n * A method decorator that marks the associated function as a 'Before All Scenario' step. The function is\r\n * executed before all scenarios are executed.\r\n *\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function beforeAll(timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.beforeAll, callSite, undefined, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'Before Scenario' step. The function is\r\n * executed before each scenario.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function before(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.before, callSite, tags, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'Before Step' step. The function is\r\n * executed before each step.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function beforeStep(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.beforeStep, callSite, tags, timeout);\r\n}\r\n\r\n/**\r\n * A method decorator that marks the associated function as an 'After All Scenario' step. The function is\r\n * executed after all scenarios are executed.\r\n *\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function afterAll(timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.afterAll, callSite, undefined, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as an 'After Scenario' step. The function is\r\n * executed after each scenario.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function after(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.after, callSite, tags, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'After Step' step. The function is\r\n * executed after each step.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function afterStep(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.afterStep, callSite, tags, timeout);\r\n}\r\n\r\nfunction checkTag(tag: string): string {\r\n\treturn tag;\r\n}\r\n\r\nfunction createDecoratorFactory(flag: StepBindingFlags, callSite: Callsite, tag?: string, timeout?: number) {\r\n\treturn function hookDecorator(target: Function, context: ClassMethodDecoratorContext) {\r\n\t\tconst stepBinding: StepBinding = {\r\n\t\t\tstepPattern: '',\r\n\t\t\tbindingType: flag,\r\n\t\t\tclassPrototype: undefined,\r\n\t\t\tclassPropertyKey: context.name,\r\n\t\t\tstepFunction: target,\r\n\t\t\tstepIsStatic: context.static,\r\n\t\t\tstepArgsLength: target.length,\r\n\t\t\ttags: tag,\r\n\t\t\ttimeout: timeout,\r\n\t\t\tcallsite: callSite,\r\n\t\t\tcucumberKey: shortUuid().new()\r\n\t\t};\r\n\r\n\t\tif (tag) {\r\n\t\t\tstepBinding.tags = checkTag(tag);\r\n\t\t}\r\n\t\taddStepBinding(context, stepBinding);\r\n\r\n\t\treturn;\r\n\t};\r\n}\r\n"]}
1
+ {"version":3,"file":"hook-decorators.js","sourceRoot":"","sources":["../../src/bindings/hook-decorators.ts"],"names":[],"mappings":";;;;;AAWA,8BAGC;AAQD,wBAGC;AAQD,gCAGC;AAQD,4BAGC;AAQD,sBAGC;AAQD,8BAGC;AArED,wDAAiD;AACjD,iDAA+D;AAC/D,4DAAmC;AACnC,uDAA0E;AAE1E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AAI;gBAC9B,YAAY,EAAE,MAAM;gBACpB,YAAY,EAAE,OAAO,CAAC,MAAM;gBAC5B,cAAc,EAAE,MAAM,CAAC,MAAM;gBAC7B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,QAAQ;gBAClB,WAAW,EAAE,IAAA,oBAAS,GAAE,CAAC,GAAG,EAAE;aAC9B,CAAC;YAEF,IAAI,GAAG,EAAE,CAAC;gBACT,WAAW,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;YAED,IAAA,oCAAkB,EAAC,WAAW,CAAC,CAAC;YAEhC,OAAO;QACR,CAAC,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["import { Callsite } from '../utils/our-callsite';\r\nimport { StepBinding, StepBindingFlags } from './step-binding';\r\nimport shortUuid from 'short-uuid';\r\nimport { collectStepBinding, addStepBindingExp } from './binding-context';\r\n\r\n/**\r\n * A method decorator that marks the associated function as a 'Before All Scenario' step. The function is\r\n * executed before all scenarios are executed.\r\n *\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function beforeAll(timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.beforeAll, callSite, undefined, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'Before Scenario' step. The function is\r\n * executed before each scenario.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function before(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.before, callSite, tags, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'Before Step' step. The function is\r\n * executed before each step.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function beforeStep(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.beforeStep, callSite, tags, timeout);\r\n}\r\n\r\n/**\r\n * A method decorator that marks the associated function as an 'After All Scenario' step. The function is\r\n * executed after all scenarios are executed.\r\n *\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function afterAll(timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.afterAll, callSite, undefined, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as an 'After Scenario' step. The function is\r\n * executed after each scenario.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function after(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.after, callSite, tags, timeout);\r\n}\r\n/**\r\n * A method decorator that marks the associated function as a 'After Step' step. The function is\r\n * executed after each step.\r\n *\r\n * @param tags Optional tag or tags associated with a scenario.\r\n * @param timeout Optional timeout in milliseconds\r\n */\r\nexport function afterStep(tags?: string, timeout?: number): any {\r\n\tconst callSite = Callsite.capture();\r\n\treturn createDecoratorFactory(StepBindingFlags.afterStep, callSite, tags, timeout);\r\n}\r\n\r\nfunction checkTag(tag: string): string {\r\n\treturn tag;\r\n}\r\n\r\nfunction createDecoratorFactory(flag: StepBindingFlags, callSite: Callsite, tag?: string, timeout?: number) {\r\n\tif (global.experimentalDecorators) {\r\n\t\treturn <T>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => {\r\n\t\t\tconst stepFunction = descriptor?.value || target[propertyKey];\r\n\r\n\t\t\tconst stepBinding: StepBinding = {\r\n\t\t\t\tstepPattern: '',\r\n\t\t\t\tbindingType: flag,\r\n\t\t\t\tclassPrototype: target,\r\n\t\t\t\tclassPropertyKey: propertyKey,\r\n\t\t\t\tstepFunction,\r\n\t\t\t\tstepIsStatic: false,\r\n\t\t\t\tstepArgsLength: stepFunction ? stepFunction.length : 0, // Safe access\r\n\t\t\t\ttags: tag,\r\n\t\t\t\ttimeout: timeout,\r\n\t\t\t\tcallsite: callSite,\r\n\t\t\t\tcucumberKey: shortUuid().new()\r\n\t\t\t};\r\n\r\n\t\t\tif (tag) {\r\n\t\t\t\tstepBinding.tags = checkTag(tag);\r\n\t\t\t}\r\n\t\t\taddStepBindingExp(stepBinding);\r\n\r\n\t\t\treturn descriptor;\r\n\t\t};\r\n\t} else {\r\n\t\treturn function hookDecorator(target: Function, context: ClassMethodDecoratorContext) {\r\n\t\t\tconst stepBinding: StepBinding = {\r\n\t\t\t\tstepPattern: '',\r\n\t\t\t\tbindingType: flag,\r\n\t\t\t\tclassPrototype: undefined,\r\n\t\t\t\tclassPropertyKey: context.name,\r\n\t\t\t\tstepFunction: target,\r\n\t\t\t\tstepIsStatic: context.static,\r\n\t\t\t\tstepArgsLength: target.length,\r\n\t\t\t\ttags: tag,\r\n\t\t\t\ttimeout: timeout,\r\n\t\t\t\tcallsite: callSite,\r\n\t\t\t\tcucumberKey: shortUuid().new()\r\n\t\t\t};\r\n\r\n\t\t\tif (tag) {\r\n\t\t\t\tstepBinding.tags = checkTag(tag);\r\n\t\t\t}\r\n\r\n\t\t\tcollectStepBinding(stepBinding);\r\n\r\n\t\t\treturn;\r\n\t\t};\r\n\t}\r\n}\r\n"]}