@lynxwall/cucumber-tsflow 7.0.0 → 7.1.1

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 (57) hide show
  1. package/README.md +114 -28
  2. package/lib/behave.js +1 -1
  3. package/lib/behave.js.map +1 -1
  4. package/lib/bindings/binding-context.d.ts +1 -1
  5. package/lib/bindings/binding-context.js.map +1 -1
  6. package/lib/bindings/binding-decorator.d.ts +1 -1
  7. package/lib/bindings/binding-decorator.js +1 -1
  8. package/lib/bindings/binding-decorator.js.map +1 -1
  9. package/lib/bindings/binding-registry.d.ts +2 -2
  10. package/lib/bindings/binding-registry.js +1 -1
  11. package/lib/bindings/binding-registry.js.map +1 -1
  12. package/lib/bindings/hook-decorators.js +1 -1
  13. package/lib/bindings/hook-decorators.js.map +1 -1
  14. package/lib/bindings/step-binding.d.ts +60 -0
  15. package/lib/bindings/step-binding.js +6 -0
  16. package/lib/bindings/step-binding.js.map +1 -0
  17. package/lib/bindings/step-decorators.js +1 -1
  18. package/lib/bindings/step-decorators.js.map +1 -1
  19. package/lib/bindings/types.d.ts +72 -0
  20. package/lib/bindings/types.js +58 -0
  21. package/lib/bindings/types.js.map +1 -0
  22. package/lib/formatter/behave-json-formatter.d.ts +49 -0
  23. package/lib/formatter/behave-json-formatter.js +85 -0
  24. package/lib/formatter/behave-json-formatter.js.map +1 -0
  25. package/lib/formatter/junit-bamboo-formatter.d.ts +17 -0
  26. package/lib/formatter/junit-bamboo-formatter.js +175 -0
  27. package/lib/formatter/junit-bamboo-formatter.js.map +1 -0
  28. package/lib/formatter/step-definition-snippit-syntax/tsflow-snippet-syntax.d.ts +9 -0
  29. package/lib/formatter/step-definition-snippit-syntax/tsflow-snippet-syntax.js +85 -0
  30. package/lib/formatter/step-definition-snippit-syntax/tsflow-snippet-syntax.js.map +1 -0
  31. package/lib/index.d.ts +36 -1
  32. package/lib/index.js +96 -2
  33. package/lib/index.js.map +1 -1
  34. package/lib/junitbamboo.js +1 -1
  35. package/lib/junitbamboo.js.map +1 -1
  36. package/lib/runtime/managed-scenario-context.d.ts +3 -3
  37. package/lib/runtime/managed-scenario-context.js +2 -2
  38. package/lib/runtime/managed-scenario-context.js.map +1 -1
  39. package/lib/runtime/message-collector.d.ts +1 -1
  40. package/lib/runtime/message-collector.js.map +1 -1
  41. package/lib/runtime/scenario-context.d.ts +16 -0
  42. package/lib/runtime/scenario-context.js +18 -0
  43. package/lib/runtime/scenario-context.js.map +1 -0
  44. package/lib/runtime/scenario-info.d.ts +16 -0
  45. package/lib/runtime/scenario-info.js +23 -0
  46. package/lib/runtime/scenario-info.js.map +1 -0
  47. package/lib/runtime/test-case-runner.d.ts +2 -2
  48. package/lib/runtime/test-case-runner.js +5 -19
  49. package/lib/runtime/test-case-runner.js.map +1 -1
  50. package/lib/snippet.js +1 -1
  51. package/lib/snippet.js.map +1 -1
  52. package/lib/tsconfig.node.tsbuildinfo +1 -1
  53. package/lib/version.d.ts +1 -1
  54. package/lib/version.js +1 -1
  55. package/lib/version.js.map +1 -1
  56. package/lib/wrapper.mjs +35 -0
  57. package/package.json +5 -8
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # cucumber-tsflow
4
4
 
5
- Provides 'specflow' like bindings for CucumberJS 11.2.0+ in TypeScript 5.8+.
5
+ Provides 'specflow' like bindings for CucumberJS 11.2.0 in TypeScript 5.8+.
6
6
 
7
7
  Supports Vue3 files in cucumber tests.
8
8
 
@@ -10,9 +10,26 @@ Supports Vue3 files in cucumber tests.
10
10
 
11
11
  This is a detached fork of <https://github.com/timjroberts/cucumber-js-tsflow>. It has had the <https://github.com/wudong/cucumber-js-tsflow/tree/before_after_all_hooks> branch merged into it, which adds support for beforeAll and afterAll hooks.
12
12
 
13
- In addition, the following features have been added:
13
+ This fork has been drastically modified from the original and will eventually be moved to a new project. In addition, the SpecFlow project has reached [end of life](https://reqnroll.net/news/2025/01/specflow-end-of-life-has-been-announced/), and this project will be rebranded. Further details will be provided in future updates. However, the new project will support the same functionality as cucumber-tsflow while providing additional tools and extensions.
14
+
15
+ ## Release Updates (7.1.0)
16
+
17
+ With this latest release, cucumber-tsflow has been refactored to support cucumber-js version 11.2.0 along with other updates that include:
18
+
19
+ - **Switch to package exports** with both cucumber-tsflow and most of cucumber-js Public types and functions exported. This allows developers to use cucumber-tsflow as a replacement for cucumber-js without requiring a peer installation. Most of the functionality is still executed in cucumber-js, cucumber-tsflow just extends cucumber-js to switch from support functions to support decorators with scoped context. This change is what allows you to use a SpecFlow type of structure for defining code that will execute BDD tests.
20
+ - **API support** that implements and extends the cucumber-js API.
21
+ - Support for Node 22 and Typescript 5.8.
22
+ - Switched to **official Typescript Decorators** with metadata support implemented in [Typescript 5.2](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#decorator-metadata).
23
+ **NOTE:** Please **remove *experimentalDecorators*** from your TypeScript configuration as it is no longer supported with the update to use official decorators, which are very different.
24
+ - Transpiler configuration updates to support node and Typescript changes.
25
+ - Added a new section to this readme that describes [Transpilers and TypeScript](#transpilers-and-typescript) in more detail.
26
+
27
+ ## Features
28
+
29
+ This fork of cucumber-tsflow provides the following features that extend the original version:
14
30
 
15
31
  - Test runner using the cucumber-tsflow command.
32
+
16
33
  - Uses underlying cucumber api to run tests.
17
34
  - Returns **four** exit codes:
18
35
  - **0** - All scenarios passing.
@@ -38,13 +55,14 @@ In addition, the following features have been added:
38
55
 
39
56
  - A behave-json-formatter that fixes json so it can be used with Behave Pro.
40
57
 
58
+ - A junit-bamboo formatter that generates xml compatible with the Bamboo JUnit plugin.
59
+
41
60
  - tsflow-snippet-syntax used to format snippet examples.
61
+
42
62
  - snippets use the [Cucumber Expressions](https://github.com/cucumber/cucumber-expressions#readme) Syntax for parameters.
43
63
 
44
64
  - [Context Injection](#context-injection) updates with support to initialize the context before each scenario test run and dispose the context after a scenario has finished executing.
45
65
 
46
-
47
-
48
66
  <div style="padding: 15px; border: 1px solid transparent; border-color: transparent; margin-bottom: 20px; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
49
67
  <strong><span style="color: #000">Note:</span></strong> With recent updates you must use the <strong><span style="color: #000">cucumber-tsflow</span></strong> command to execute tests. This command executes the same API calls that cucumber-js does and supports all of the options and features as cucumber-js along with new features listed above.
50
68
  </div>
@@ -135,6 +153,75 @@ Running the cucumber-tsflow command will execute your features along with the su
135
153
 
136
154
  In this quick example test state is encapsulated directly in the class. As your test suite grows larger and step definitions get shared between multiple classes, you can begin using '[Context Injection](#context-injection)' to share state between running step definitions.
137
155
 
156
+ ## Transpilers and TypeScript
157
+
158
+ Cucumber-tsflow provides several [transpilers](#transpiler-and-vue3-supported) that can be used in your configuration. However, you are not required to use them. If a different configuration or transpiler is needed you can copy code from one of the provided transpilers.
159
+
160
+ This section focuses on the Typescript configuration used to transpile your test code, and any dependencies, into JavaScript that is executed within the cucumber-js test runner.
161
+
162
+ ### CommonJS and ESM
163
+
164
+ The transpilers included with cucumber-tsflow transpile to **CommonJS** and do not support projects with `"type": "module"` in your `package.json`. However, [esModuleinterop](https://www.typescriptlang.org/tsconfig/#esModuleInterop) is enabled by default, which allows you to write code using ECMAScript (ESM) standards and import ESM modules in your test code.
165
+
166
+ ### TypeScript Configuration
167
+
168
+ All of the transpilers included with cucumber-tsflow use the same TypeScript configuration, which take precedence when running your tests using one of these transpilers. In other words, while each transpiler is different, they all use the same tsconfig settings, which are shown below:
169
+
170
+ ```typescript
171
+ compilerOptions: {
172
+ module: 'nodeNext',
173
+ target: 'es2022',
174
+ strict: true,
175
+ resolveJsonModule: true,
176
+ esModuleInterop: true,
177
+ skipLibCheck: true,
178
+ lib: ['es2022', 'esnext.decorators']
179
+ },
180
+ ```
181
+
182
+ When test runs are started, the settings from your local tsconfig.json are loaded first and then the settings from the transpiler will override the specific settings shown above. As a result, you should use these transpilers in projects that will support these settings.
183
+
184
+ For example, the settings from the cucumber-tsflow vue test project is shown below:
185
+
186
+ ```json
187
+ "compilerOptions": {
188
+ "baseUrl": ".",
189
+ "target": "es2022",
190
+ "module": "Node18",
191
+ "strict": true,
192
+ "importHelpers": true,
193
+ "skipLibCheck": true,
194
+ "esModuleInterop": true,
195
+ "forceConsistentCasingInFileNames": true,
196
+ "useDefineForClassFields": true,
197
+ "inlineSourceMap": true,
198
+ "allowJs": true,
199
+ "removeComments": false,
200
+ "lib": ["es2022", "esnext.decorators"],
201
+ "typeRoots": ["../../node_modules/@types"]
202
+ },
203
+ ```
204
+
205
+ These settings are similar to the default transpiler settings, which will not cause an issue. The only change will be the module from Node18 to nodeNext. Any other settings that are not included in the transpiler default will also be applied when the transpiler is executed.
206
+
207
+ ### esbuild Transpilers
208
+
209
+ Cucumber-tsflow provides two esbuild transpilers: one with esbuild and support for Vue using the vue-sfc transpiler, and another that only uses the esbuild transpiler. Both cucumber-tsflow transpilers use the same esbuild transpiler, which is configured to generate CommonJS, as shown below:
210
+
211
+ ```typescript
212
+ const commonOptions: CommonOptions = {
213
+ format: 'cjs',
214
+ logLevel: 'info',
215
+ target: [`es2020`],
216
+ minify: false,
217
+ sourcemap: 'external'
218
+ };
219
+ ```
220
+
221
+ As you can see, this also uses the same target as the typescript configuration. In addition, minify is set to false, which makes it easy to debug and step into code when running tests.
222
+
223
+ As mentioned at the beginning of this section, there are several transpilers provided, which can be used with your test project. The [transpilers](#transpiler-and-vue3-supported) section below provides information on how to configure your project to use one of these transpilers.
224
+
138
225
  ## Cucumber-tsflow Test Runner
139
226
 
140
227
  As mentioned previously, with recent updates cucumber-tsflow must be used to execute tests. The reason for this update was to replace before and after hooks previously used to manage context with a message handler. Executing tests with cucumber-tsflow uses the same API calls that cucumber-js does. The only differences are updates to support new configuration parameters along with updates to step definitions that set the correct location.
@@ -226,19 +313,19 @@ echo $?
226
313
 
227
314
  ## New Configuration options
228
315
 
229
- As mentioned, when using cucumber-tsflow to execute tests all of the configuration options documented here are supported: <https://github.com/cucumber/cucumber-js/blob/v8.0.0/docs/configuration.md>
316
+ As mentioned, when using cucumber-tsflow to execute tests all of the configuration options documented here are supported: <https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/configuration.md>
230
317
 
231
318
  In addition to cucumber configuration options the following two options have been added:
232
319
 
233
- | Name | Type | Repeatable | CLI Option | Description | Default |
234
- | ---------------- | --------- | ---------- | -------------------- | ------------------------------------------------------------ | ------- |
320
+ | Name | Type | Repeatable | CLI Option | Description | Default |
321
+ | ---------------- | --------- | ---------- | -------------------- | ------------------------------------------------------------- | ------- |
235
322
  | `transpiler` | `string` | No | `--transpiler` | Name of the transpiler to use: esnode, esvue, tsnode or tsvue | esnode |
236
- | `debugFile` | `string` | No | `--debug-file` | Path to a file with steps for debugging | |
237
- | `enableVueStyle` | `boolean` | No | `--enable-vue-style` | Enable Vue `<style>` block when compiling Vue SFC. | false |
323
+ | `debugFile` | `string` | No | `--debug-file` | Path to a file with steps for debugging | |
324
+ | `enableVueStyle` | `boolean` | No | `--enable-vue-style` | Enable Vue `<style>` block when compiling Vue SFC. | false |
238
325
 
239
326
  ### Transpiler and Vue3 supported
240
327
 
241
- Using TypeScript with CucumberJs requires a couple of tsconfig.json parameters as described here: [Transpiling](https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/transpiling.md). In addition, there is no support for transpiling Vue files with CucumberJS.
328
+ Using TypeScript with cucumber-js requires setting tsconfig.json parameters as described here: [cucumber-js Transpiling](https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/transpiling.md). In addition, there is no support for transpiling Vue files with cucumber-js.
242
329
 
243
330
  As a result, cucumber-tsflow adds several configurations for transpiling TypeScript code using the recommended configuration. In addition, support has been added to transform .vue files during test execution allowing you to test Vue SFC components using cucumber.
244
331
 
@@ -254,7 +341,7 @@ The following transpilers are provided:
254
341
  - **jsdom** is also loaded globally to support loading and testing Vue SFC components.
255
342
 
256
343
  <div style="padding: 15px; border: 1px solid transparent; border-color: transparent; margin-bottom: 20px; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
257
- <strong><span style="color: #000">Note:</span></strong> The transpilers provide with cucumber-tsflow will only support CommonJS modules. In other words, if your package.json file has 'type: module' you will not be able to use these transpilers. However, you can use ts-node for transpiling as documented here: <a ref='https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/transpiling.md#esm'>Transpiling</a>
344
+ <strong><span style="color: #000">Note:</span></strong> The transpilers provide with cucumber-tsflow will only support CommonJS modules. In other words, if your package.json file has 'type: module' you will not be able to use these transpilers. However, you can use ts-node for transpiling as documented here: <a ref='https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/transpiling.md#esm'>Transpiling</a>
258
345
  </div>
259
346
 
260
347
  ##### Using the transpiler configuration option
@@ -426,7 +513,7 @@ public givenAValueBasedSearch(searchValue: string): void {
426
513
  }
427
514
  ```
428
515
 
429
- **Note**: Tags added to steps work the same as "Tagged Hooks" documented here: <https://github.com/cucumber/cucumber-js/blob/v8.0.0/docs/support_files/hooks.md>
516
+ **Note**: Tags added to steps work the same as "Tagged Hooks" documented here: <https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/support_files/hooks.md>
430
517
 
431
518
  ## Hooks
432
519
 
@@ -527,7 +614,7 @@ If it doesn't already exist, create a file named cucumber.json at the root of yo
527
614
 
528
615
  #### Using the behave json formatter
529
616
 
530
- The following example shows how to configure the behave formatter in cucumber.json. The tsflow-snippet-syntax module is configured as the default snippet syntax and does not require configuration. However, you can override the snippet syntax as documented here: <https://github.com/cucumber/cucumber-js/blob/v8.0.0/docs/custom_snippet_syntaxes.md>
617
+ The following example shows how to configure the behave formatter in cucumber.json. The tsflow-snippet-syntax module is configured as the default snippet syntax and does not require configuration. However, you can override the snippet syntax as documented here: <https://github.com/cucumber/cucumber-js/blob/v11.2.0/docs/custom_snippet_syntaxes.md>
531
618
 
532
619
  ```typescript
533
620
  {
@@ -559,32 +646,32 @@ Like 'specflow', cucumber-tsflow supports a simple dependency injection framewor
559
646
 
560
647
  ### Sharing Data between Steps and Bindings
561
648
 
562
- Each scenario in a feature will get a new instance of the *Context* object when the steps associated with a scenario are executed. Hooks and steps used by the scenario will have access to the same instance of a "Scenario Context" during execution of the test steps. In addition, if steps of a scenario are implemented in separate bindings, those steps will still have access to the same instance of the *Context* object created for the scenario.
649
+ Each scenario in a feature will get a new instance of the _Context_ object when the steps associated with a scenario are executed. Hooks and steps used by the scenario will have access to the same instance of a "Scenario Context" during execution of the test steps. In addition, if steps of a scenario are implemented in separate bindings, those steps will still have access to the same instance of the _Context_ object created for the scenario.
563
650
 
564
651
  **Recent Updates:**
565
652
 
566
653
  - versions >= 6.5.2
654
+
567
655
  - Updated execution of the `initialize()` function to pass in argument that is an object with information about the Test Case (Scenario).
568
656
  - The object passed in will be in the form:
569
657
  `{ pickle, gherkinDocument, testCaseStartedId } : StartTestCaseInfo`
570
658
  - Updated execution of the `dispose()` function to pass in argument that is an object with information about the Test Case (Scenario).
571
659
  - The object passed in will be in the form:
572
660
  `{ pickle, gherkinDocument, result, willBeRetried, testCaseStartedId } : EndTestCaseInfo`
573
-
661
+
574
662
  - versions >= 6.5.0
575
663
  - Context classes now support an `initialize()` function that can be defined synchronous or asynchronous. The `initialize()` function is called after the `BeforeAll` hook and before any other hooks or steps. This provides the ability to initialize a scenario context before any tests are executed with support for async operations.
576
664
  - Context classes have always supported a `dispose()` function for cleanup. However, with latest updates the `dispose()` function can be defined synchronously or asynchronously.
577
665
  - versions >= 6.4.0
578
666
  - The current Cucumber World object is now available as a constructor parameter on all classes defined for Context Injection. For more information on the World object see: [Access to Cucumber.js World object](#access-to-cucumber.js-world-object).
579
667
 
580
-
581
668
  ### Using Context Injection
582
669
 
583
670
  With Context Injection you first need to define one or more classes that will be injected into a binding instance. Next, you'll need to add the context types to the `@binding` decorator and implement a constructor that passes initialized instances of the context type into the binding instance.
584
671
 
585
672
  **Defining a Context class:**
586
673
 
587
- - Create a simple *Context* class representing the shared data. The class can have no constructor or a default empty constructor. However, to access the Cucumber World object you should define a constructor as shown in the example below.
674
+ - Create a simple _Context_ class representing the shared data. The class can have no constructor or a default empty constructor. However, to access the Cucumber World object you should define a constructor as shown in the example below.
588
675
 
589
676
  **Synchronous example:**
590
677
 
@@ -603,7 +690,7 @@ export class ScenarioContext {
603
690
  public initialize({ pickle, gherkinDocument }: StartTestCaseInfo): void {
604
691
  this.id = this.makeid(5);
605
692
  console.log(`Sync init: ${this.id}`);
606
- console.log(`Start Test Case: ${this.getFeatureAndScenario(gherkinDocument.uri!, pickle.name)}`);
693
+ console.log(`Start Test Case: ${this.getFeatureAndScenario(gherkinDocument.uri!, pickle.name)}`);
607
694
  }
608
695
  public dispose({ pickle, gherkinDocument }: EndTestCaseInfo): void {
609
696
  console.log(`Sync dispose: ${this.id}`);
@@ -657,11 +744,9 @@ export class ScenarioContext {
657
744
  }
658
745
  ```
659
746
 
660
-
661
-
662
747
  **Initialize Binding in Step class:**
663
748
 
664
- - Update the `@binding()` decorator to indicate the types of context objects that are required by the 'binding' class. You can include up to nine separate *Context* objects.
749
+ - Update the `@binding()` decorator to indicate the types of context objects that are required by the 'binding' class. You can include up to nine separate _Context_ objects.
665
750
  - Define a constructor on the `@binding` class with steps that need access to the shared data that accepts one or more context objects as parameters based on initialization of the `@binding` decorator.
666
751
 
667
752
  **Single Context class example:**
@@ -698,7 +783,10 @@ import { expect } from 'chai';
698
783
 
699
784
  @binding([ScenarioContext, SyncContext])
700
785
  export default class InjectionTestSteps1 {
701
- constructor(private context: ScenarioContext, private syncContext: SyncContext) {}
786
+ constructor(
787
+ private context: ScenarioContext,
788
+ private syncContext: SyncContext
789
+ ) {}
702
790
 
703
791
  @given('The Workspace is available and valid')
704
792
  theWorkspaceIsAvailableAndValid() {
@@ -716,8 +804,6 @@ export default class InjectionTestSteps1 {
716
804
  }
717
805
  ```
718
806
 
719
-
720
-
721
807
  ### Access to Cucumber.js World object
722
808
 
723
809
  The context object that you inject can also be configured to access the [World](https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md) object from Cucumber.js, which provides the following:
@@ -726,7 +812,7 @@ The context object that you inject can also be configured to access the [World](
726
812
  - `log`: a method for [logging](https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/attachments.md#logging) information from hooks/steps
727
813
  - `parameters`: an object of parameters passed in via configuration
728
814
 
729
- Starting with version **6.4.0** the Cucumber World object is now passed into a *Context* class as a constructor parameter as shown below:
815
+ Starting with version **6.4.0** the Cucumber World object is now passed into a _Context_ class as a constructor parameter as shown below:
730
816
 
731
817
  ```typescript
732
818
  import { World } from '@cucumber/cucumber';
@@ -749,15 +835,15 @@ In the example shown above, the world object instance passed in to the construct
749
835
 
750
836
  **NOTE:** `BeforeAll` and `AfterAll` hooks do not have access to the scenario context.
751
837
 
752
- *Context* classes, as demonstrated by the `ScenarioContext` example above, also support a `dispose()` function that is called when the execution of a test scenario is complete.
838
+ _Context_ classes, as demonstrated by the `ScenarioContext` example above, also support a `dispose()` function that is called when the execution of a test scenario is complete.
753
839
 
754
840
  With instance initialization, and dispose functionality, you have the ability to initialize common support operations and data needed for scenario test runs, and cleanup any resources when scenario test runs are complete.
755
841
 
756
842
  ### Access to the World object without using a constructor
757
843
 
758
- **NOTE:** This approach of accessing the Cucumber World object is still supported. However, the ability to access the world object during *Context* initialization provides much better control over when context data is initialized versus relying on execution of a hook. As a result, using a `@before` hook as shown below is not recommended.
844
+ **NOTE:** This approach of accessing the Cucumber World object is still supported. However, the ability to access the world object during _Context_ initialization provides much better control over when context data is initialized versus relying on execution of a hook. As a result, using a `@before` hook as shown below is not recommended.
759
845
 
760
- With this approach, you would define a world property on simple *Context* class that you're injecting:
846
+ With this approach, you would define a world property on simple _Context_ class that you're injecting:
761
847
 
762
848
  ```typescript
763
849
  import { World } from '@cucumber/cucumber';
package/lib/behave.js CHANGED
@@ -33,6 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- const behave = __importStar(require("./formatters/behave-json-formatter"));
36
+ const behave = __importStar(require("./formatter/behave-json-formatter"));
37
37
  module.exports = behave;
38
38
  //# sourceMappingURL=behave.js.map
package/lib/behave.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"behave.js","sourceRoot":"","sources":["../src/behave.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAA6D;AAE7D,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC","sourcesContent":["import * as behave from './formatters/behave-json-formatter';\r\n\r\nmodule.exports = behave;\r\n"]}
1
+ {"version":3,"file":"behave.js","sourceRoot":"","sources":["../src/behave.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA4D;AAE5D,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC","sourcesContent":["import * as behave from './formatter/behave-json-formatter';\r\n\r\nmodule.exports = behave;\r\n"]}
@@ -1,4 +1,4 @@
1
- import { StepBinding } from '../types/step-binding';
1
+ import { StepBinding } from './step-binding';
2
2
  /**
3
3
  * Add a StepBinding to the DecoratorContext metadata
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"binding-context.js","sourceRoot":"","sources":["../../src/bindings/binding-context.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAAC,OAAyB,EAAE,OAAoB,EAAQ,EAAE;IACvF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY;QAAE,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,KAAK,EAAe,CAAC;IAC5F,OAAO,CAAC,QAAQ,CAAC,YAAmC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACrE,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,CAAC,OAAyB,EAAE,QAAiB,IAAI,EAAiB,EAAE;IAClG,IAAI,QAAQ,GAAkB,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAkC,CAAC;IACzE,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,QAAQ,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,KAAK,EAAe,CAAC;QAC1D,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["import { StepBinding } from '../types/step-binding';\r\n\r\n/**\r\n * Add a StepBinding to the DecoratorContext metadata\r\n *\r\n * @param context Current DecoratorContext\r\n * @param binding StepBinding to add\r\n */\r\nexport const addStepBinding = (context: DecoratorContext, binding: StepBinding): void => {\r\n\tif (!context.metadata.stepBindings) context.metadata.stepBindings = new Array<StepBinding>();\r\n\t(context.metadata.stepBindings as Array<StepBinding>).push(binding);\r\n};\r\n\r\n/**\r\n * Get all step bindings in DecoratorContext metadata and then reset\r\n * stepBindings in the metadata to an empty array if reset = true (default)\r\n *\r\n * @param context Current DecoratorContext\r\n * @param reset Reset metadata on the context. Default=true\r\n * @returns Array of StepBindings\r\n */\r\nexport const getStepBindings = (context: DecoratorContext, reset: boolean = true): StepBinding[] => {\r\n\tlet bindings: StepBinding[] = [];\r\n\tconst stepBindings = context.metadata.stepBindings as Array<StepBinding>;\r\n\tif (stepBindings && stepBindings.length > 0) {\r\n\t\tbindings = [...stepBindings];\r\n\t\tif (reset) {\r\n\t\t\tcontext.metadata.stepBindings = new Array<StepBinding>();\r\n\t\t}\r\n\t}\r\n\treturn bindings;\r\n};\r\n"]}
1
+ {"version":3,"file":"binding-context.js","sourceRoot":"","sources":["../../src/bindings/binding-context.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAAC,OAAyB,EAAE,OAAoB,EAAQ,EAAE;IACvF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY;QAAE,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,KAAK,EAAe,CAAC;IAC5F,OAAO,CAAC,QAAQ,CAAC,YAAmC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACrE,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,CAAC,OAAyB,EAAE,QAAiB,IAAI,EAAiB,EAAE;IAClG,IAAI,QAAQ,GAAkB,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAkC,CAAC;IACzE,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,QAAQ,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,KAAK,EAAe,CAAC;QAC1D,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["import { StepBinding } from './step-binding';\r\n\r\n/**\r\n * Add a StepBinding to the DecoratorContext metadata\r\n *\r\n * @param context Current DecoratorContext\r\n * @param binding StepBinding to add\r\n */\r\nexport const addStepBinding = (context: DecoratorContext, binding: StepBinding): void => {\r\n\tif (!context.metadata.stepBindings) context.metadata.stepBindings = new Array<StepBinding>();\r\n\t(context.metadata.stepBindings as Array<StepBinding>).push(binding);\r\n};\r\n\r\n/**\r\n * Get all step bindings in DecoratorContext metadata and then reset\r\n * stepBindings in the metadata to an empty array if reset = true (default)\r\n *\r\n * @param context Current DecoratorContext\r\n * @param reset Reset metadata on the context. Default=true\r\n * @returns Array of StepBindings\r\n */\r\nexport const getStepBindings = (context: DecoratorContext, reset: boolean = true): StepBinding[] => {\r\n\tlet bindings: StepBinding[] = [];\r\n\tconst stepBindings = context.metadata.stepBindings as Array<StepBinding>;\r\n\tif (stepBindings && stepBindings.length > 0) {\r\n\t\tbindings = [...stepBindings];\r\n\t\tif (reset) {\r\n\t\t\tcontext.metadata.stepBindings = new Array<StepBinding>();\r\n\t\t}\r\n\t}\r\n\treturn bindings;\r\n};\r\n"]}
@@ -1,4 +1,4 @@
1
- import { ContextType } from '../types/types';
1
+ import { ContextType } from './types';
2
2
  /**
3
3
  * A class decorator that marks the associated class as a CucumberJS binding.
4
4
  *
@@ -8,7 +8,7 @@ const cucumber_1 = require("@cucumber/cucumber");
8
8
  const binding_context_1 = require("./binding-context");
9
9
  const index_1 = __importDefault(require("@cucumber/cucumber/lib/support_code_library_builder/index"));
10
10
  const binding_registry_1 = require("./binding-registry");
11
- const step_binding_1 = require("../types/step-binding");
11
+ const step_binding_1 = require("./step-binding");
12
12
  const cucumber_2 = require("@cucumber/cucumber");
13
13
  const underscore_1 = __importDefault(require("underscore"));
14
14
  /**
@@ -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,wDAAsE;AAEtE,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,CAAC,4BAA4B,CAAC,MAAM,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QACrF,MAAM,GAAG,GAAG,eAAyB,CAAC;QACtC,gBAAgB,EAAE,CAAC;QAEnB,qGAAqG;QACrG,gEAAgE;QAChE,4FAA4F;QAC5F,MAAM,WAAW,GAA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I,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 '../types/step-binding';\r\nimport { ContextType, StepPattern } from '../types/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":";;;;;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,CAAC,4BAA4B,CAAC,MAAM,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QACrF,MAAM,GAAG,GAAG,eAAyB,CAAC;QACtC,gBAAgB,EAAE,CAAC;QAEnB,qGAAqG;QACrG,gEAAgE;QAChE,4FAA4F;QAC5F,MAAM,WAAW,GAAkB,IAAA,iCAAe,EAAC,OAAO,CAAC,CAAC;QAC5D,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACjC,2EAA2E;YAC3E,WAAW,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC;YAC9C,eAAe,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAEjD,IAAI,WAAW,CAAC,WAAW,GAAG,+BAAgB,CAAC,eAAe,EAAE,CAAC;gBAChE,IAAI,gBAAgB,GAAG,wBAA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nG,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,6 +1,6 @@
1
1
  import { SupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types';
2
- import { StepBinding } from '../types/step-binding';
3
- import { ContextType, StepPattern, TagName } from '../types/types';
2
+ import { StepBinding } from './step-binding';
3
+ import { ContextType, StepPattern, TagName } from './types';
4
4
  /**
5
5
  * Represents the default step pattern.
6
6
  */
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BindingRegistry = exports.DEFAULT_TAG = exports.DEFAULT_STEP_PATTERN = void 0;
7
7
  const underscore_1 = __importDefault(require("underscore"));
8
- const step_binding_1 = require("../types/step-binding");
8
+ const step_binding_1 = require("./step-binding");
9
9
  const logger_1 = __importDefault(require("../utils/logger"));
10
10
  /**
11
11
  * Represents the default step pattern.
@@ -1 +1 @@
1
- {"version":3,"file":"binding-registry.js","sourceRoot":"","sources":["../../src/bindings/binding-registry.ts"],"names":[],"mappings":";;;;;;AACA,4DAA2B;AAC3B,wDAAsE;AAEtE,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;QACzB,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;QAEtE,MAAM,QAAQ,GAAI,MAAc,CAAC,yBAAyB,CAAC,CAAC;QAE5D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAc,CAAC,yBAAyB,CAAC,GAAG,IAAI,eAAe,EAAE,CAAC;QACpE,CAAC;QAED,OAAO,QAAQ,IAAK,MAAc,CAAC,yBAAyB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;OAOG;IACI,4BAA4B,CAAC,cAAmB,EAAE,YAA4B;QAC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AAO,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 '../types/step-binding';\r\nimport { ContextType, StepPattern, TagName } from '../types/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;QACzB,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;QAEtE,MAAM,QAAQ,GAAI,MAAc,CAAC,yBAAyB,CAAC,CAAC;QAE5D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAc,CAAC,yBAAyB,CAAC,GAAG,IAAI,eAAe,EAAE,CAAC;QACpE,CAAC;QAED,OAAO,QAAQ,IAAK,MAAc,CAAC,yBAAyB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;OAOG;IACI,4BAA4B,CAAC,cAAmB,EAAE,YAA4B;QACpF,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QAED,IAAI,iBAAiB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAEhE,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACxB,iBAAiB,GAAG;gBACnB,YAAY,EAAE,EAAE;gBAChB,YAAY,EAAE,EAAE;aAChB,CAAC;YAEF,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,iBAAiB,CAAC,C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AC,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"]}
@@ -10,7 +10,7 @@ exports.afterAll = afterAll;
10
10
  exports.after = after;
11
11
  exports.afterStep = afterStep;
12
12
  const our_callsite_1 = require("../utils/our-callsite");
13
- const step_binding_1 = require("../types/step-binding");
13
+ const step_binding_1 = require("./step-binding");
14
14
  const short_uuid_1 = __importDefault(require("short-uuid"));
15
15
  const binding_context_1 = require("./binding-context");
16
16
  /**
@@ -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,wDAAsE;AACtE,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,uBAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,sBAAsB,CAAC,+BAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC;AACD;;;;;;GAMG;AACH,SAAgB,KAAK,CAAC,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from '../types/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,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,EAA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BAAsB,CAAC,IAAsB,EAAE,QAAkB,EAAE,GAAY,EAAE,OAAgB;IACzG,OAAO,SAAS,aAAa,CAAC,MAAgB,EAAE,OAAoC;QACnF,MAAM,WAAW,GAAgB;YAChC,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,IAAI;YACjB,cAAc,EAAE,SAAS;YACzB,gBAAgB,EAAE,OAAO,CAAC,IAAI;YAC9B,YAAY,EAAE,MAAM;YACpB,YAAY,EAAE,OAAO,CAAC,MAAM;YAC5B,cAAc,EAAE,MAAM,CAAC,MAAM;YAC7B,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,IAAA,oBAAS,GAAE,CAAC,GAAG,EAAE;SAC9B,CAAC;QAEF,IAAI,GAAG,EAAE,CAAC;YACT,WAAW,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,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"]}