@lynxwall/cucumber-tsflow 6.5.6 → 7.0.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.
- package/README.md +22 -12
- package/api/index.d.ts +6 -0
- package/bin/cucumber-tsflow +3 -3
- package/bin/cucumber-tsflow.js +3 -0
- package/lib/api/index.d.ts +17 -0
- package/lib/api/index.js +30 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/load-configuration.d.ts +21 -0
- package/lib/api/load-configuration.js +127 -0
- package/lib/api/load-configuration.js.map +1 -0
- package/lib/api/load-support.d.ts +10 -0
- package/lib/api/load-support.js +48 -0
- package/lib/api/load-support.js.map +1 -0
- package/lib/api/run-cucumber.d.ts +16 -0
- package/lib/api/run-cucumber.js +151 -0
- package/lib/api/run-cucumber.js.map +1 -0
- package/lib/api/wrapper.mjs +6 -0
- package/lib/behave.js +18 -8
- package/lib/behave.js.map +1 -0
- package/lib/bindings/binding-context.d.ts +17 -0
- package/lib/bindings/binding-context.js +36 -0
- package/lib/bindings/binding-context.js.map +1 -0
- package/lib/{cucumber → bindings}/binding-decorator.d.ts +2 -2
- package/lib/bindings/binding-decorator.js +201 -0
- package/lib/bindings/binding-decorator.js.map +1 -0
- package/lib/{cucumber → bindings}/binding-registry.d.ts +8 -8
- package/lib/bindings/binding-registry.js +232 -0
- package/lib/bindings/binding-registry.js.map +1 -0
- package/lib/{cucumber → bindings}/hook-decorators.d.ts +6 -6
- package/lib/{cucumber → bindings}/hook-decorators.js +17 -15
- package/lib/bindings/hook-decorators.js.map +1 -0
- package/lib/{cucumber/step-definition-decorators.d.ts → bindings/step-decorators.d.ts} +3 -3
- package/lib/bindings/step-decorators.js +97 -0
- package/lib/bindings/step-decorators.js.map +1 -0
- package/lib/cli/argv-parser.js +3 -3
- package/lib/cli/argv-parser.js.map +1 -0
- package/lib/cli/index.d.ts +1 -2
- package/lib/cli/index.js +12 -40
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/load-configuration.d.ts +2 -1
- package/lib/cli/load-configuration.js +12 -10
- package/lib/cli/load-configuration.js.map +1 -0
- package/lib/cli/run.js +5 -7
- package/lib/cli/run.js.map +1 -0
- package/lib/cucumber/coordinator.d.ts +15 -0
- package/lib/cucumber/coordinator.js +40 -0
- package/lib/cucumber/coordinator.js.map +1 -0
- package/lib/cucumber/make-runtime.d.ts +12 -16
- package/lib/cucumber/make-runtime.js +10 -33
- package/lib/cucumber/make-runtime.js.map +1 -0
- package/lib/cucumber/managed-scenario-context.d.ts +3 -3
- package/lib/cucumber/managed-scenario-context.js +24 -24
- package/lib/cucumber/managed-scenario-context.js.map +1 -0
- package/lib/cucumber/message-collector.d.ts +3 -0
- package/lib/cucumber/message-collector.js +38 -16
- package/lib/cucumber/message-collector.js.map +1 -0
- package/lib/cucumber/parallel/adapter.d.ts +46 -0
- package/lib/cucumber/parallel/adapter.js +156 -0
- package/lib/cucumber/parallel/adapter.js.map +1 -0
- package/lib/cucumber/parallel/run-worker.d.ts +1 -1
- package/lib/cucumber/parallel/run-worker.js +8 -16
- package/lib/cucumber/parallel/run-worker.js.map +1 -0
- package/lib/cucumber/parallel/worker.d.ts +10 -14
- package/lib/cucumber/parallel/worker.js +59 -68
- package/lib/cucumber/parallel/worker.js.map +1 -0
- package/lib/cucumber/run-cucumber.d.ts +5 -3
- package/lib/cucumber/run-cucumber.js +59 -38
- package/lib/cucumber/run-cucumber.js.map +1 -0
- package/lib/cucumber/serial/adapter.d.ts +12 -0
- package/lib/cucumber/serial/adapter.js +24 -0
- package/lib/cucumber/serial/adapter.js.map +1 -0
- package/lib/cucumber/test-case-info.js +1 -1
- package/lib/cucumber/test-case-info.js.map +1 -0
- package/lib/cucumber/test-case-runner.d.ts +2 -2
- package/lib/cucumber/test-case-runner.js +47 -19
- package/lib/cucumber/test-case-runner.js.map +1 -0
- package/lib/cucumber/utils.js +1 -1
- package/lib/cucumber/utils.js.map +1 -0
- package/lib/cucumber/worker.d.ts +17 -0
- package/lib/cucumber/worker.js +57 -0
- package/lib/cucumber/worker.js.map +1 -0
- package/lib/esnode.d.ts +1 -0
- package/lib/esnode.js +5 -7
- package/lib/esnode.js.map +1 -0
- package/lib/esvue.js +3 -6
- package/lib/esvue.js.map +1 -0
- package/lib/formatters/behave-json-formatter.js +18 -8
- package/lib/formatters/behave-json-formatter.js.map +1 -0
- package/lib/formatters/junit-bamboo-formatter.js +2 -2
- package/lib/formatters/junit-bamboo-formatter.js.map +1 -0
- package/lib/formatters/tsflow-snippet-syntax.js +2 -3
- package/lib/formatters/tsflow-snippet-syntax.js.map +1 -0
- package/lib/gherkin/configuration.d.ts +4 -4
- package/lib/gherkin/configuration.js +1 -1
- package/lib/gherkin/configuration.js.map +1 -0
- package/lib/gherkin/gherkin-feature.js +18 -8
- package/lib/gherkin/gherkin-feature.js.map +1 -0
- package/lib/gherkin/gherkin-manager.js +2 -2
- package/lib/gherkin/gherkin-manager.js.map +1 -0
- package/lib/gherkin/models.d.ts +1 -1
- package/lib/gherkin/models.js +1 -1
- package/lib/gherkin/models.js.map +1 -0
- package/lib/index.d.ts +6 -3
- package/lib/index.js +30 -18
- package/lib/index.js.map +1 -0
- package/lib/junitbamboo.js +18 -8
- package/lib/junitbamboo.js.map +1 -0
- package/lib/runtime/coordinator.d.ts +15 -0
- package/lib/runtime/coordinator.js +40 -0
- package/lib/runtime/coordinator.js.map +1 -0
- package/lib/runtime/make-runtime.d.ts +22 -0
- package/lib/runtime/make-runtime.js +17 -0
- package/lib/runtime/make-runtime.js.map +1 -0
- package/lib/runtime/managed-scenario-context.d.ts +52 -0
- package/lib/runtime/managed-scenario-context.js +149 -0
- package/lib/runtime/managed-scenario-context.js.map +1 -0
- package/lib/runtime/message-collector.d.ts +98 -0
- package/lib/runtime/message-collector.js +284 -0
- package/lib/runtime/message-collector.js.map +1 -0
- package/lib/runtime/parallel/adapter.d.ts +47 -0
- package/lib/runtime/parallel/adapter.js +159 -0
- package/lib/runtime/parallel/adapter.js.map +1 -0
- package/lib/runtime/parallel/run-worker.d.ts +1 -0
- package/lib/runtime/parallel/run-worker.js +24 -0
- package/lib/runtime/parallel/run-worker.js.map +1 -0
- package/lib/runtime/parallel/types.d.ts +13 -0
- package/lib/runtime/parallel/types.js +3 -0
- package/lib/runtime/parallel/types.js.map +1 -0
- package/lib/runtime/parallel/worker.d.ts +44 -0
- package/lib/runtime/parallel/worker.js +118 -0
- package/lib/runtime/parallel/worker.js.map +1 -0
- package/lib/runtime/serial/adapter.d.ts +12 -0
- package/lib/runtime/serial/adapter.js +24 -0
- package/lib/runtime/serial/adapter.js.map +1 -0
- package/lib/runtime/test-case-info.d.ts +23 -0
- package/lib/runtime/test-case-info.js +3 -0
- package/lib/runtime/test-case-info.js.map +1 -0
- package/lib/runtime/test-case-runner.d.ts +48 -0
- package/lib/runtime/test-case-runner.js +359 -0
- package/lib/runtime/test-case-runner.js.map +1 -0
- package/lib/runtime/utils.d.ts +16 -0
- package/lib/runtime/utils.js +78 -0
- package/lib/runtime/utils.js.map +1 -0
- package/lib/runtime/worker.d.ts +17 -0
- package/lib/runtime/worker.js +57 -0
- package/lib/runtime/worker.js.map +1 -0
- package/lib/snippet.js +20 -10
- package/lib/snippet.js.map +1 -0
- package/lib/transpilers/esbuild-transpiler.d.ts +1 -1
- package/lib/transpilers/esbuild-transpiler.js +1 -1
- package/lib/transpilers/esbuild-transpiler.js.map +1 -0
- package/lib/transpilers/esbuild.js +4 -4
- package/lib/transpilers/esbuild.js.map +1 -0
- package/lib/transpilers/vue-sfc/compiler.js +1 -1
- package/lib/transpilers/vue-sfc/compiler.js.map +1 -0
- package/lib/transpilers/vue-sfc/index.d.ts +4 -4
- package/lib/transpilers/vue-sfc/index.js +1 -2
- package/lib/transpilers/vue-sfc/index.js.map +1 -0
- package/lib/transpilers/vue-sfc/main.d.ts +1 -1
- package/lib/transpilers/vue-sfc/main.js +1 -1
- package/lib/transpilers/vue-sfc/main.js.map +1 -0
- package/lib/transpilers/vue-sfc/script.js +1 -2
- package/lib/transpilers/vue-sfc/script.js.map +1 -0
- package/lib/transpilers/vue-sfc/template.d.ts +1 -1
- package/lib/transpilers/vue-sfc/template.js +2 -3
- package/lib/transpilers/vue-sfc/template.js.map +1 -0
- package/lib/transpilers/vue-sfc/types.d.ts +2 -2
- package/lib/transpilers/vue-sfc/types.js +1 -1
- package/lib/transpilers/vue-sfc/types.js.map +1 -0
- package/lib/transpilers/vue-sfc/utils/descriptorCache.js +1 -1
- package/lib/transpilers/vue-sfc/utils/descriptorCache.js.map +1 -0
- package/lib/transpilers/vue-sfc/utils/error.js +1 -1
- package/lib/transpilers/vue-sfc/utils/error.js.map +1 -0
- package/lib/transpilers/vue-sfc/utils/query.js +1 -1
- package/lib/transpilers/vue-sfc/utils/query.js.map +1 -0
- package/lib/tsconfig.node.tsbuildinfo +1 -0
- package/lib/tsnode.d.ts +1 -0
- package/lib/tsnode.js +4 -6
- package/lib/tsnode.js.map +1 -0
- package/lib/tsvue.js +3 -6
- package/lib/tsvue.js.map +1 -0
- package/lib/types/parallel.d.ts +11 -0
- package/lib/types/parallel.js +3 -0
- package/lib/types/parallel.js.map +1 -0
- package/lib/types/scenario-context.js +1 -1
- package/lib/types/scenario-context.js.map +1 -0
- package/lib/types/scenario-info.js +1 -1
- package/lib/types/scenario-info.js.map +1 -0
- package/lib/types/step-binding-flags.js +1 -1
- package/lib/types/step-binding-flags.js.map +1 -0
- package/lib/types/step-binding.d.ts +30 -20
- package/lib/types/step-binding.js +1 -1
- package/lib/types/step-binding.js.map +1 -0
- package/lib/types/types.js +1 -1
- package/lib/types/types.js.map +1 -0
- package/lib/utils/helpers.js +1 -1
- package/lib/utils/helpers.js.map +1 -0
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +7 -26
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/our-callsite.js +18 -8
- package/lib/utils/our-callsite.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +2 -2
- package/lib/version.js.map +1 -0
- package/lib/wrapper.mjs +21 -0
- package/package.json +68 -27
- package/lib/cucumber/binding-decorator.js +0 -181
- package/lib/cucumber/binding-registry.js +0 -231
- package/lib/cucumber/parallel/coordinator.d.ts +0 -79
- package/lib/cucumber/parallel/coordinator.js +0 -247
- package/lib/cucumber/runtime.d.ts +0 -40
- package/lib/cucumber/runtime.js +0 -85
- package/lib/cucumber/step-definition-decorators.js +0 -92
package/lib/behave.js
CHANGED
|
@@ -15,14 +15,24 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
const behave = __importStar(require("./formatters/behave-json-formatter"));
|
|
27
37
|
module.exports = behave;
|
|
28
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=behave.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StepBinding } from '../types/step-binding';
|
|
2
|
+
/**
|
|
3
|
+
* Add a StepBinding to the DecoratorContext metadata
|
|
4
|
+
*
|
|
5
|
+
* @param context Current DecoratorContext
|
|
6
|
+
* @param binding StepBinding to add
|
|
7
|
+
*/
|
|
8
|
+
export declare const addStepBinding: (context: DecoratorContext, binding: StepBinding) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Get all step bindings in DecoratorContext metadata and then reset
|
|
11
|
+
* stepBindings in the metadata to an empty array if reset = true (default)
|
|
12
|
+
*
|
|
13
|
+
* @param context Current DecoratorContext
|
|
14
|
+
* @param reset Reset metadata on the context. Default=true
|
|
15
|
+
* @returns Array of StepBindings
|
|
16
|
+
*/
|
|
17
|
+
export declare const getStepBindings: (context: DecoratorContext, reset?: boolean) => StepBinding[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStepBindings = exports.addStepBinding = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Add a StepBinding to the DecoratorContext metadata
|
|
6
|
+
*
|
|
7
|
+
* @param context Current DecoratorContext
|
|
8
|
+
* @param binding StepBinding to add
|
|
9
|
+
*/
|
|
10
|
+
const addStepBinding = (context, binding) => {
|
|
11
|
+
if (!context.metadata.stepBindings)
|
|
12
|
+
context.metadata.stepBindings = new Array();
|
|
13
|
+
context.metadata.stepBindings.push(binding);
|
|
14
|
+
};
|
|
15
|
+
exports.addStepBinding = addStepBinding;
|
|
16
|
+
/**
|
|
17
|
+
* Get all step bindings in DecoratorContext metadata and then reset
|
|
18
|
+
* stepBindings in the metadata to an empty array if reset = true (default)
|
|
19
|
+
*
|
|
20
|
+
* @param context Current DecoratorContext
|
|
21
|
+
* @param reset Reset metadata on the context. Default=true
|
|
22
|
+
* @returns Array of StepBindings
|
|
23
|
+
*/
|
|
24
|
+
const getStepBindings = (context, reset = true) => {
|
|
25
|
+
let bindings = [];
|
|
26
|
+
const stepBindings = context.metadata.stepBindings;
|
|
27
|
+
if (stepBindings && stepBindings.length > 0) {
|
|
28
|
+
bindings = [...stepBindings];
|
|
29
|
+
if (reset) {
|
|
30
|
+
context.metadata.stepBindings = new Array();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return bindings;
|
|
34
|
+
};
|
|
35
|
+
exports.getStepBindings = getStepBindings;
|
|
36
|
+
//# sourceMappingURL=binding-context.js.map
|
|
@@ -0,0 +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,4 +1,4 @@
|
|
|
1
|
-
import { ContextType
|
|
1
|
+
import { ContextType } from '../types/types';
|
|
2
2
|
/**
|
|
3
3
|
* A class decorator that marks the associated class as a CucumberJS binding.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import { ContextType, TypeDecorator } from '../types/types';
|
|
|
7
7
|
*
|
|
8
8
|
* An instance of the decorated class will be created for each scenario.
|
|
9
9
|
*/
|
|
10
|
-
export declare function binding(requiredContextTypes?: ContextType[]):
|
|
10
|
+
export declare function binding(requiredContextTypes?: ContextType[]): any;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.binding = binding;
|
|
7
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
8
|
+
const binding_context_1 = require("./binding-context");
|
|
9
|
+
const index_1 = __importDefault(require("@cucumber/cucumber/lib/support_code_library_builder/index"));
|
|
10
|
+
const binding_registry_1 = require("./binding-registry");
|
|
11
|
+
const step_binding_1 = require("../types/step-binding");
|
|
12
|
+
const cucumber_2 = require("@cucumber/cucumber");
|
|
13
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
14
|
+
/**
|
|
15
|
+
* A set of step patterns that have been registered with Cucumber.
|
|
16
|
+
*
|
|
17
|
+
* In order to support scoped (or tagged) step definitions, we must ensure that any step binding is
|
|
18
|
+
* only registered with Cucumber once. The binding function for that step pattern then becomes
|
|
19
|
+
* responsible for looking up and execuing the step binding based on the context that is in scope at
|
|
20
|
+
* the point of invocation.
|
|
21
|
+
*/
|
|
22
|
+
const stepPatternRegistrations = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* A class decorator that marks the associated class as a CucumberJS binding.
|
|
25
|
+
*
|
|
26
|
+
* @param requiredContextTypes An optional array of Types that will be created and passed into the created
|
|
27
|
+
* object for each scenario.
|
|
28
|
+
*
|
|
29
|
+
* An instance of the decorated class will be created for each scenario.
|
|
30
|
+
*/
|
|
31
|
+
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;
|
|
49
|
+
}
|
|
50
|
+
if (stepBindingFlags & stepBinding.bindingType) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
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
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Called only once to register new parameters. This has to be
|
|
65
|
+
* executed here during binding initialization for cucumber to
|
|
66
|
+
* to use it when matching expressions. Attempting to add it
|
|
67
|
+
* before the test run doesn't work
|
|
68
|
+
*/
|
|
69
|
+
const defineParameters = underscore_1.default.once(() => {
|
|
70
|
+
(0, cucumber_2.defineParameterType)({
|
|
71
|
+
name: 'boolean',
|
|
72
|
+
regexp: /true|false/,
|
|
73
|
+
transformer: s => (s === 'true' ? true : false)
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Binds a step definition to Cucumber.
|
|
78
|
+
*
|
|
79
|
+
* @param stepBinding The [[StepBinding]] that represents a 'given', 'when', or 'then' step definition.
|
|
80
|
+
*/
|
|
81
|
+
function bindStepDefinition(stepBinding) {
|
|
82
|
+
const stepFunction = function () {
|
|
83
|
+
const bindingRegistry = binding_registry_1.BindingRegistry.instance;
|
|
84
|
+
const scenarioContext = global.messageCollector.getStepScenarioContext(stepBinding);
|
|
85
|
+
if (scenarioContext) {
|
|
86
|
+
const matchingStepBindings = bindingRegistry.getStepBindings(stepBinding.stepPattern.toString(), scenarioContext.scenarioInfo.tags);
|
|
87
|
+
if (matchingStepBindings.length > 1) {
|
|
88
|
+
let message = `Ambiguous step definitions for '${matchingStepBindings[0].stepPattern}':\n`;
|
|
89
|
+
matchingStepBindings.forEach(matchingStepBinding => {
|
|
90
|
+
message =
|
|
91
|
+
message +
|
|
92
|
+
`\t\t${String(matchingStepBinding.classPropertyKey)} (${matchingStepBinding.callsite.toString()})\n`;
|
|
93
|
+
});
|
|
94
|
+
throw new Error(message);
|
|
95
|
+
}
|
|
96
|
+
else if (matchingStepBindings.length === 0) {
|
|
97
|
+
throw new Error(`Cannot find matched step definition for ${stepBinding.stepPattern.toString()} with tag ${scenarioContext.scenarioInfo.tags} in binding registry`);
|
|
98
|
+
}
|
|
99
|
+
const contextTypes = bindingRegistry.getContextTypesForClass(matchingStepBindings[0].classPrototype);
|
|
100
|
+
const bindingObject = scenarioContext.getOrActivateBindingClass(matchingStepBindings[0].classPrototype, contextTypes, this);
|
|
101
|
+
bindingObject._worldObj = this;
|
|
102
|
+
return bindingObject[matchingStepBindings[0].classPropertyKey].apply(bindingObject, arguments);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new Error('Unable to find the Scenario Context for a Step!');
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
Object.defineProperty(stepFunction, 'length', {
|
|
109
|
+
value: stepBinding.stepArgsLength
|
|
110
|
+
});
|
|
111
|
+
// initialize options used on all step bindings
|
|
112
|
+
const options = {
|
|
113
|
+
cucumberKey: stepBinding.cucumberKey,
|
|
114
|
+
timeout: stepBinding.timeout,
|
|
115
|
+
wrapperOptions: stepBinding.wrapperOption
|
|
116
|
+
};
|
|
117
|
+
// call appropriate step
|
|
118
|
+
if (stepBinding.bindingType & step_binding_1.StepBindingFlags.given) {
|
|
119
|
+
(0, cucumber_1.Given)(stepBinding.stepPattern, options, stepFunction);
|
|
120
|
+
}
|
|
121
|
+
else if (stepBinding.bindingType & step_binding_1.StepBindingFlags.when) {
|
|
122
|
+
(0, cucumber_1.When)(stepBinding.stepPattern, options, stepFunction);
|
|
123
|
+
}
|
|
124
|
+
else if (stepBinding.bindingType & step_binding_1.StepBindingFlags.then) {
|
|
125
|
+
(0, cucumber_1.Then)(stepBinding.stepPattern, options, stepFunction);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Binds a hook to Cucumber.
|
|
130
|
+
*
|
|
131
|
+
* @param stepBinding The [[StepBinding]] that represents a 'before', or 'after', step definition.
|
|
132
|
+
*/
|
|
133
|
+
function bindHook(stepBinding) {
|
|
134
|
+
// beforeAll and afterAll are called before and after all tests.
|
|
135
|
+
// these can be class instance or static functions
|
|
136
|
+
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;
|
|
140
|
+
}
|
|
141
|
+
return stepBinding.classPrototype[stepBinding.classPropertyKey].apply();
|
|
142
|
+
};
|
|
143
|
+
// Main binding for all other steps
|
|
144
|
+
const hookFunction = function (arg) {
|
|
145
|
+
const scenarioContext = global.messageCollector.getHookScenarioContext(arg);
|
|
146
|
+
if (scenarioContext) {
|
|
147
|
+
const contextTypes = binding_registry_1.BindingRegistry.instance.getContextTypesForClass(stepBinding.classPrototype);
|
|
148
|
+
const bindingObject = scenarioContext.getOrActivateBindingClass(stepBinding.classPrototype, contextTypes, this);
|
|
149
|
+
bindingObject._worldObj = this;
|
|
150
|
+
return bindingObject[stepBinding.classPropertyKey].apply(bindingObject, arguments);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
throw new Error('Unable to find the Scenario Context for Hook!');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// length values need to be added to our binding functions.
|
|
157
|
+
// These are used in cucumber to determine if the function is
|
|
158
|
+
// a callback or promise.
|
|
159
|
+
Object.defineProperty(globalHookFunction, 'length', {
|
|
160
|
+
value: stepBinding.stepArgsLength
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(hookFunction, 'length', {
|
|
163
|
+
value: stepBinding.stepArgsLength
|
|
164
|
+
});
|
|
165
|
+
const tags = stepBinding.tags === binding_registry_1.DEFAULT_TAG ? undefined : stepBinding.tags;
|
|
166
|
+
// This binds the appropriate function above to the associated
|
|
167
|
+
// cucumber step functions.
|
|
168
|
+
switch (stepBinding.bindingType) {
|
|
169
|
+
case step_binding_1.StepBindingFlags.beforeAll: {
|
|
170
|
+
const options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };
|
|
171
|
+
(0, cucumber_1.BeforeAll)(options, globalHookFunction);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case step_binding_1.StepBindingFlags.before: {
|
|
175
|
+
const options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };
|
|
176
|
+
(0, cucumber_1.Before)(options, hookFunction);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case step_binding_1.StepBindingFlags.beforeStep: {
|
|
180
|
+
const options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };
|
|
181
|
+
(0, cucumber_1.BeforeStep)(options, hookFunction);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case step_binding_1.StepBindingFlags.afterAll: {
|
|
185
|
+
const options = { cucumberKey: stepBinding.cucumberKey, timeout: stepBinding.timeout };
|
|
186
|
+
(0, cucumber_1.AfterAll)(options, globalHookFunction);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case step_binding_1.StepBindingFlags.after: {
|
|
190
|
+
const options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };
|
|
191
|
+
(0, cucumber_1.After)(options, hookFunction);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case step_binding_1.StepBindingFlags.afterStep: {
|
|
195
|
+
const options = { cucumberKey: stepBinding.cucumberKey, tags: tags, timeout: stepBinding.timeout };
|
|
196
|
+
(0, cucumber_1.AfterStep)(options, hookFunction);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=binding-decorator.js.map
|
|
@@ -0,0 +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,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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 '../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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types';
|
|
2
2
|
import { StepBinding } from '../types/step-binding';
|
|
3
3
|
import { ContextType, StepPattern, TagName } from '../types/types';
|
|
4
4
|
/**
|
|
@@ -13,8 +13,8 @@ export declare const DEFAULT_TAG = "*";
|
|
|
13
13
|
* A metadata registry that captures information about bindings and their bound step bindings.
|
|
14
14
|
*/
|
|
15
15
|
export declare class BindingRegistry {
|
|
16
|
-
private
|
|
17
|
-
private
|
|
16
|
+
private _stepBindings;
|
|
17
|
+
private _classBindings;
|
|
18
18
|
/**
|
|
19
19
|
* Gets the binding registry singleton.
|
|
20
20
|
*
|
|
@@ -25,20 +25,20 @@ export declare class BindingRegistry {
|
|
|
25
25
|
* Updates the binding registry with information about the context types required by a
|
|
26
26
|
* binding class.
|
|
27
27
|
*
|
|
28
|
-
* @param
|
|
28
|
+
* @param classPrototype The class representing the binding (constructor function).
|
|
29
29
|
* @param contextTypes An array of [[ContextType]] that define the types of objects that
|
|
30
30
|
* should be injected into the binding class during a scenario execution.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
registerContextTypesForClass(classPrototype: any, contextTypes?: ContextType[]): void;
|
|
33
33
|
/**
|
|
34
34
|
* Retrieves the context types that have been registered for a given binding class.
|
|
35
35
|
*
|
|
36
|
-
* @param
|
|
36
|
+
* @param classPrototype The class representing the binding (constructor function).
|
|
37
37
|
*
|
|
38
38
|
* @returns An array of [[ContextType]] that have been registered for the specified
|
|
39
39
|
* binding class.
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
getContextTypesForClass(classPrototype: any): ContextType[];
|
|
42
42
|
/**
|
|
43
43
|
* Updates the binding registry indexes with a step binding.
|
|
44
44
|
*
|
|
@@ -70,7 +70,7 @@ export declare class BindingRegistry {
|
|
|
70
70
|
* @param library
|
|
71
71
|
* @returns
|
|
72
72
|
*/
|
|
73
|
-
updateSupportCodeLibrary: (library:
|
|
73
|
+
updateSupportCodeLibrary: (library: SupportCodeLibrary) => SupportCodeLibrary;
|
|
74
74
|
/**
|
|
75
75
|
* Maps an array of tag names to an array of associated step bindings.
|
|
76
76
|
*
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BindingRegistry = exports.DEFAULT_TAG = exports.DEFAULT_STEP_PATTERN = void 0;
|
|
7
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
8
|
+
const step_binding_1 = require("../types/step-binding");
|
|
9
|
+
const logger_1 = __importDefault(require("../utils/logger"));
|
|
10
|
+
/**
|
|
11
|
+
* Represents the default step pattern.
|
|
12
|
+
*/
|
|
13
|
+
exports.DEFAULT_STEP_PATTERN = '/.*/';
|
|
14
|
+
/**
|
|
15
|
+
* Represents the default tag.
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFAULT_TAG = '*';
|
|
18
|
+
/**
|
|
19
|
+
* A metadata registry that captures information about bindings and their bound step bindings.
|
|
20
|
+
*/
|
|
21
|
+
class BindingRegistry {
|
|
22
|
+
_stepBindings = new Map();
|
|
23
|
+
_classBindings = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Gets the binding registry singleton.
|
|
26
|
+
*
|
|
27
|
+
* @returns A [[BindingRegistry]].
|
|
28
|
+
*/
|
|
29
|
+
static get instance() {
|
|
30
|
+
const BINDING_REGISTRY_SLOTNAME = '__CUCUMBER_TSFLOW_BINDINGREGISTRY';
|
|
31
|
+
const registry = global[BINDING_REGISTRY_SLOTNAME];
|
|
32
|
+
if (!registry) {
|
|
33
|
+
global[BINDING_REGISTRY_SLOTNAME] = new BindingRegistry();
|
|
34
|
+
}
|
|
35
|
+
return registry || global[BINDING_REGISTRY_SLOTNAME];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Updates the binding registry with information about the context types required by a
|
|
39
|
+
* binding class.
|
|
40
|
+
*
|
|
41
|
+
* @param classPrototype The class representing the binding (constructor function).
|
|
42
|
+
* @param contextTypes An array of [[ContextType]] that define the types of objects that
|
|
43
|
+
* should be injected into the binding class during a scenario execution.
|
|
44
|
+
*/
|
|
45
|
+
registerContextTypesForClass(classPrototype, contextTypes) {
|
|
46
|
+
if (!contextTypes) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let targetDecorations = this._classBindings.get(classPrototype);
|
|
50
|
+
if (!targetDecorations) {
|
|
51
|
+
targetDecorations = {
|
|
52
|
+
stepBindings: [],
|
|
53
|
+
contextTypes: []
|
|
54
|
+
};
|
|
55
|
+
this._classBindings.set(classPrototype, targetDecorations);
|
|
56
|
+
}
|
|
57
|
+
targetDecorations.contextTypes = contextTypes;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the context types that have been registered for a given binding class.
|
|
61
|
+
*
|
|
62
|
+
* @param classPrototype The class representing the binding (constructor function).
|
|
63
|
+
*
|
|
64
|
+
* @returns An array of [[ContextType]] that have been registered for the specified
|
|
65
|
+
* binding class.
|
|
66
|
+
*/
|
|
67
|
+
getContextTypesForClass(classPrototype) {
|
|
68
|
+
const targetBinding = this._classBindings.get(classPrototype);
|
|
69
|
+
if (!targetBinding) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return targetBinding.contextTypes;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Updates the binding registry indexes with a step binding.
|
|
76
|
+
*
|
|
77
|
+
* @param stepBinding The step binding that is to be registered with the binding registry.
|
|
78
|
+
*/
|
|
79
|
+
registerStepBinding(stepBinding) {
|
|
80
|
+
if (!stepBinding.tags) {
|
|
81
|
+
stepBinding.tags = exports.DEFAULT_TAG;
|
|
82
|
+
}
|
|
83
|
+
if (stepBinding.tags !== exports.DEFAULT_TAG && !stepBinding.tags.startsWith('@')) {
|
|
84
|
+
// tslint:disable-next-line:no-console
|
|
85
|
+
logger_1.default.debug('tag should start with @; tsflow has stopped to automatically prepend @ for you.');
|
|
86
|
+
}
|
|
87
|
+
const stepPattern = stepBinding.stepPattern
|
|
88
|
+
? stepBinding.stepPattern.toString()
|
|
89
|
+
: exports.DEFAULT_STEP_PATTERN;
|
|
90
|
+
let tagMap = this._stepBindings.get(stepPattern);
|
|
91
|
+
if (!tagMap) {
|
|
92
|
+
tagMap = new Map();
|
|
93
|
+
this._stepBindings.set(stepPattern, tagMap);
|
|
94
|
+
}
|
|
95
|
+
let stepBindings = tagMap.get(stepBinding.tags);
|
|
96
|
+
if (!stepBindings) {
|
|
97
|
+
stepBindings = [];
|
|
98
|
+
tagMap.set(stepBinding.tags, stepBindings);
|
|
99
|
+
}
|
|
100
|
+
if (!stepBindings.some(b => isSameStepBinding(stepBinding, b))) {
|
|
101
|
+
stepBindings.push(stepBinding);
|
|
102
|
+
}
|
|
103
|
+
// Index the step binding for the target
|
|
104
|
+
let targetBinding = this._classBindings.get(stepBinding.classPrototype);
|
|
105
|
+
if (!targetBinding) {
|
|
106
|
+
targetBinding = {
|
|
107
|
+
stepBindings: [],
|
|
108
|
+
contextTypes: []
|
|
109
|
+
};
|
|
110
|
+
this._classBindings.set(stepBinding.classPrototype, targetBinding);
|
|
111
|
+
}
|
|
112
|
+
if (!targetBinding.stepBindings.some(b => isSameStepBinding(stepBinding, b))) {
|
|
113
|
+
targetBinding.stepBindings.push(stepBinding);
|
|
114
|
+
}
|
|
115
|
+
function isSameStepBinding(a, b) {
|
|
116
|
+
return (a.callsite.filename === b.callsite.filename &&
|
|
117
|
+
a.callsite.lineNumber === b.callsite.lineNumber &&
|
|
118
|
+
String(a.tags) === String(b.tags) &&
|
|
119
|
+
String(a.stepPattern) === String(b.stepPattern));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves the step bindings that have been registered for a given binding class.
|
|
124
|
+
*
|
|
125
|
+
* @param targetPrototype The class representing the binding (constructor function).
|
|
126
|
+
*
|
|
127
|
+
* @returns An array of [[StepBinding]] objects that have been registered for the specified
|
|
128
|
+
* binding class.
|
|
129
|
+
*/
|
|
130
|
+
getStepBindingsForTarget(targetPrototype) {
|
|
131
|
+
const targetBinding = this._classBindings.get(targetPrototype);
|
|
132
|
+
if (!targetBinding) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return targetBinding.stepBindings;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves the step bindings for a given step pattern and collection of tag names.
|
|
139
|
+
*
|
|
140
|
+
* @param stepPattern The step pattern to search.
|
|
141
|
+
* @param tags An array of [[TagName]] to search.
|
|
142
|
+
*
|
|
143
|
+
* @returns An array of [[StepBinding]] that map to the given step pattern and set of tag names.
|
|
144
|
+
*/
|
|
145
|
+
getStepBindings(stepPattern, tags) {
|
|
146
|
+
const tagMap = this._stepBindings.get(stepPattern);
|
|
147
|
+
if (!tagMap) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const matchingStepBindings = this.mapTagNamesToStepBindings(tags, tagMap);
|
|
151
|
+
if (matchingStepBindings.length > 0) {
|
|
152
|
+
return matchingStepBindings;
|
|
153
|
+
}
|
|
154
|
+
return this.mapTagNamesToStepBindings(['*'], tagMap);
|
|
155
|
+
}
|
|
156
|
+
getStepBindingByCucumberKey(cucumberKey) {
|
|
157
|
+
let result = undefined;
|
|
158
|
+
for (const [_, binding] of this._classBindings) {
|
|
159
|
+
for (const stepBinding of binding.stepBindings) {
|
|
160
|
+
if (stepBinding.cucumberKey === cucumberKey) {
|
|
161
|
+
result = stepBinding;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (result) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Updates the SupportCodeLibrary from Cucumber with
|
|
173
|
+
* callsite information from tsflow bindings
|
|
174
|
+
* @param library
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
updateSupportCodeLibrary = (library) => {
|
|
178
|
+
this._classBindings.forEach(binding => {
|
|
179
|
+
binding.stepBindings.forEach(stepBinding => {
|
|
180
|
+
let cucumberDefinition = undefined;
|
|
181
|
+
switch (stepBinding.bindingType) {
|
|
182
|
+
case step_binding_1.StepBindingFlags.beforeAll:
|
|
183
|
+
cucumberDefinition = library.beforeTestRunHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
184
|
+
break;
|
|
185
|
+
case step_binding_1.StepBindingFlags.before:
|
|
186
|
+
cucumberDefinition = library.beforeTestCaseHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
187
|
+
break;
|
|
188
|
+
case step_binding_1.StepBindingFlags.beforeStep:
|
|
189
|
+
cucumberDefinition = library.beforeTestStepHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
190
|
+
break;
|
|
191
|
+
case step_binding_1.StepBindingFlags.given:
|
|
192
|
+
cucumberDefinition = library.stepDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
193
|
+
break;
|
|
194
|
+
case step_binding_1.StepBindingFlags.when:
|
|
195
|
+
cucumberDefinition = library.stepDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
196
|
+
break;
|
|
197
|
+
case step_binding_1.StepBindingFlags.then:
|
|
198
|
+
cucumberDefinition = library.stepDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
199
|
+
break;
|
|
200
|
+
case step_binding_1.StepBindingFlags.afterStep:
|
|
201
|
+
cucumberDefinition = library.afterTestStepHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
202
|
+
break;
|
|
203
|
+
case step_binding_1.StepBindingFlags.after:
|
|
204
|
+
cucumberDefinition = library.afterTestCaseHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
205
|
+
break;
|
|
206
|
+
case step_binding_1.StepBindingFlags.afterAll:
|
|
207
|
+
cucumberDefinition = library.afterTestRunHookDefinitions.find(s => s.options.cucumberKey === stepBinding.cucumberKey);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
if (cucumberDefinition) {
|
|
211
|
+
cucumberDefinition.line = stepBinding.callsite.lineNumber;
|
|
212
|
+
cucumberDefinition.uri = stepBinding.callsite.filename;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
return library;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Maps an array of tag names to an array of associated step bindings.
|
|
220
|
+
*
|
|
221
|
+
* @param tags An array of [[TagName]].
|
|
222
|
+
* @param tagMap The map of [[TagName]] -> [[StepBinding]] to use when mapping.
|
|
223
|
+
*
|
|
224
|
+
* @returns An array of [[StepBinding]].
|
|
225
|
+
*/
|
|
226
|
+
mapTagNamesToStepBindings(tags, tagMap) {
|
|
227
|
+
const matchingStepBindings = underscore_1.default.flatten(underscore_1.default.map(tags, tag => tagMap.get(tag)));
|
|
228
|
+
return underscore_1.default.reject(matchingStepBindings, stepBinding => stepBinding === undefined);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.BindingRegistry = BindingRegistry;
|
|
232
|
+
//# sourceMappingURL=binding-registry.js.map
|