@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,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.GherkinDocuments = void 0;
7
- var _AutofillMap = require("../../../utils/AutofillMap");
8
- var _loadFeatures = require("../../../cucumber/loadFeatures");
9
- var _configDir = require("../../../config/configDir");
10
- var _GherkinDocumentClone = require("./GherkinDocumentClone");
11
- var _GherkinDocument = require("./GherkinDocument");
12
- var _Projects = require("./Projects");
13
- var _env = require("../../../config/env");
14
- var _lang = require("../../../config/lang");
15
- class GherkinDocuments {
16
- featuresLoader = new _loadFeatures.FeaturesLoader();
17
- projectsPerFeaturePath = new _AutofillMap.AutofillMap();
18
- gherkinDocumentsPerProject = new _AutofillMap.AutofillMap();
19
- constructor() {}
20
- async load(testCaseRuns) {
21
- this.fillProjectsPerFeaturePath(testCaseRuns);
22
- const cwd = (0, _configDir.getPlaywrightConfigDir)();
23
- const featurePaths = [...this.projectsPerFeaturePath.keys()];
24
- await this.featuresLoader.load(featurePaths, {
25
- relativeTo: cwd,
26
- defaultDialect: this.getFeaturesLang()
27
- });
28
- this.fillGherkinDocumentsPerProject();
29
- }
30
- getDocumentsForProject(projectInfo) {
31
- const docs = this.gherkinDocumentsPerProject.get(projectInfo);
32
- if (!docs) {
33
- throw new Error(`No gherkin docs for project ${projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectName}`);
34
- }
35
- return docs;
36
- }
37
- buildMessages() {
38
- const sources = [];
39
- const gherkinDocuments = [];
40
- this.gherkinDocumentsPerProject.forEach((docs, project) => {
41
- docs.forEach(doc => {
42
- sources.push(this.buildSourceMessage(project, doc));
43
- gherkinDocuments.push(new _GherkinDocument.GherkinDocumentMessage(project, doc).build());
44
- });
45
- });
46
- return {
47
- sources,
48
- gherkinDocuments
49
- };
50
- }
51
- fillProjectsPerFeaturePath(testCaseRuns) {
52
- testCaseRuns.forEach(testCaseRun => {
53
- const projects = this.projectsPerFeaturePath.getOrCreate(testCaseRun.bddData.uri, () => new Set());
54
- projects.add(testCaseRun.projectInfo);
55
- });
56
- }
57
- fillGherkinDocumentsPerProject() {
58
- this.featuresLoader.getDocumentsWithPickles().forEach(gherkinDocument => {
59
- if (!gherkinDocument.uri) {
60
- throw new Error(`Feature without uri`);
61
- }
62
- const projects = this.projectsPerFeaturePath.get(gherkinDocument.uri);
63
- if (!projects) {
64
- throw new Error(`Feature without projects: ${gherkinDocument.uri}`);
65
- }
66
- projects.forEach(project => {
67
- this.addGherkinDocumentToProject(project, gherkinDocument);
68
- });
69
- });
70
- }
71
- addGherkinDocumentToProject(projectInfo, gherkinDocument) {
72
- const projectDocs = this.gherkinDocumentsPerProject.getOrCreate(projectInfo, () => []);
73
- const clonedDocument = new _GherkinDocumentClone.GherkinDocumentClone(gherkinDocument).getClone();
74
- projectDocs.push(clonedDocument);
75
- }
76
- buildSourceMessage(projectInfo, doc) {
77
- if (!doc.uri) {
78
- throw new Error(`Doc without uri`);
79
- }
80
- const originalSource = this.featuresLoader.gherkinQuery.getSource(doc.uri);
81
- if (!originalSource) {
82
- throw new Error(`No source`);
83
- }
84
- const source = {
85
- ...originalSource,
86
- uri: (0, _Projects.getFeatureUriWithProject)(projectInfo, doc.uri)
87
- };
88
- return {
89
- source
90
- };
91
- }
92
- getFeaturesLang() {
93
- const langsSet = new Set();
94
- const envConfigs = (0, _env.getEnvConfigs)();
95
- Object.values(envConfigs).forEach(config => {
96
- langsSet.add(config.language || _lang.LANG_EN);
97
- });
98
- const langs = [...langsSet];
99
- if (langs.length > 1) {
100
- throw new Error([`Multi-language features are not supported yet.`, `Detected languages: ${langs.join(', ')}`].join(' '));
101
- }
102
- return langs[0];
103
- }
104
- }
105
- exports.GherkinDocuments = GherkinDocuments;
@@ -1,70 +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.Hook = void 0;
8
- var _crypto = require("crypto");
9
- var _configDir = require("../../../config/configDir");
10
- var _path = _interopRequireDefault(require("path"));
11
- /**
12
- * Hook that can be used in different test cases.
13
- * Builds Cucumber's hook message.
14
- */
15
-
16
- class Hook {
17
- internalId;
18
- static getInternalId(pwStep) {
19
- const {
20
- file,
21
- line,
22
- column
23
- } = pwStep.location || {};
24
- return [pwStep.category, ...pwStep.titlePath(), file, line, column].join('|');
25
- }
26
- id;
27
- name;
28
- sourceReference;
29
- constructor(internalId, /* one of pwSteps for this hook */
30
- pwStep) {
31
- this.internalId = internalId;
32
- this.id = (0, _crypto.randomUUID)();
33
- this.name = this.getName(pwStep);
34
- this.sourceReference = this.getSourceReference(pwStep);
35
- }
36
- buildMessage() {
37
- const hook = {
38
- id: this.id,
39
- name: this.name,
40
- sourceReference: this.sourceReference
41
- };
42
- return {
43
- hook
44
- };
45
- }
46
- getName(pwStep) {
47
- // These fixture names are for anonymous hooks
48
- // created with Before() / After() functions.
49
- // Keep name empty for them to be consistent with Cucumber.
50
- // const bddSystemFixtures = ['fixture: $before', 'fixture: $after'];
51
- // if (!pwStep.title || bddSystemFixtures.includes(pwStep.title)) return undefined;
52
- return pwStep.title;
53
- }
54
- getSourceReference(pwStep) {
55
- const {
56
- file,
57
- line,
58
- column
59
- } = pwStep.location || {};
60
- const uri = file ? _path.default.relative((0, _configDir.getPlaywrightConfigDir)(), file) : undefined;
61
- return {
62
- uri,
63
- location: line ? {
64
- line,
65
- column
66
- } : undefined
67
- };
68
- }
69
- }
70
- exports.Hook = Hook;
@@ -1,45 +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.Meta = void 0;
8
- var _os = _interopRequireDefault(require("os"));
9
- var messages = _interopRequireWildcard(require("@cucumber/messages"));
10
- var _utils = require("../../../utils");
11
- 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); }
12
- 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; }
13
- /**
14
- * Builds meta message.
15
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/helpers.ts#L100
16
- */
17
-
18
- class Meta {
19
- buildMessage() {
20
- const playwrightBddVersion = (0, _utils.getPackageVersion)('playwright-bdd');
21
- const playwrightVersion = (0, _utils.getPackageVersion)('@playwright/test');
22
- const meta = {
23
- protocolVersion: messages.version,
24
- implementation: {
25
- version: `${playwrightBddVersion} (playwright ${playwrightVersion})`,
26
- name: 'playwright-bdd'
27
- },
28
- cpu: {
29
- name: _os.default.arch()
30
- },
31
- os: {
32
- name: _os.default.platform(),
33
- version: _os.default.release()
34
- },
35
- runtime: {
36
- name: 'node.js',
37
- version: process.versions.node
38
- }
39
- };
40
- return {
41
- meta
42
- };
43
- }
44
- }
45
- exports.Meta = Meta;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Pickles = void 0;
7
- var _utils = require("../../../utils");
8
- var _Projects = require("./Projects");
9
- class Pickles {
10
- buildMessages(testCases) {
11
- const messages = [];
12
- testCases.forEach(testCase => {
13
- messages.push(this.buildPickleMessage(testCase));
14
- });
15
- return messages;
16
- }
17
- buildPickleMessage(testCase) {
18
- const pickle = {
19
- ...(0, _utils.omit)(testCase.pickle, 'location'),
20
- uri: (0, _Projects.getFeatureUriWithProject)(testCase.projectInfo, testCase.pickle.uri)
21
- };
22
- return {
23
- pickle
24
- };
25
- }
26
- }
27
- exports.Pickles = Pickles;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TITLE_SEPARATOR = void 0;
7
- exports.getFeatureNameWithProject = getFeatureNameWithProject;
8
- exports.getFeatureUriWithProject = getFeatureUriWithProject;
9
- exports.getProjectInfo = getProjectInfo;
10
- var _AutofillMap = require("../../../utils/AutofillMap");
11
- // title separator used in Playwright
12
- const TITLE_SEPARATOR = exports.TITLE_SEPARATOR = ' › ';
13
- const projectsMap = new _AutofillMap.AutofillMap();
14
- function getProjectInfo(test) {
15
- const project = test.parent.project();
16
- const projectId = project === null || project === void 0 ? void 0 : project.name;
17
- return projectsMap.getOrCreate(projectId, () => {
18
- return {
19
- projectName: project === null || project === void 0 ? void 0 : project.name,
20
- // browserName will be empty if not defined in project
21
- // todo: get browser info from bddData
22
- browserName: (project === null || project === void 0 ? void 0 : project.use.browserName) || (project === null || project === void 0 ? void 0 : project.use.defaultBrowserType)
23
- };
24
- });
25
- }
26
- /**
27
- * Returns URI prepended with project name.
28
- * It allows to separate PW projects runs of the same feature file.
29
- *
30
- * Now result should not contain spaces as Cucumber HTML report uses it as uuid.
31
- * See: https://github.com/cucumber/react-components/issues/344
32
- */
33
- function getFeatureUriWithProject(projectInfo, uri) {
34
- return projectInfo !== null && projectInfo !== void 0 && projectInfo.projectName && uri ? `[${projectInfo.projectName}]:${uri}` : uri;
35
- }
36
- function getFeatureNameWithProject(projectName, featureName) {
37
- return projectName ? `${projectName}${TITLE_SEPARATOR}${featureName}` : featureName;
38
- }
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TestCase = void 0;
7
- var _utils = require("../../../utils");
8
- class TestCase {
9
- id;
10
- gherkinDocuments;
11
- #pickle;
12
- #projectInfo;
13
- beforeHooks = new Map();
14
- afterHooks = new Map();
15
- mainSteps = [];
16
- constructor(id, gherkinDocuments) {
17
- this.id = id;
18
- this.gherkinDocuments = gherkinDocuments;
19
- }
20
- get projectInfo() {
21
- if (!this.#projectInfo) {
22
- throw new Error(`Empty projectInfo for testCase: ${this.id}`);
23
- }
24
- return this.#projectInfo;
25
- }
26
- get pickle() {
27
- if (!this.#pickle) {
28
- throw new Error(`Empty pickle for testCase: ${this.id}`);
29
- }
30
- return this.#pickle;
31
- }
32
- addRun(testCaseRun) {
33
- if (!this.#projectInfo) {
34
- this.#projectInfo = testCaseRun.projectInfo;
35
- }
36
- this.addHooks(testCaseRun, 'before');
37
- this.addHooks(testCaseRun, 'after');
38
- if (!this.#pickle) {
39
- this.#pickle = this.findPickle(testCaseRun.bddData);
40
- this.addStepsFromPickle(this.#pickle);
41
- }
42
- this.addStepsArgumentsLists(testCaseRun);
43
- }
44
- getHooks(hookType) {
45
- return hookType == 'before' ? this.beforeHooks : this.afterHooks;
46
- }
47
- getMainSteps() {
48
- return this.mainSteps;
49
- }
50
- buildMessage() {
51
- const testSteps = [...Array.from(this.beforeHooks.values()).map(hook => hook.testStep), ...(this.mainSteps || []), ...Array.from(this.afterHooks.values()).map(hook => hook.testStep)];
52
- const testCase = {
53
- id: this.id,
54
- pickleId: this.pickle.id,
55
- testSteps
56
- };
57
- return {
58
- testCase
59
- };
60
- }
61
- /**
62
- * We collect hooks from all runs of this test case, avoiding duplicates.
63
- */
64
- addHooks(testCaseRun, hookType) {
65
- const testCaseHooks = hookType === 'before' ? this.beforeHooks : this.afterHooks;
66
- const testRunHooks = testCaseRun.getExecutedHooks(hookType);
67
- testRunHooks.forEach(({
68
- hook
69
- }) => {
70
- if (testCaseHooks.has(hook.internalId)) {
71
- return;
72
- }
73
- const testStep = {
74
- id: `${this.id}-${hookType}-${testCaseHooks.size}`,
75
- hookId: hook.id
76
- };
77
- testCaseHooks.set(hook.internalId, {
78
- hook,
79
- testStep
80
- });
81
- });
82
- }
83
- /**
84
- * Initially create steps from pickle steps, with empty stepMatchArgumentsLists.
85
- */
86
- addStepsFromPickle(pickle) {
87
- this.mainSteps = pickle.steps.map((pickleStep, stepIndex) => {
88
- return {
89
- id: `${this.id}-step-${stepIndex}`,
90
- pickleStepId: pickleStep.id,
91
- stepDefinitionIds: [],
92
- stepMatchArgumentsLists: []
93
- };
94
- });
95
- }
96
- /**
97
- * Fill stepMatchArgumentsLists from all test runs.
98
- * It allows to fill as many steps as possible.
99
- * Possibly, we write the same stepMatchArgumentsLists several times,
100
- * looks like it's not a problem as they should be equal for all runs.
101
- */
102
- addStepsArgumentsLists(testCaseRun) {
103
- testCaseRun.bddData.steps.forEach((bddDataStep, stepIndex) => {
104
- var _this$mainSteps;
105
- const testCaseStep = (_this$mainSteps = this.mainSteps) === null || _this$mainSteps === void 0 ? void 0 : _this$mainSteps[stepIndex];
106
- if (testCaseStep && bddDataStep.stepMatchArgumentsLists) {
107
- testCaseStep.stepMatchArgumentsLists = bddDataStep.stepMatchArgumentsLists;
108
- }
109
- });
110
- }
111
- findPickle({
112
- uri,
113
- pickleLocation
114
- }) {
115
- const doc = this.gherkinDocuments.find(doc => doc.uri === uri);
116
- if (!doc) {
117
- throw new Error('GherkinDocument not found');
118
- }
119
- const pickle = doc.pickles.find(pickle => {
120
- return (0, _utils.stringifyLocation)(pickle.location) === pickleLocation;
121
- });
122
- if (!pickle) {
123
- throw new Error('Pickle not found');
124
- }
125
- return pickle;
126
- }
127
- }
128
- exports.TestCase = TestCase;
@@ -1,154 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TestCaseRun = void 0;
7
- var _utils = require("../../../utils");
8
- var _TestStepRun = require("./TestStepRun");
9
- var _timing = require("./timing");
10
- var _pwStepUtils = require("./pwStepUtils");
11
- var _AttachmentMapper = require("./AttachmentMapper");
12
- var _TestCaseRunHooks = require("./TestCaseRunHooks");
13
- var _Projects = require("./Projects");
14
- var _bddData = require("../../../run/bddData");
15
- class TestCaseRun {
16
- test;
17
- result;
18
- hooks;
19
- id;
20
- bddData;
21
- testCase;
22
- attachmentMapper;
23
- projectInfo;
24
- // collect steps with error and show only these errors in report.
25
- // it allows to not show the same error on parent steps
26
- errorSteps = new Set();
27
- timeoutedStep;
28
- executedBeforeHooks;
29
- executedAfterHooks;
30
- executedSteps;
31
- // eslint-disable-next-line max-params
32
- constructor(test, result, hooks) {
33
- this.test = test;
34
- this.result = result;
35
- this.hooks = hooks;
36
- this.id = this.generateTestRunId();
37
- this.bddData = this.extractBddData();
38
- this.projectInfo = (0, _Projects.getProjectInfo)(this.test);
39
- this.attachmentMapper = new _AttachmentMapper.AttachmentMapper(this.result);
40
- this.executedSteps = this.fillExecutedSteps();
41
- this.executedBeforeHooks = this.fillExecutedHooks('before');
42
- this.executedAfterHooks = this.fillExecutedHooks('after');
43
- }
44
- getTestCase() {
45
- if (!this.testCase) {
46
- throw new Error(`TestCase is not set.`);
47
- }
48
- return this.testCase;
49
- }
50
- isTimeouted() {
51
- return this.result.status === 'timedOut';
52
- }
53
- generateTestRunId() {
54
- return `${this.test.id}-attempt-${this.result.retry}`;
55
- }
56
- extractBddData() {
57
- const {
58
- bddData,
59
- annotationIndex
60
- } = (0, _bddData.getBddDataFromTest)(this.test);
61
- if (!bddData) {
62
- throw new Error(`__bddData annotation is not found for test "${this.test.title}".`);
63
- }
64
- // remove __bddData annotation from test (mutate)
65
- this.test.annotations.splice(annotationIndex, 1);
66
- return bddData;
67
- }
68
- fillExecutedSteps() {
69
- const possiblePwSteps = this.getPossiblePlaywrightBddSteps();
70
- return this.bddData.steps.map(bddDataStep => {
71
- const pwStep = this.findPlaywrightStep(possiblePwSteps, bddDataStep);
72
- this.registerErrorStep(pwStep);
73
- this.registerTimeoutedStep(pwStep);
74
- return {
75
- bddDataStep,
76
- pwStep
77
- };
78
- });
79
- }
80
- fillExecutedHooks(hookType) {
81
- return new _TestCaseRunHooks.TestCaseRunHooks(this, hookType).fill(this.executedSteps);
82
- }
83
- registerErrorStep(pwStep) {
84
- if (pwStep !== null && pwStep !== void 0 && pwStep.error) {
85
- this.errorSteps.add(pwStep);
86
- }
87
- }
88
- // eslint-disable-next-line complexity
89
- registerTimeoutedStep(pwStep) {
90
- if (!pwStep || !this.isTimeouted() || this.timeoutedStep) {
91
- return;
92
- }
93
- const {
94
- error
95
- } = pwStep;
96
- if ((0, _pwStepUtils.isUnknownDuration)(pwStep) || this.result.errors.some(e => e.message === (error === null || error === void 0 ? void 0 : error.message))) {
97
- this.timeoutedStep = pwStep;
98
- }
99
- }
100
- buildMessages() {
101
- return [this.buildTestCaseStarted(), ...this.executedBeforeHooks.buildMessages(), ...this.buildStepRuns(), ...this.executedAfterHooks.buildMessages(), this.buildTestCaseFinished()];
102
- }
103
- getExecutedHooks(hookType) {
104
- return hookType === 'before' ? this.executedBeforeHooks.executedHooks : this.executedAfterHooks.executedHooks;
105
- }
106
- buildTestCaseStarted() {
107
- const testCaseStarted = {
108
- id: this.id,
109
- attempt: this.result.retry,
110
- testCaseId: this.getTestCase().id,
111
- // workerId: 'worker-1'
112
- timestamp: (0, _timing.toCucumberTimestamp)(this.result.startTime.getTime())
113
- };
114
- return {
115
- testCaseStarted
116
- };
117
- }
118
- buildStepRuns() {
119
- return this.getTestCase().getMainSteps().reduce((messages, testStep, stepIndex) => {
120
- const {
121
- pwStep
122
- } = this.executedSteps[stepIndex] || {};
123
- const testStepRun = new _TestStepRun.TestStepRun(this, testStep, pwStep);
124
- return messages.concat(testStepRun.buildMessages());
125
- }, []);
126
- }
127
- buildTestCaseFinished() {
128
- const {
129
- startTime,
130
- duration
131
- } = this.result;
132
- const testCaseFinished = {
133
- testCaseStartedId: this.id,
134
- willBeRetried: Boolean(this.result.error && this.result.retry < this.test.retries),
135
- timestamp: (0, _timing.toCucumberTimestamp)(startTime.getTime() + duration)
136
- };
137
- return {
138
- testCaseFinished
139
- };
140
- }
141
- findPlaywrightStep(possiblePwSteps, bddDataStep) {
142
- return possiblePwSteps.find(pwStep => {
143
- return pwStep.location && (0, _utils.stringifyLocation)(pwStep.location) === bddDataStep.pwStepLocation;
144
- });
145
- }
146
- getPossiblePlaywrightBddSteps() {
147
- // Before we collected only top-level steps and steps from before hooks (as they are background)
148
- // But it's more reliable to just collect all test.step items b/c some Playwright versions
149
- // move steps to fixtures (see: https://github.com/microsoft/playwright/issues/30075)
150
- // Collecting all test.step items should be ok, as later we anyway map them by location.
151
- return (0, _pwStepUtils.collectStepsWithCategory)(this.result, 'test.step');
152
- }
153
- }
154
- exports.TestCaseRun = TestCaseRun;
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TestCaseRunHooks = void 0;
7
- var _Hook = require("./Hook");
8
- var _pwStepUtils = require("./pwStepUtils");
9
- var _TestStepRun = require("./TestStepRun");
10
- class TestCaseRunHooks {
11
- testCaseRun;
12
- hookType;
13
- rootPwStep;
14
- candidateSteps = [];
15
- hookSteps = new Set();
16
- executedHooks = new Map();
17
- constructor(testCaseRun, hookType) {
18
- this.testCaseRun = testCaseRun;
19
- this.hookType = hookType;
20
- }
21
- fill(mainSteps) {
22
- this.setRootStep();
23
- this.setCandidateSteps();
24
- this.addStepsWithName();
25
- this.addStepWithError();
26
- this.addStepWithTimeout();
27
- this.addStepsWithAttachment();
28
- this.excludeMainSteps(mainSteps);
29
- this.setExecutedHooks();
30
- return this;
31
- }
32
- buildMessages() {
33
- const messages = [];
34
- this.testCaseRun.getTestCase().getHooks(this.hookType).forEach(hookInfo => {
35
- const executedHook = this.executedHooks.get(hookInfo.hook.internalId);
36
- // todo: if pwStep is not found in this.executedBeforeHooks,
37
- // it means that this hook comes from another attempt of this test case.
38
- // We can stil try to find it in test result, as otherwise it will be marked as skipped,
39
- // but actually it was executed.
40
- const testStepRun = new _TestStepRun.TestStepRun(this.testCaseRun, hookInfo.testStep, executedHook === null || executedHook === void 0 ? void 0 : executedHook.pwStep);
41
- messages.push(...testStepRun.buildMessages());
42
- });
43
- return messages;
44
- }
45
- setRootStep() {
46
- this.rootPwStep = (0, _pwStepUtils.getHooksRootPwStep)(this.testCaseRun.result, this.hookType);
47
- }
48
- setCandidateSteps() {
49
- if (this.rootPwStep) {
50
- this.candidateSteps.push(this.rootPwStep);
51
- }
52
- this.candidateSteps.push(...(0, _pwStepUtils.collectStepsDfs)(this.rootPwStep));
53
- }
54
- addStepsWithName() {
55
- this.candidateSteps.forEach(pwStep => {
56
- if (pwStep.category === 'test.step' && pwStep.title) {
57
- this.hookSteps.add(pwStep);
58
- }
59
- });
60
- }
61
- addStepsWithAttachment() {
62
- const {
63
- attachmentMapper
64
- } = this.testCaseRun;
65
- this.candidateSteps.forEach(pwStep => {
66
- if (attachmentMapper.getStepAttachments(pwStep).length > 0) {
67
- this.hookSteps.add(pwStep);
68
- }
69
- });
70
- }
71
- addStepWithError() {
72
- const stepWithError = (0, _pwStepUtils.findDeepestStepWithError)(this.rootPwStep);
73
- if (stepWithError) {
74
- this.hookSteps.add(stepWithError);
75
- // in Playwright error is inherited by all parent steps,
76
- // but we want to show it once (in the deepest step)
77
- this.testCaseRun.registerErrorStep(stepWithError);
78
- this.testCaseRun.registerTimeoutedStep(stepWithError);
79
- }
80
- }
81
- addStepWithTimeout() {
82
- if (!this.testCaseRun.isTimeouted()) {
83
- return;
84
- }
85
- if (this.testCaseRun.timeoutedStep) {
86
- return;
87
- }
88
- const timeoutedStep = this.hookType === 'before' ?
89
- // Timeouted steps have duration = -1 in PW <= 1.39 and no error field.
90
- // In PW > 1.39 timeouted steps have '.error' populated
91
- (0, _pwStepUtils.findDeepestStepWithUnknownDuration)(this.rootPwStep) :
92
- // Timeouted after hooks don't have duration = -1,
93
- // so there is no way to find which exactly fixture timed out.
94
- // We mark root 'After Hooks' step as timeouted.
95
- this.rootPwStep;
96
- if (timeoutedStep) {
97
- this.hookSteps.add(timeoutedStep);
98
- this.testCaseRun.timeoutedStep = timeoutedStep;
99
- }
100
- }
101
- excludeMainSteps(mainSteps) {
102
- // - exclude background steps, b/c they are in pickle and should not in hooks.
103
- // - exclude other test.step items that are bdd steps and should not be in hooks.
104
- // Important to run this fn after this.fillExecutedSteps()
105
- // as we assume steps are already populated
106
- mainSteps.forEach(stepInfo => {
107
- if (stepInfo.pwStep) {
108
- this.hookSteps.delete(stepInfo.pwStep);
109
- }
110
- });
111
- }
112
- setExecutedHooks() {
113
- this.hookSteps.forEach(pwStep => {
114
- const internalId = _Hook.Hook.getInternalId(pwStep);
115
- const hook = this.testCaseRun.hooks.getOrCreate(internalId, () => new _Hook.Hook(internalId, pwStep));
116
- this.executedHooks.set(internalId, {
117
- hook,
118
- pwStep
119
- });
120
- });
121
- }
122
- }
123
- exports.TestCaseRunHooks = TestCaseRunHooks;