@zohodesk/testinglibrary 0.1.8-exp.15 → 0.1.8-exp.16

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 (74) hide show
  1. package/build/bdd-framework/cli/commands/env.js +1 -1
  2. package/build/bdd-framework/config/configDir.js +35 -0
  3. package/build/bdd-framework/config/enrichReporterData.js +23 -0
  4. package/build/bdd-framework/config/index.js +10 -6
  5. package/build/bdd-framework/cucumber/createTestStep.js +43 -0
  6. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +126 -0
  7. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +72 -0
  8. package/build/bdd-framework/cucumber/formatter/PickleParser.js +25 -0
  9. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +13 -0
  10. package/build/bdd-framework/cucumber/formatter/getColorFns.js +57 -0
  11. package/build/bdd-framework/cucumber/formatter/index.js +16 -0
  12. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +16 -0
  13. package/build/bdd-framework/cucumber/loadFeatures.js +62 -31
  14. package/build/bdd-framework/cucumber/loadSteps.js +7 -0
  15. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +62 -0
  16. package/build/bdd-framework/cucumber/stepArguments.js +21 -0
  17. package/build/bdd-framework/cucumber/valueChecker.js +23 -0
  18. package/build/bdd-framework/gen/formatter.js +11 -23
  19. package/build/bdd-framework/gen/index.js +41 -20
  20. package/build/bdd-framework/gen/testFile.js +69 -26
  21. package/build/bdd-framework/gen/testMeta.js +60 -0
  22. package/build/bdd-framework/gen/testNode.js +11 -12
  23. package/build/bdd-framework/hooks/scenario.js +29 -6
  24. package/build/bdd-framework/hooks/worker.js +7 -1
  25. package/build/bdd-framework/index.js +8 -1
  26. package/build/bdd-framework/playwright/getLocationInFile.js +36 -9
  27. package/build/bdd-framework/playwright/loadUtils.js +33 -0
  28. package/build/bdd-framework/playwright/transform.js +5 -1
  29. package/build/bdd-framework/reporter/cucumber/base.js +57 -0
  30. package/build/bdd-framework/reporter/cucumber/custom.js +73 -0
  31. package/build/bdd-framework/reporter/cucumber/helper.js +12 -0
  32. package/build/bdd-framework/reporter/cucumber/html.js +35 -0
  33. package/build/bdd-framework/reporter/cucumber/index.js +74 -0
  34. package/build/bdd-framework/reporter/cucumber/json.js +312 -0
  35. package/build/bdd-framework/reporter/cucumber/junit.js +205 -0
  36. package/build/bdd-framework/reporter/cucumber/message.js +20 -0
  37. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +64 -0
  38. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +196 -0
  39. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +43 -0
  40. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +52 -0
  41. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +105 -0
  42. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +70 -0
  43. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +45 -0
  44. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +27 -0
  45. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +38 -0
  46. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +128 -0
  47. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +126 -0
  48. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +102 -0
  49. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +50 -0
  50. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +88 -0
  51. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +30 -0
  52. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwUtils.js +51 -0
  53. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +35 -0
  54. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +5 -0
  55. package/build/bdd-framework/run/StepInvoker.js +21 -26
  56. package/build/bdd-framework/run/bddDataAttachment.js +46 -0
  57. package/build/bdd-framework/run/bddFixtures.js +31 -10
  58. package/build/bdd-framework/run/bddWorld.js +5 -2
  59. package/build/bdd-framework/run/bddWorldInternal.js +15 -0
  60. package/build/bdd-framework/snippets/index.js +3 -7
  61. package/build/bdd-framework/stepDefinitions/defineStep.js +1 -1
  62. package/build/bdd-framework/utils/AutofillMap.js +20 -0
  63. package/build/bdd-framework/utils/index.js +23 -0
  64. package/build/bdd-framework/utils/stripAnsiEscapes.js +20 -0
  65. package/build/core/playwright/helpers/getUserFixtures.js +8 -3
  66. package/build/core/playwright/readConfigFile.js +1 -0
  67. package/build/core/playwright/setup/config-creator.js +1 -0
  68. package/build/core/playwright/test-runner.js +0 -1
  69. package/build/lib/post-install.js +2 -0
  70. package/npm-shrinkwrap.json +18 -12
  71. package/package.json +6 -4
  72. package/build/bdd-framework/config/dir.js +0 -27
  73. package/build/bdd-framework/cucumber/loadSources.js +0 -57
  74. /package/build/bdd-framework/cucumber/{gherkin.d.js → types.js} +0 -0
@@ -33,7 +33,7 @@ function showPackageVersion(packageName) {
33
33
  * to aneble using directly from /dist in tests.
34
34
  */
35
35
  function getOwnVersion() {
36
- return '5.6.0';
36
+ return '6.0.1';
37
37
  }
38
38
  function showPlaywrightConfigPath(cliConfigPath) {
39
39
  const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getPlaywrightConfigDir = getPlaywrightConfigDir;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _loadConfig = require("../playwright/loadConfig");
10
+ var _options = require("../cli/options");
11
+ /**
12
+ * Store playwright config dir in env to provide access to it in workers.
13
+ * Important that in workers there is different process.argv, that's why we save it to env.
14
+ * Config dir is needed to resolve all paths (features, step definitions).
15
+ */
16
+
17
+ /**
18
+ * Returns Playwright config dir considering cli --config option.
19
+ */
20
+ function getPlaywrightConfigDir({
21
+ resolveAndSave = false
22
+ } = {}) {
23
+ let configDir = process.env.PLAYWRIGHT_BDD_CONFIG_DIR;
24
+ if (!configDir) {
25
+ if (resolveAndSave) {
26
+ const cliConfigPath = (0, _options.getCliConfigPath)();
27
+ const playwrightConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
28
+ configDir = playwrightConfigFile ? _path.default.dirname(playwrightConfigFile) : process.cwd();
29
+ process.env.PLAYWRIGHT_BDD_CONFIG_DIR = configDir;
30
+ } else {
31
+ throw new Error(`Something went wrong: PLAYWRIGHT_BDD_CONFIG_DIR is not set.`);
32
+ }
33
+ }
34
+ return configDir;
35
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enableEnrichReporterData = enableEnrichReporterData;
7
+ exports.getEnrichReporterData = getEnrichReporterData;
8
+ function enableEnrichReporterData() {
9
+ process.env.PLAYWRIGHT_BDD_ENRICH_REPORTER_DATA = '1';
10
+ }
11
+ function getEnrichReporterData(config) {
12
+ const enrichReporterDataFromEnv = Boolean(process.env.PLAYWRIGHT_BDD_ENRICH_REPORTER_DATA);
13
+ if (config.enrichReporterData === true) {
14
+ return true;
15
+ }
16
+ if (config.enrichReporterData === false) {
17
+ if (enrichReporterDataFromEnv) {
18
+ throw new Error([`Cucumber reports can't work with enrichReporterData = false in bdd config.`, `Please, set enrichReporterData = true OR remove it from config`, `to let it be auto-configured.`].join(' '));
19
+ }
20
+ return false;
21
+ }
22
+ return enrichReporterDataFromEnv;
23
+ }
@@ -9,7 +9,7 @@ exports.defineBddConfig = defineBddConfig;
9
9
  exports.extractCucumberConfig = extractCucumberConfig;
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
  var _env = require("./env");
12
- var _dir = require("./dir");
12
+ var _configDir = require("./configDir");
13
13
  var _utils = require("../utils");
14
14
  /**
15
15
  * BDD Config.
@@ -23,16 +23,19 @@ const defaults = exports.defaults = {
23
23
  quotes: 'double'
24
24
  };
25
25
  function defineBddConfig(inputConfig) {
26
- const config = getConfig(inputConfig);
26
+ const isMainProcess = !process.env.TEST_WORKER_INDEX;
27
+ const configDir = (0, _configDir.getPlaywrightConfigDir)({
28
+ resolveAndSave: isMainProcess
29
+ });
30
+ const config = getConfig(configDir, inputConfig);
27
31
  // In main process store config in env to be accessible by workers
28
- if (!process.env.TEST_WORKER_INDEX) {
32
+ if (isMainProcess) {
29
33
  (0, _env.saveConfigToEnv)(config);
30
34
  }
31
35
  return config.outputDir;
32
36
  }
33
- function getConfig(inputConfig) {
37
+ function getConfig(configDir, inputConfig) {
34
38
  const config = Object.assign({}, defaults, inputConfig);
35
- const configDir = (0, _dir.getPlaywrightConfigDir)();
36
39
  const featuresRoot = config.featuresRoot ? _path.default.resolve(configDir, config.featuresRoot) : configDir;
37
40
  return {
38
41
  ...config,
@@ -53,7 +56,8 @@ function extractCucumberConfig(config) {
53
56
  examplesTitleFormat: true,
54
57
  quotes: true,
55
58
  tags: true,
56
- featuresRoot: true
59
+ featuresRoot: true,
60
+ enrichReporterData: true
57
61
  };
58
62
  const keys = Object.keys(omitProps);
59
63
  const cucumberConfig = {
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createTestStep = createTestStep;
7
+ /**
8
+ * Creates partial TestStep for usage in reporter.
9
+ * It is partial, b/c final pickleStepId will be known only in reporter.
10
+ *
11
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/runtime/assemble_test_cases.ts#L93
12
+ */
13
+ function createTestStep(stepDefinition, stepText) {
14
+ const result = stepDefinition.expression.match(stepText);
15
+ if (!result) {
16
+ // this should not happen as stepDefinition is already matched
17
+ throw Error(`Step definition didn't match step "${stepText}"`);
18
+ }
19
+ const stepMatchArguments = result.map(arg => {
20
+ return {
21
+ group: mapArgumentGroup(arg.group),
22
+ parameterTypeName: arg.parameterType.name
23
+ };
24
+ });
25
+ return {
26
+ // id will be generated in reporter, no need to generate it here
27
+ id: '',
28
+ // looks like it's useless to store stepDefinitionIds here
29
+ // b/c they will be different in reporter
30
+ // stepDefinitionIds: [stepDefinition.id],
31
+ stepMatchArgumentsLists: [{
32
+ stepMatchArguments
33
+ }]
34
+ };
35
+ }
36
+ function mapArgumentGroup(group) {
37
+ var _group$children;
38
+ return {
39
+ start: group.start,
40
+ value: group.value,
41
+ children: (_group$children = group.children) === null || _group$children === void 0 ? void 0 : _group$children.map(child => mapArgumentGroup(child))
42
+ };
43
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var messages = _interopRequireWildcard(require("@cucumber/messages"));
8
+ var _valueChecker = require("../valueChecker");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ /**
12
+ * Groups Cucumber messages for easier access.
13
+ * Based on Cucumber, with some changes due to strictNullChecks errors.
14
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/helpers/event_data_collector.ts
15
+ */
16
+
17
+ class EventDataCollector {
18
+ gherkinDocumentMap = {};
19
+ pickleMap = {};
20
+ testCaseMap = {};
21
+ testCaseAttemptDataMap = {};
22
+ undefinedParameterTypes = [];
23
+ constructor(eventBroadcaster) {
24
+ eventBroadcaster.on('envelope', this.parseEnvelope.bind(this));
25
+ }
26
+ /**
27
+ * @public
28
+ */
29
+ getGherkinDocument(uri) {
30
+ return this.gherkinDocumentMap[uri];
31
+ }
32
+ /**
33
+ * @public
34
+ */
35
+ getPickle(pickleId) {
36
+ return this.pickleMap[pickleId];
37
+ }
38
+ getTestCaseAttempts() {
39
+ return Object.keys(this.testCaseAttemptDataMap).map(testCaseStartedId => {
40
+ return this.getTestCaseAttempt(testCaseStartedId);
41
+ });
42
+ }
43
+ getTestCaseAttempt(testCaseStartedId) {
44
+ const testCaseAttemptData = this.testCaseAttemptDataMap[testCaseStartedId];
45
+ const testCase = this.testCaseMap[testCaseAttemptData.testCaseId];
46
+ const pickle = this.pickleMap[testCase.pickleId];
47
+ return {
48
+ gherkinDocument: this.gherkinDocumentMap[pickle.uri],
49
+ pickle,
50
+ testCase,
51
+ attempt: testCaseAttemptData.attempt,
52
+ willBeRetried: testCaseAttemptData.willBeRetried,
53
+ stepAttachments: testCaseAttemptData.stepAttachments,
54
+ stepResults: testCaseAttemptData.stepResults,
55
+ worstTestStepResult: testCaseAttemptData.worstTestStepResult
56
+ };
57
+ }
58
+ parseEnvelope(envelope) {
59
+ var _envelope$gherkinDocu;
60
+ if ((0, _valueChecker.doesHaveValue)((_envelope$gherkinDocu = envelope.gherkinDocument) === null || _envelope$gherkinDocu === void 0 ? void 0 : _envelope$gherkinDocu.uri)) {
61
+ this.gherkinDocumentMap[envelope.gherkinDocument.uri] = envelope.gherkinDocument;
62
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.pickle)) {
63
+ this.pickleMap[envelope.pickle.id] = envelope.pickle;
64
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.undefinedParameterType)) {
65
+ this.undefinedParameterTypes.push(envelope.undefinedParameterType);
66
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.testCase)) {
67
+ this.testCaseMap[envelope.testCase.id] = envelope.testCase;
68
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.testCaseStarted)) {
69
+ this.initTestCaseAttempt(envelope.testCaseStarted);
70
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.attachment)) {
71
+ this.storeAttachment(envelope.attachment);
72
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.testStepFinished)) {
73
+ this.storeTestStepResult(envelope.testStepFinished);
74
+ } else if ((0, _valueChecker.doesHaveValue)(envelope.testCaseFinished)) {
75
+ this.storeTestCaseResult(envelope.testCaseFinished);
76
+ }
77
+ }
78
+ initTestCaseAttempt(testCaseStarted) {
79
+ this.testCaseAttemptDataMap[testCaseStarted.id] = {
80
+ attempt: testCaseStarted.attempt,
81
+ willBeRetried: false,
82
+ testCaseId: testCaseStarted.testCaseId,
83
+ stepAttachments: {},
84
+ stepResults: {},
85
+ worstTestStepResult: {
86
+ duration: {
87
+ seconds: 0,
88
+ nanos: 0
89
+ },
90
+ status: messages.TestStepResultStatus.UNKNOWN
91
+ }
92
+ };
93
+ }
94
+ storeAttachment(attachment) {
95
+ const {
96
+ testCaseStartedId,
97
+ testStepId
98
+ } = attachment;
99
+ // TODO: we shouldn't have to check if these properties have values - they are non-nullable
100
+ if ((0, _valueChecker.doesHaveValue)(testCaseStartedId) && (0, _valueChecker.doesHaveValue)(testStepId)) {
101
+ const {
102
+ stepAttachments
103
+ } = this.testCaseAttemptDataMap[testCaseStartedId];
104
+ if ((0, _valueChecker.doesNotHaveValue)(stepAttachments[testStepId])) {
105
+ stepAttachments[testStepId] = [];
106
+ }
107
+ stepAttachments[testStepId].push(attachment);
108
+ }
109
+ }
110
+ storeTestStepResult({
111
+ testCaseStartedId,
112
+ testStepId,
113
+ testStepResult
114
+ }) {
115
+ this.testCaseAttemptDataMap[testCaseStartedId].stepResults[testStepId] = testStepResult;
116
+ }
117
+ storeTestCaseResult({
118
+ testCaseStartedId,
119
+ willBeRetried
120
+ }) {
121
+ const stepResults = Object.values(this.testCaseAttemptDataMap[testCaseStartedId].stepResults);
122
+ this.testCaseAttemptDataMap[testCaseStartedId].worstTestStepResult = messages.getWorstTestStepResult(stepResults);
123
+ this.testCaseAttemptDataMap[testCaseStartedId].willBeRetried = willBeRetried;
124
+ }
125
+ }
126
+ exports.default = EventDataCollector;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getGherkinExampleRuleMap = getGherkinExampleRuleMap;
7
+ exports.getGherkinScenarioLocationMap = getGherkinScenarioLocationMap;
8
+ exports.getGherkinScenarioMap = getGherkinScenarioMap;
9
+ exports.getGherkinStepMap = getGherkinStepMap;
10
+ var _valueChecker = require("../valueChecker");
11
+ /**
12
+ * Based on: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/helpers/gherkin_document_parser.ts
13
+ */
14
+
15
+ function getGherkinStepMap(gherkinDocument) {
16
+ var _gherkinDocument$feat;
17
+ const result = {};
18
+ (_gherkinDocument$feat = gherkinDocument.feature) === null || _gherkinDocument$feat === void 0 || _gherkinDocument$feat.children.map(extractStepContainers).flat().forEach(x => x.steps.forEach(step => result[step.id] = step));
19
+ return result;
20
+ }
21
+ function extractStepContainers(child) {
22
+ if ((0, _valueChecker.doesHaveValue)(child.background)) {
23
+ return [child.background];
24
+ } else if ((0, _valueChecker.doesHaveValue)(child.rule)) {
25
+ return child.rule.children.map(ruleChild => (0, _valueChecker.doesHaveValue)(ruleChild.background) ? ruleChild.background : ruleChild.scenario).filter(v => !!v);
26
+ } else if ((0, _valueChecker.doesHaveValue)(child.scenario)) {
27
+ return [child.scenario];
28
+ } else {
29
+ throw new Error('Empty step container');
30
+ }
31
+ }
32
+ function getGherkinScenarioMap(gherkinDocument) {
33
+ var _gherkinDocument$feat2;
34
+ const result = {};
35
+ (_gherkinDocument$feat2 = gherkinDocument.feature) === null || _gherkinDocument$feat2 === void 0 || _gherkinDocument$feat2.children.map(child => {
36
+ if ((0, _valueChecker.doesHaveValue)(child.rule)) {
37
+ return child.rule.children;
38
+ }
39
+ return [child];
40
+ }).flat().forEach(x => {
41
+ if (x.scenario != null) {
42
+ result[x.scenario.id] = x.scenario;
43
+ }
44
+ });
45
+ return result;
46
+ }
47
+ function getGherkinExampleRuleMap(gherkinDocument) {
48
+ var _gherkinDocument$feat3;
49
+ const result = {};
50
+ (_gherkinDocument$feat3 = gherkinDocument.feature) === null || _gherkinDocument$feat3 === void 0 || _gherkinDocument$feat3.children.filter(x => x.rule != null).forEach(x => {
51
+ var _x$rule;
52
+ return x === null || x === void 0 || (_x$rule = x.rule) === null || _x$rule === void 0 ? void 0 : _x$rule.children.filter(child => (0, _valueChecker.doesHaveValue)(child.scenario)).forEach(child => {
53
+ var _child$scenario;
54
+ if (child !== null && child !== void 0 && (_child$scenario = child.scenario) !== null && _child$scenario !== void 0 && _child$scenario.id && x.rule) {
55
+ result[child.scenario.id] = x.rule;
56
+ }
57
+ });
58
+ });
59
+ return result;
60
+ }
61
+ function getGherkinScenarioLocationMap(gherkinDocument) {
62
+ const locationMap = {};
63
+ const scenarioMap = getGherkinScenarioMap(gherkinDocument);
64
+ Object.keys(scenarioMap).forEach(id => {
65
+ const scenario = scenarioMap[id];
66
+ locationMap[id] = scenario.location;
67
+ if ((0, _valueChecker.doesHaveValue)(scenario.examples)) {
68
+ scenario.examples.forEach(x => x.tableBody.forEach(tableRow => locationMap[tableRow.id] = tableRow.location));
69
+ }
70
+ });
71
+ return locationMap;
72
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPickleStepMap = getPickleStepMap;
7
+ exports.getScenarioDescription = getScenarioDescription;
8
+ exports.getStepKeyword = getStepKeyword;
9
+ function getScenarioDescription({
10
+ pickle,
11
+ gherkinScenarioMap
12
+ }) {
13
+ return pickle.astNodeIds.map(id => gherkinScenarioMap[id]).filter(x => x != null)[0].description;
14
+ }
15
+ function getStepKeyword({
16
+ pickleStep,
17
+ gherkinStepMap
18
+ }) {
19
+ return pickleStep.astNodeIds.map(id => gherkinStepMap[id]).filter(x => x != null)[0].keyword;
20
+ }
21
+ function getPickleStepMap(pickle) {
22
+ const result = {};
23
+ pickle.steps.forEach(pickleStep => result[pickleStep.id] = pickleStep);
24
+ return result;
25
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.durationToNanoseconds = durationToNanoseconds;
7
+ /**
8
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/helpers/duration_helpers.ts#L5
9
+ */
10
+ const NANOS_IN_SECOND = 1_000_000_000;
11
+ function durationToNanoseconds(duration) {
12
+ return Math.floor(duration.seconds * NANOS_IN_SECOND + duration.nanos);
13
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = getColorFns;
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ var _supportsColor = require("supports-color");
10
+ var _valueChecker = require("../valueChecker");
11
+ function getColorFns(stream, env, enabled) {
12
+ const support = detectSupport(stream, env, enabled);
13
+ if (support) {
14
+ const chalkInstance = new _chalk.default.Instance(support);
15
+ return {
16
+ forStatus(status) {
17
+ return {
18
+ AMBIGUOUS: chalkInstance.red.bind(_chalk.default),
19
+ FAILED: chalkInstance.red.bind(_chalk.default),
20
+ PASSED: chalkInstance.green.bind(_chalk.default),
21
+ PENDING: chalkInstance.yellow.bind(_chalk.default),
22
+ SKIPPED: chalkInstance.cyan.bind(_chalk.default),
23
+ UNDEFINED: chalkInstance.yellow.bind(_chalk.default),
24
+ UNKNOWN: chalkInstance.yellow.bind(_chalk.default)
25
+ }[status];
26
+ },
27
+ location: chalkInstance.gray.bind(_chalk.default),
28
+ tag: chalkInstance.cyan.bind(_chalk.default),
29
+ diffAdded: chalkInstance.green.bind(_chalk.default),
30
+ diffRemoved: chalkInstance.red.bind(_chalk.default),
31
+ errorMessage: chalkInstance.red.bind(_chalk.default),
32
+ errorStack: chalkInstance.grey.bind(_chalk.default)
33
+ };
34
+ } else {
35
+ return {
36
+ forStatus() {
37
+ return x => x;
38
+ },
39
+ location: x => x,
40
+ tag: x => x,
41
+ diffAdded: x => x,
42
+ diffRemoved: x => x,
43
+ errorMessage: x => x,
44
+ errorStack: x => x
45
+ };
46
+ }
47
+ }
48
+ function detectSupport(stream, env, enabled) {
49
+ const support = (0, _supportsColor.supportsColor)(stream);
50
+ // if we find FORCE_COLOR, we can let the supports-color library handle that
51
+ if ('FORCE_COLOR' in env || (0, _valueChecker.doesNotHaveValue)(enabled)) {
52
+ return support;
53
+ }
54
+ return enabled ? support || {
55
+ level: 1
56
+ } : false;
57
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // simplified Formatter class
8
+ class Formatter {
9
+ options;
10
+ static documentation;
11
+ constructor(options) {
12
+ this.options = options;
13
+ }
14
+ async finished() {}
15
+ }
16
+ exports.default = Formatter;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatLocation = formatLocation;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _valueChecker = require("../valueChecker");
10
+ function formatLocation(obj, cwd) {
11
+ let uri = obj.uri;
12
+ if ((0, _valueChecker.doesHaveValue)(cwd)) {
13
+ uri = _path.default.relative(cwd, uri);
14
+ }
15
+ return `${uri}:${obj.line.toString()}`;
16
+ }
@@ -3,37 +3,68 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.loadFeatures = loadFeatures;
7
- var _loadSources = require("./loadSources");
8
- var _exit = require("../utils/exit");
9
- async function loadFeatures(runConfiguration, environment) {
10
- const {
11
- filteredPickles,
12
- parseErrors
13
- } = await (0, _loadSources.loadSources)(runConfiguration.sources, environment);
14
- handleParseErrors(parseErrors);
15
- return groupByDocument(filteredPickles);
6
+ exports.FeaturesLoader = void 0;
7
+ var _gherkinStreams = require("@cucumber/gherkin-streams");
8
+ var _gherkinUtils = require("@cucumber/gherkin-utils");
9
+ /**
10
+ * Load features.
11
+ *
12
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
13
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts
14
+ */
15
+
16
+ class FeaturesLoader {
17
+ gherkinQuery = new _gherkinUtils.Query();
18
+ parseErrors = [];
19
+ /**
20
+ * Loads and parses feature files.
21
+ * - featurePaths should be absolute.
22
+ * See: https://github.com/cucumber/gherkin-streams/blob/main/src/GherkinStreams.ts#L36
23
+ * - if options.relativeTo is provided, uri in gherkin documents will be relative to it.
24
+ * See: https://github.com/cucumber/gherkin-streams/blob/main/src/SourceMessageStream.ts#L31
25
+ * - options.defaultDialect is 'en' by default.
26
+ * See: https://github.com/cucumber/gherkin-streams/blob/main/src/makeGherkinOptions.ts#L5
27
+ */
28
+ async load(featurePaths, options) {
29
+ this.gherkinQuery = new _gherkinUtils.Query();
30
+ this.parseErrors = [];
31
+ await gherkinFromPaths(featurePaths, options, envelope => {
32
+ this.gherkinQuery.update(envelope);
33
+ if (envelope.parseError) {
34
+ this.parseErrors.push(envelope.parseError);
35
+ }
36
+ });
37
+ }
38
+ getDocumentsCount() {
39
+ return this.gherkinQuery.getGherkinDocuments().length;
40
+ }
41
+ getDocumentsWithPickles() {
42
+ return this.gherkinQuery.getGherkinDocuments().map(gherkinDocument => {
43
+ const pickles = this.getDocumentPickles(gherkinDocument);
44
+ return {
45
+ ...gherkinDocument,
46
+ pickles
47
+ };
48
+ });
49
+ }
50
+ getDocumentPickles(gherkinDocument) {
51
+ return this.gherkinQuery.getPickles().filter(pickle => gherkinDocument.uri === pickle.uri).map(pickle => this.getPickleWithLocation(pickle));
52
+ }
53
+ getPickleWithLocation(pickle) {
54
+ const lastAstNodeId = pickle.astNodeIds[pickle.astNodeIds.length - 1];
55
+ const location = this.gherkinQuery.getLocation(lastAstNodeId);
56
+ return {
57
+ ...pickle,
58
+ location
59
+ };
60
+ }
16
61
  }
17
- function groupByDocument(filteredPickles) {
18
- const features = new Map();
19
- filteredPickles.forEach(({
20
- pickle,
21
- gherkinDocument
22
- }) => {
23
- let pickles = features.get(gherkinDocument);
24
- if (!pickles) {
25
- pickles = [];
26
- features.set(gherkinDocument, pickles);
27
- }
28
- pickles.push(pickle);
62
+ exports.FeaturesLoader = FeaturesLoader;
63
+ async function gherkinFromPaths(paths, options, onEnvelope) {
64
+ return new Promise((resolve, reject) => {
65
+ const gherkinMessageStream = _gherkinStreams.GherkinStreams.fromPaths(paths, options);
66
+ gherkinMessageStream.on('data', onEnvelope);
67
+ gherkinMessageStream.on('end', resolve);
68
+ gherkinMessageStream.on('error', reject);
29
69
  });
30
- return features;
31
- }
32
- function handleParseErrors(parseErrors) {
33
- if (parseErrors.length) {
34
- const message = parseErrors.map(parseError => {
35
- return `Parse error in "${parseError.source.uri}" ${parseError.message}`;
36
- }).join('\n');
37
- (0, _exit.exit)(message);
38
- }
39
70
  }
@@ -21,6 +21,13 @@ async function loadSteps(runConfiguration, environment = {}) {
21
21
  }
22
22
  return lib;
23
23
  }
24
+ /**
25
+ * Finds step definition by step text.
26
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/runtime/assemble_test_cases.ts#L103
27
+ *
28
+ * Handling case when several step definitions found:
29
+ * https://github.com/cucumber/cucumber-js/blob/main/src/runtime/test_case_runner.ts#L313
30
+ */
24
31
  function findStepDefinition(supportCodeLibrary, stepText, file) {
25
32
  const matchedSteps = supportCodeLibrary.stepDefinitions.filter(step => {
26
33
  return step.matchesStepName(stepText);
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.resovleFeaturePaths = resovleFeaturePaths;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _environment = require("@cucumber/cucumber/lib/api/environment");
11
+ var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
12
+ var _utils = require("../utils");
13
+ /**
14
+ * Representation of https://github.com/cucumber/cucumber-js/blob/main/src/paths/paths.ts
15
+ * Since Cucumber 10.1 resolvePaths was moved from lib/api/paths to lib/paths/paths.
16
+ * This module makes resolvePaths working with any version of Cucumber.
17
+ * See: https://github.com/cucumber/cucumber-js/pull/2361/files
18
+ *
19
+ * todo: replace with own paths resolution.
20
+ */
21
+
22
+ /**
23
+ * Returns list of absolute feature paths.
24
+ */
25
+ // eslint-disable-next-line max-statements
26
+ async function resovleFeaturePaths(runConfiguration, environment = {}) {
27
+ const {
28
+ cwd,
29
+ stderr,
30
+ debug
31
+ } = (0, _environment.mergeEnvironment)(environment);
32
+ const logger = new _console_logger.ConsoleLogger(stderr, debug);
33
+ const cucumberRoot = (0, _utils.resolvePackageRoot)('@cucumber/cucumber');
34
+ const pathsModuleBefore10_1 = _path.default.join(cucumberRoot, 'lib/api/paths.js');
35
+ const pathsModuleAfter10_1 = _path.default.join(cucumberRoot, 'lib/paths/paths.js');
36
+ const isNewResolvePaths = _fs.default.existsSync(pathsModuleAfter10_1);
37
+ if (isNewResolvePaths) {
38
+ const {
39
+ resolvePaths
40
+ } = require(pathsModuleAfter10_1);
41
+ const {
42
+ sourcePaths,
43
+ unexpandedSourcePaths
44
+ } = await resolvePaths(logger, cwd, runConfiguration.sources);
45
+ return {
46
+ featurePaths: sourcePaths,
47
+ unexpandedFeaturePaths: unexpandedSourcePaths
48
+ };
49
+ } else {
50
+ const {
51
+ resolvePaths
52
+ } = require(pathsModuleBefore10_1);
53
+ const {
54
+ featurePaths,
55
+ unexpandedFeaturePaths
56
+ } = await resolvePaths(logger, cwd, runConfiguration.sources);
57
+ return {
58
+ featurePaths,
59
+ unexpandedFeaturePaths
60
+ };
61
+ }
62
+ }