@zohodesk/testinglibrary 2.9.2 → 3.0.2

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 (122) hide show
  1. package/.gitlab-ci.yml +1 -1
  2. package/README.md +27 -1
  3. package/build/core/playwright/fixtures.js +24 -0
  4. package/build/core/playwright/index.js +10 -23
  5. package/build/core/playwright/setup/config-creator.js +3 -3
  6. package/build/core/playwright/setup/config-utils.js +8 -25
  7. package/build/core/playwright/test-runner.js +1 -1
  8. package/build/decorators.d.ts +1 -1
  9. package/build/decorators.js +1 -1
  10. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  11. package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
  12. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  13. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  14. package/build/setup-folder-structure/samples/settings.json +7 -0
  15. package/build/setup-folder-structure/setupProject.js +18 -5
  16. package/nobdd/uat/conf/nobdd/uat.config.js +1 -2
  17. package/nobdd/uat.config.js +1 -2
  18. package/package.json +7 -7
  19. package/build/bdd-framework/cli/commands/env.js +0 -42
  20. package/build/bdd-framework/cli/commands/export.js +0 -62
  21. package/build/bdd-framework/cli/commands/test.js +0 -64
  22. package/build/bdd-framework/cli/index.js +0 -11
  23. package/build/bdd-framework/cli/options.js +0 -19
  24. package/build/bdd-framework/cli/worker.js +0 -13
  25. package/build/bdd-framework/config/configDir.js +0 -35
  26. package/build/bdd-framework/config/enrichReporterData.js +0 -23
  27. package/build/bdd-framework/config/env.js +0 -50
  28. package/build/bdd-framework/config/index.js +0 -94
  29. package/build/bdd-framework/config/lang.js +0 -14
  30. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  31. package/build/bdd-framework/cucumber/createTestStep.js +0 -43
  32. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
  33. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
  34. package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
  35. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
  36. package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
  37. package/build/bdd-framework/cucumber/formatter/index.js +0 -16
  38. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
  39. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  40. package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
  41. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  42. package/build/bdd-framework/cucumber/loadSteps.js +0 -47
  43. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
  44. package/build/bdd-framework/cucumber/stepArguments.js +0 -21
  45. package/build/bdd-framework/cucumber/types.js +0 -5
  46. package/build/bdd-framework/cucumber/valueChecker.js +0 -23
  47. package/build/bdd-framework/decorators.js +0 -18
  48. package/build/bdd-framework/gen/fixtures.js +0 -48
  49. package/build/bdd-framework/gen/formatter.js +0 -167
  50. package/build/bdd-framework/gen/i18n.js +0 -39
  51. package/build/bdd-framework/gen/index.js +0 -197
  52. package/build/bdd-framework/gen/specialTags.js +0 -70
  53. package/build/bdd-framework/gen/testFile.js +0 -470
  54. package/build/bdd-framework/gen/testMeta.js +0 -60
  55. package/build/bdd-framework/gen/testNode.js +0 -35
  56. package/build/bdd-framework/gen/testPoms.js +0 -133
  57. package/build/bdd-framework/hooks/scenario.js +0 -130
  58. package/build/bdd-framework/hooks/worker.js +0 -89
  59. package/build/bdd-framework/index.js +0 -52
  60. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
  61. package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
  62. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  63. package/build/bdd-framework/playwright/loadUtils.js +0 -33
  64. package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
  65. package/build/bdd-framework/playwright/transform.js +0 -88
  66. package/build/bdd-framework/playwright/types.js +0 -12
  67. package/build/bdd-framework/playwright/utils.js +0 -56
  68. package/build/bdd-framework/reporter/cucumber/base.js +0 -52
  69. package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
  70. package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
  71. package/build/bdd-framework/reporter/cucumber/html.js +0 -40
  72. package/build/bdd-framework/reporter/cucumber/index.js +0 -74
  73. package/build/bdd-framework/reporter/cucumber/json.js +0 -312
  74. package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
  75. package/build/bdd-framework/reporter/cucumber/message.js +0 -20
  76. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
  77. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
  78. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
  79. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
  80. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
  81. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
  82. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
  83. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
  84. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
  85. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
  86. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
  87. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
  88. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
  89. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
  90. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
  91. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
  92. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
  93. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
  94. package/build/bdd-framework/run/StepInvoker.js +0 -69
  95. package/build/bdd-framework/run/bddData/index.js +0 -59
  96. package/build/bdd-framework/run/bddData/types.js +0 -5
  97. package/build/bdd-framework/run/bddFixtures.js +0 -192
  98. package/build/bdd-framework/run/bddWorld.js +0 -79
  99. package/build/bdd-framework/run/bddWorldInternal.js +0 -11
  100. package/build/bdd-framework/snippets/index.js +0 -132
  101. package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
  102. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  103. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  104. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
  105. package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
  106. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
  107. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
  108. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  109. package/build/bdd-framework/steps/createBdd.js +0 -78
  110. package/build/bdd-framework/steps/decorators/class.js +0 -68
  111. package/build/bdd-framework/steps/decorators/steps.js +0 -98
  112. package/build/bdd-framework/steps/defineStep.js +0 -62
  113. package/build/bdd-framework/steps/stepConfig.js +0 -24
  114. package/build/bdd-framework/utils/AutofillMap.js +0 -20
  115. package/build/bdd-framework/utils/exit.js +0 -62
  116. package/build/bdd-framework/utils/index.js +0 -93
  117. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  118. package/build/bdd-framework/utils/logger.js +0 -30
  119. package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
  120. package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
  121. package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
  122. package/npm-shrinkwrap.json +0 -6475
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.configOption = void 0;
7
- exports.getCliConfigPath = getCliConfigPath;
8
- var _commander = require("commander");
9
- /**
10
- * Config option moved to separate file as it used in test run.
11
- */
12
-
13
- const configOption = exports.configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
14
- /**
15
- * Helper used in test run to detect config location.
16
- */
17
- function getCliConfigPath() {
18
- return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
19
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- var _worker_threads = require("worker_threads");
4
- var _gen = require("../gen");
5
- /**
6
- * Worker to generate test files with fresh require/import cache
7
- * See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
8
- */
9
-
10
- async function main() {
11
- await new _gen.TestFilesGenerator(_worker_threads.workerData.config).generate();
12
- }
13
- main();
@@ -1,35 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getConfigFromEnv = getConfigFromEnv;
8
- exports.getEnvConfigs = getEnvConfigs;
9
- exports.saveConfigToEnv = saveConfigToEnv;
10
- var _path = _interopRequireDefault(require("path"));
11
- var _exit = require("../utils/exit");
12
- /**
13
- * Storing configs in env var PLAYWRIGHT_BDD_CONFIGS as JSON-stringified values.
14
- * For passing configs to playwright workers and bddgen.
15
- */
16
-
17
- function saveConfigToEnv(config) {
18
- const envConfigs = getEnvConfigs();
19
- const existingConfig = envConfigs[config.outputDir];
20
- if (existingConfig) {
21
- // Playwright config can be evaluated several times.
22
- // Throw error only if different calls of defineBddConfig() use the same outputDir.
23
- // See: https://github.com/vitalets/playwright-bdd/issues/39#issuecomment-1653805368
24
- if (!isSameConfigs(config, existingConfig)) {
25
- (0, _exit.exit)(`When using several calls of defineBddConfig()`, `please manually provide different "outputDir" option.`);
26
- }
27
- return;
28
- }
29
- envConfigs[config.outputDir] = config;
30
- saveEnvConfigs(envConfigs);
31
- }
32
- function getConfigFromEnv(outputDir) {
33
- const envConfigs = getEnvConfigs();
34
- outputDir = _path.default.resolve(outputDir);
35
- const config = envConfigs[outputDir];
36
- if (!config) {
37
- // exit(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
38
- return {};
39
- }
40
- return config;
41
- }
42
- function getEnvConfigs() {
43
- return JSON.parse(process.env.PLAYWRIGHT_BDD_CONFIGS || '{}');
44
- }
45
- function saveEnvConfigs(envConfigs) {
46
- process.env.PLAYWRIGHT_BDD_CONFIGS = JSON.stringify(envConfigs);
47
- }
48
- function isSameConfigs(config1, config2) {
49
- return JSON.stringify(config1) === JSON.stringify(config2);
50
- }
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.defaults = void 0;
8
- exports.defineBddConfig = defineBddConfig;
9
- exports.extractCucumberConfig = extractCucumberConfig;
10
- var _path = _interopRequireDefault(require("path"));
11
- var _env = require("./env");
12
- var _configDir = require("./configDir");
13
- var _utils = require("../utils");
14
- /**
15
- * BDD Config.
16
- */
17
-
18
- const defaults = exports.defaults = {
19
- outputDir: '.features-gen',
20
- verbose: false,
21
- examplesTitleFormat: 'Example #<_index_>',
22
- publishQuiet: true,
23
- quotes: 'double'
24
- };
25
- function defineBddConfig(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);
31
- // In main process store config in env to be accessible by workers
32
- if (isMainProcess) {
33
- (0, _env.saveConfigToEnv)(config);
34
- }
35
- return config.outputDir;
36
- }
37
- function getConfig(configDir, inputConfig) {
38
- const config = Object.assign({}, defaults, inputConfig);
39
- const featuresRoot = config.featuresRoot ? _path.default.resolve(configDir, config.featuresRoot) : configDir;
40
- return {
41
- ...config,
42
- // important to resolve outputDir as it is used as unique key for input configs
43
- outputDir: _path.default.resolve(configDir, config.outputDir),
44
- importTestFrom: resolveImportTestFrom(configDir, config.importTestFrom),
45
- featuresRoot
46
- };
47
- }
48
- function extractCucumberConfig(config) {
49
- // todo: find more strict way to omit own config fields
50
- // see: https://bobbyhadz.com/blog/typescript-object-remove-property
51
- const omitProps = {
52
- outputDir: true,
53
- importTestFrom: true,
54
- verbose: true,
55
- skip: true,
56
- examplesTitleFormat: true,
57
- quotes: true,
58
- tags: true,
59
- featuresRoot: true,
60
- enrichReporterData: true
61
- };
62
- const keys = Object.keys(omitProps);
63
- const cucumberConfig = {
64
- ...config
65
- };
66
- keys.forEach(key => delete cucumberConfig[key]);
67
- stripPublishQuiet(cucumberConfig);
68
- return cucumberConfig;
69
- }
70
- function resolveImportTestFrom(configDir, importTestFrom) {
71
- if (importTestFrom) {
72
- const {
73
- file,
74
- varName
75
- } = typeof importTestFrom === 'string' ? {
76
- file: importTestFrom
77
- } : importTestFrom;
78
- return {
79
- file: _path.default.resolve(configDir, file),
80
- varName
81
- };
82
- }
83
- }
84
- function stripPublishQuiet(cucumberConfig) {
85
- const cucumberVersion = (0, _utils.getPackageVersion)('@cucumber/cucumber');
86
- // Playwright-bdd supports Cucumber from v9+
87
- // publishQuiet was deprecated in Cucumber 9.4.0.
88
- // See: https://github.com/cucumber/cucumber-js/pull/2311
89
- // Remove publishQuite from Cucumber config to hide deprecation warning.
90
- // See: https://github.com/vitalets/playwright-bdd/pull/47
91
- if (!/^9\.[0123]\./.test(cucumberVersion)) {
92
- delete cucumberConfig.publishQuiet;
93
- }
94
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.LANG_EN = void 0;
7
- exports.isEnglish = isEnglish;
8
- /**
9
- * Helpers for Cucumber language option.
10
- */
11
- const LANG_EN = exports.LANG_EN = 'en';
12
- function isEnglish(lang) {
13
- return !lang || lang === LANG_EN;
14
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.buildStepDefinition = buildStepDefinition;
8
- var _messages = require("@cucumber/messages");
9
- var _cucumberExpressions = require("@cucumber/cucumber-expressions");
10
- var _step_definition = _interopRequireDefault(require("@cucumber/cucumber/lib/models/step_definition"));
11
- /**
12
- * Extracted from cucumber SupportCodeLibraryBuilder.
13
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
14
- */
15
-
16
- const newId = _messages.IdGenerator.uuid();
17
- function buildStepDefinition({
18
- keyword,
19
- pattern,
20
- code,
21
- line,
22
- options,
23
- uri
24
- }, supportCodeLibrary) {
25
- // todo: handle error.undefinedParameterTypeName as it's done in cucumber?
26
- const expression = typeof pattern === 'string' ? new _cucumberExpressions.CucumberExpression(pattern, supportCodeLibrary.parameterTypeRegistry) : new _cucumberExpressions.RegularExpression(pattern, supportCodeLibrary.parameterTypeRegistry);
27
- // skip wrapping code as it is not needed for decorator steps
28
- // const wrappedCode = this.wrapCode({
29
- // code,
30
- // wrapperOptions: options.wrapperOptions,
31
- // })
32
- return new _step_definition.default({
33
- code,
34
- expression,
35
- id: newId(),
36
- line,
37
- options,
38
- keyword,
39
- pattern,
40
- unwrappedCode: code,
41
- uri
42
- });
43
- }
@@ -1,43 +0,0 @@
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
- }
@@ -1,126 +0,0 @@
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;
@@ -1,72 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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;
@@ -1,16 +0,0 @@
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
- }