@zohodesk/testinglibrary 0.0.4 → 0.0.5-exp.10

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 (88) hide show
  1. package/.babelrc +16 -0
  2. package/bin/cli.js +1 -1
  3. package/bin/postinstall.js +1 -16
  4. package/build/bdd-framework/cli/commands/env.js +44 -0
  5. package/build/bdd-framework/cli/commands/export.js +47 -0
  6. package/build/bdd-framework/cli/commands/test.js +60 -0
  7. package/build/bdd-framework/cli/index.js +11 -0
  8. package/build/bdd-framework/cli/options.js +21 -0
  9. package/build/bdd-framework/cli/worker.js +13 -0
  10. package/build/bdd-framework/config/dir.js +27 -0
  11. package/build/bdd-framework/config/env.js +49 -0
  12. package/build/bdd-framework/config/index.js +92 -0
  13. package/build/bdd-framework/cucumber/buildStepDefinition.js +45 -0
  14. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  15. package/build/bdd-framework/cucumber/loadConfig.js +17 -0
  16. package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
  17. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
  18. package/build/bdd-framework/cucumber/loadSources.js +58 -0
  19. package/build/bdd-framework/cucumber/loadSteps.js +41 -0
  20. package/build/bdd-framework/decorators.js +21 -0
  21. package/build/bdd-framework/gen/formatter.js +92 -0
  22. package/build/bdd-framework/gen/i18n.js +44 -0
  23. package/build/bdd-framework/gen/index.js +150 -0
  24. package/build/bdd-framework/gen/poms.js +47 -0
  25. package/build/bdd-framework/gen/testFile.js +356 -0
  26. package/build/bdd-framework/gen/testNode.js +50 -0
  27. package/build/bdd-framework/index.js +33 -0
  28. package/build/bdd-framework/playwright/fixtureParameterNames.js +103 -0
  29. package/build/bdd-framework/playwright/getLocationInFile.js +50 -0
  30. package/build/bdd-framework/playwright/loadConfig.js +42 -0
  31. package/build/bdd-framework/playwright/testTypeImpl.js +47 -0
  32. package/build/bdd-framework/playwright/transform.js +85 -0
  33. package/build/bdd-framework/playwright/utils.js +24 -0
  34. package/build/bdd-framework/run/bddFixtures.js +109 -0
  35. package/build/bdd-framework/run/bddWorld.js +91 -0
  36. package/build/bdd-framework/snippets/index.js +132 -0
  37. package/build/bdd-framework/snippets/snippetSyntax.js +50 -0
  38. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +32 -0
  39. package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
  40. package/build/bdd-framework/stepDefinitions/createBdd.js +52 -0
  41. package/build/bdd-framework/stepDefinitions/createDecorators.js +110 -0
  42. package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
  43. package/build/bdd-framework/utils/index.js +52 -0
  44. package/build/bdd-framework/utils/jsStringWrap.js +44 -0
  45. package/build/bdd-framework/utils/logger.js +21 -0
  46. package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
  47. package/{src → build}/core/jest/runner/jest-runner.js +16 -15
  48. package/build/core/jest/setup/index.js +9 -0
  49. package/build/core/playwright/codegen.js +56 -0
  50. package/build/core/playwright/custom-commands.js +8 -0
  51. package/build/core/playwright/env-initializer.js +21 -0
  52. package/{src → build}/core/playwright/index.js +51 -21
  53. package/build/core/playwright/readConfigFile.js +64 -0
  54. package/build/core/playwright/report-generator.js +43 -0
  55. package/build/core/playwright/setup/config-creator.js +106 -0
  56. package/build/core/playwright/test-runner.js +106 -0
  57. package/build/index.js +37 -0
  58. package/build/lib/cli.js +45 -0
  59. package/build/lib/post-install.js +17 -0
  60. package/build/lint/index.js +7 -0
  61. package/build/setup-folder-structure/env-config-sample.json +17 -0
  62. package/build/setup-folder-structure/git-ignore.sample.js +39 -0
  63. package/build/setup-folder-structure/setupProject.js +104 -0
  64. package/build/setup-folder-structure/uat-config-sample.js +31 -0
  65. package/build/setup-folder-structure/user-example.json +3 -0
  66. package/build/utils/cliArgsToObject.js +64 -0
  67. package/build/utils/getFilePath.js +11 -0
  68. package/build/utils/logger.js +56 -0
  69. package/build/utils/rootPath.js +46 -0
  70. package/changelog.md +27 -0
  71. package/npm-shrinkwrap.json +2097 -147
  72. package/package.json +20 -5
  73. package/playwright.config.js +6 -6
  74. package/src/core/jest/preprocessor/jsPreprocessor.js +0 -9
  75. package/src/core/jest/setup/index.js +0 -165
  76. package/src/core/playwright/codegen.js +0 -60
  77. package/src/core/playwright/custom-commands.js +0 -3
  78. package/src/core/playwright/env-initializer.js +0 -24
  79. package/src/core/playwright/readConfigFile.js +0 -30
  80. package/src/core/playwright/report-generator.js +0 -43
  81. package/src/core/playwright/setup/config-creator.js +0 -77
  82. package/src/core/playwright/test-runner.js +0 -64
  83. package/src/index.js +0 -9
  84. package/src/lib/cli.js +0 -35
  85. package/src/utils/cliArgsToObject.js +0 -35
  86. package/src/utils/getFilePath.js +0 -9
  87. package/src/utils/logger.js +0 -28
  88. package/src/utils/rootPath.js +0 -51
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TestFile = void 0;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _formatter = require("./formatter");
11
+ var _i18n = require("./i18n");
12
+ var _loadSteps = require("../cucumber/loadSteps");
13
+ var _createBdd = require("../stepDefinitions/createBdd");
14
+ var _index = require("@cucumber/cucumber/lib/formatter/helpers/index");
15
+ var _utils = require("../utils");
16
+ var _defineStep = require("../stepDefinitions/defineStep");
17
+ var _poms = require("./poms");
18
+ var _testNode = require("./testNode");
19
+ /**
20
+ * Generate test code.
21
+ */
22
+
23
+ /* eslint-disable max-lines, max-params */
24
+
25
+ class TestFile {
26
+ lines = [];
27
+ i18nKeywordsMap;
28
+ formatter;
29
+ testNodes = [];
30
+ hasCustomTest = false;
31
+ undefinedSteps = [];
32
+ constructor(options) {
33
+ this.options = options;
34
+ this.formatter = new _formatter.Formatter(options.config);
35
+ }
36
+ get sourceFile() {
37
+ const {
38
+ uri
39
+ } = this.options.doc;
40
+ if (!uri) throw new Error(`Document without uri`);
41
+ return uri;
42
+ }
43
+ get content() {
44
+ return this.lines.join('\n');
45
+ }
46
+ get language() {
47
+ var _this$options$doc$fea;
48
+ return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || 'en';
49
+ }
50
+ get config() {
51
+ return this.options.config;
52
+ }
53
+ get outputPath() {
54
+ return this.options.outputPath;
55
+ }
56
+ build() {
57
+ this.loadI18nKeywords();
58
+ this.lines = [...this.getFileHeader(),
59
+ // prettier-ignore
60
+ ...this.getRootSuite(), ...this.getFileFixtures()];
61
+ return this;
62
+ }
63
+ save() {
64
+ const dir = _path.default.dirname(this.outputPath);
65
+ if (!_fs.default.existsSync(dir)) _fs.default.mkdirSync(dir, {
66
+ recursive: true
67
+ });
68
+ _fs.default.writeFileSync(this.outputPath, this.content);
69
+ }
70
+ getFileHeader() {
71
+ const importTestFrom = this.getRelativeImportTestFrom();
72
+ return this.formatter.fileHeader(this.sourceFile, importTestFrom);
73
+ }
74
+ loadI18nKeywords() {
75
+ if (this.language !== 'en') {
76
+ this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
77
+ }
78
+ }
79
+ getRelativeImportTestFrom() {
80
+ const {
81
+ importTestFrom
82
+ } = this.config;
83
+ if (!importTestFrom) return;
84
+ const {
85
+ file,
86
+ varName
87
+ } = importTestFrom;
88
+ const dir = _path.default.dirname(this.outputPath);
89
+ return {
90
+ file: _path.default.relative(dir, file),
91
+ varName
92
+ };
93
+ }
94
+ getFileFixtures() {
95
+ return this.formatter.useFixtures([...this.formatter.testFixture(), ...this.formatter.tagsFixture(this.testNodes)]);
96
+ }
97
+ getRootSuite() {
98
+ const {
99
+ feature
100
+ } = this.options.doc;
101
+ if (!feature) throw new Error(`Document without feature.`);
102
+ return this.getSuite(feature);
103
+ }
104
+
105
+ /**
106
+ * Generate test.describe suite for root Feature or Rule
107
+ */
108
+ getSuite(feature, parent) {
109
+ const node = new _testNode.TestNode(feature, parent);
110
+ const lines = [];
111
+ feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
112
+ return this.formatter.suite(node, lines);
113
+ }
114
+ getSuiteChild(child, parent) {
115
+ if ('rule' in child && child.rule) return this.getSuite(child.rule, parent);
116
+ if (child.background) return this.getBeforeEach(child.background);
117
+ if (child.scenario) return this.getScenarioLines(child.scenario, parent);
118
+ throw new Error(`Empty child: ${JSON.stringify(child)}`);
119
+ }
120
+ getScenarioLines(scenario, parent) {
121
+ return isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
122
+ }
123
+
124
+ /**
125
+ * Generate test.beforeEach for Background
126
+ */
127
+ getBeforeEach(bg) {
128
+ const {
129
+ fixtures,
130
+ lines
131
+ } = this.getSteps(bg);
132
+ return this.formatter.beforeEach(fixtures, lines);
133
+ }
134
+
135
+ /**
136
+ * Generate test.describe suite for Scenario Outline
137
+ */
138
+ getOutlineSuite(scenario, parent) {
139
+ const node = new _testNode.TestNode(scenario, parent);
140
+ const lines = [];
141
+ let exampleIndex = 0;
142
+ scenario.examples.forEach(examples => {
143
+ const titleFormat = this.getExamplesTitleFormat(examples);
144
+ examples.tableBody.forEach(exampleRow => {
145
+ const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
146
+ const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
147
+ lines.push(...testLines);
148
+ });
149
+ });
150
+ return this.formatter.suite(node, lines);
151
+ }
152
+
153
+ /**
154
+ * Generate test from Examples row of Scenario Outline
155
+ */
156
+ // eslint-disable-next-line max-params
157
+ getOutlineTest(scenario, examples, exampleRow, title, parent) {
158
+ const node = new _testNode.TestNode({
159
+ name: title,
160
+ tags: examples.tags
161
+ }, parent);
162
+ if (this.skipByTagsExpression(node)) return [];
163
+ this.testNodes.push(node);
164
+ const {
165
+ fixtures,
166
+ lines
167
+ } = this.getSteps(scenario, node.ownTags, exampleRow.id);
168
+ return this.formatter.test(node, fixtures, lines);
169
+ }
170
+
171
+ /**
172
+ * Generate test from Scenario
173
+ */
174
+ getTest(scenario, parent) {
175
+ const node = new _testNode.TestNode(scenario, parent);
176
+ if (this.skipByTagsExpression(node)) return [];
177
+ this.testNodes.push(node);
178
+ const {
179
+ fixtures,
180
+ lines
181
+ } = this.getSteps(scenario, node.ownTags);
182
+ return this.formatter.test(node, fixtures, lines);
183
+ }
184
+
185
+ /**
186
+ * Generate test steps
187
+ */
188
+ getSteps(scenario, ownTestTags, outlineExampleRowId) {
189
+ const testFixtureNames = new Set();
190
+ const usedPoms = new _poms.POMS();
191
+ const decoratorSteps = [];
192
+ let previousKeywordType = undefined;
193
+ const lines = scenario.steps.map((step, index) => {
194
+ const {
195
+ keyword,
196
+ keywordType,
197
+ fixtureNames: stepFixtureNames,
198
+ line,
199
+ pickleStep,
200
+ stepConfig
201
+ } = this.getStep(step, previousKeywordType, outlineExampleRowId);
202
+ previousKeywordType = keywordType;
203
+ testFixtureNames.add(keyword);
204
+ stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
205
+ if (!line && stepConfig !== null && stepConfig !== void 0 && stepConfig.pomNode) {
206
+ usedPoms.add(stepConfig.pomNode);
207
+ decoratorSteps.push({
208
+ index,
209
+ keyword,
210
+ pickleStep,
211
+ pomNode: stepConfig.pomNode
212
+ });
213
+ }
214
+ return line;
215
+ });
216
+ if (decoratorSteps.length) {
217
+ testFixtureNames.forEach(fixtureName => usedPoms.addByFixtureName(fixtureName));
218
+ ownTestTags === null || ownTestTags === void 0 || ownTestTags.forEach(tag => usedPoms.addByTag(tag));
219
+ decoratorSteps.forEach(step => {
220
+ const {
221
+ line,
222
+ fixtureNames
223
+ } = this.getDecoratorStep(step, usedPoms);
224
+ lines[step.index] = line;
225
+ fixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
226
+ });
227
+ }
228
+ return {
229
+ fixtures: testFixtureNames,
230
+ lines
231
+ };
232
+ }
233
+
234
+ /**
235
+ * Generate step for Given, When, Then
236
+ */
237
+ // eslint-disable-next-line max-statements, complexity
238
+ getStep(step, previousKeywordType, outlineExampleRowId) {
239
+ const pickleStep = this.getPickleStep(step, outlineExampleRowId);
240
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
241
+ const keywordType = (0, _index.getStepKeywordType)({
242
+ keyword: step.keyword,
243
+ language: this.language,
244
+ previousKeywordType
245
+ });
246
+ let keyword = this.getStepKeyword(step);
247
+ if (!stepDefinition) {
248
+ this.undefinedSteps.push({
249
+ keywordType,
250
+ step,
251
+ pickleStep
252
+ });
253
+ return this.getMissingStep(keyword, keywordType, pickleStep);
254
+ }
255
+ // for cucumber-style stepConfig is undefined
256
+ const stepConfig = (0, _defineStep.getStepConfig)(stepDefinition);
257
+ if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) this.hasCustomTest = true;
258
+ // for cucumber-style transform Given/When/Then -> Given_/When_/Then_
259
+ // to use fixtures with own bddWorld (containing fixtures)
260
+ if (!(0, _defineStep.isPlaywrightStyle)(stepDefinition)) keyword = `${keyword}_`;
261
+ // for decorator steps fixtures defined later in second pass
262
+ const fixtureNames = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? [] : (0, _createBdd.extractFixtureNames)(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.fn);
263
+ const line = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? '' : this.formatter.step(keyword, pickleStep.text, pickleStep.argument, fixtureNames);
264
+ return {
265
+ keyword,
266
+ keywordType,
267
+ fixtureNames,
268
+ line,
269
+ pickleStep,
270
+ stepConfig
271
+ };
272
+ }
273
+ getMissingStep(keyword, keywordType, pickleStep) {
274
+ return {
275
+ keyword,
276
+ keywordType,
277
+ fixtureNames: [],
278
+ line: this.formatter.missingStep(keyword, pickleStep.text),
279
+ pickleStep,
280
+ stepConfig: undefined
281
+ };
282
+ }
283
+ getPickleStep(step, outlineExampleRowId) {
284
+ for (const pickle of this.options.pickles) {
285
+ const pickleStep = pickle.steps.find(({
286
+ astNodeIds
287
+ }) => {
288
+ const hasStepId = astNodeIds.includes(step.id);
289
+ const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
290
+ return hasStepId && hasRowId;
291
+ });
292
+ if (pickleStep) return pickleStep;
293
+ }
294
+ throw new Error(`Pickle step not found for step: ${step.text}`);
295
+ }
296
+ getStepKeyword(step) {
297
+ const origKeyword = step.keyword.trim();
298
+ let enKeyword;
299
+ if (origKeyword === '*') {
300
+ enKeyword = 'And';
301
+ } else {
302
+ enKeyword = this.i18nKeywordsMap ? this.i18nKeywordsMap.get(origKeyword) : origKeyword;
303
+ }
304
+ if (!enKeyword) throw new Error(`Keyword not found: ${origKeyword}`);
305
+ return enKeyword;
306
+ }
307
+ getDecoratorStep(step, usedPoms) {
308
+ const {
309
+ keyword,
310
+ pickleStep,
311
+ pomNode
312
+ } = step;
313
+ const fixtureNames = usedPoms.resolveFixtureNames(pomNode);
314
+ if (fixtureNames.length !== 1) {
315
+ const suggestedTags = fixtureNames.map(name => (0, _poms.buildFixtureTag)(name)).join(', ');
316
+ (0, _utils.exitWithMessage)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.sourceFile}.`, `Please set one of the following tags (${suggestedTags}) or refactor your Page Object classes.`);
317
+ }
318
+ return {
319
+ fixtureNames,
320
+ line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureNames[0]])
321
+ };
322
+ }
323
+ getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
324
+ const params = {
325
+ _index_: exampleIndex
326
+ };
327
+ exampleRow.cells.forEach((cell, index) => {
328
+ var _examples$tableHeader;
329
+ const colName = (_examples$tableHeader = examples.tableHeader) === null || _examples$tableHeader === void 0 || (_examples$tableHeader = _examples$tableHeader.cells[index]) === null || _examples$tableHeader === void 0 ? void 0 : _examples$tableHeader.value;
330
+ if (colName) params[colName] = cell.value;
331
+ });
332
+ return (0, _utils.template)(titleFormat, params);
333
+ }
334
+ getExamplesTitleFormat(examples) {
335
+ var _comment$text;
336
+ const {
337
+ line
338
+ } = examples.location;
339
+ const titleFormatCommentLine = line - 1;
340
+ const comment = this.options.doc.comments.find(c => {
341
+ return c.location.line === titleFormatCommentLine;
342
+ });
343
+ const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
344
+ const prefix = '# title-format:';
345
+ return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : this.config.examplesTitleFormat;
346
+ }
347
+ skipByTagsExpression(node) {
348
+ var _this$options$tagsExp;
349
+ // see: https://github.com/cucumber/tag-expressions/tree/main/javascript
350
+ return ((_this$options$tagsExp = this.options.tagsExpression) === null || _this$options$tagsExp === void 0 ? void 0 : _this$options$tagsExp.evaluate(node.tags)) === false;
351
+ }
352
+ }
353
+ exports.TestFile = TestFile;
354
+ function isOutline(scenario) {
355
+ return scenario.keyword === 'Scenario Outline' || scenario.keyword === 'Scenario Template';
356
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TestNode = void 0;
7
+ var _utils = require("../utils");
8
+ /**
9
+ * Universal TestNode class with accumulated data (tags, titiles)
10
+ * of parent-child relations in test file structure.
11
+ */
12
+
13
+ const SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
14
+ class TestNode {
15
+ title;
16
+ titlePath;
17
+ ownTags = [];
18
+ tags = [];
19
+ flags = {};
20
+ constructor(origItem, parent) {
21
+ this.origItem = origItem;
22
+ this.parent = parent;
23
+ this.initOwnTags(origItem);
24
+ this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
25
+ this.title = origItem.name;
26
+ this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
27
+ }
28
+ initOwnTags(origItem) {
29
+ const tagNames = (0, _utils.removeDuplicates)(getTagNames(origItem.tags));
30
+ tagNames.forEach(tag => {
31
+ if (isSpecialTag(tag)) {
32
+ this.setFlag(tag);
33
+ } else {
34
+ this.ownTags.push(tag);
35
+ }
36
+ });
37
+ }
38
+ setFlag(tag) {
39
+ if (tag === '@only') this.flags.only = true;
40
+ if (tag === '@skip') this.flags.skip = true;
41
+ if (tag === '@fixme') this.flags.fixme = true;
42
+ }
43
+ }
44
+ exports.TestNode = TestNode;
45
+ function getTagNames(tags) {
46
+ return tags.map(tag => tag.name);
47
+ }
48
+ function isSpecialTag(tag) {
49
+ return SPECIAL_TAGS.includes(tag);
50
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BddWorld", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _bddWorld.BddWorld;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "createBdd", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _createBdd.createBdd;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "defineBddConfig", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _config.defineBddConfig;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "test", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _bddFixtures.test;
28
+ }
29
+ });
30
+ var _config = require("./config");
31
+ var _createBdd = require("./stepDefinitions/createBdd");
32
+ var _bddFixtures = require("./run/bddFixtures");
33
+ var _bddWorld = require("./run/bddWorld");
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fixtureParameterNames = fixtureParameterNames;
7
+ /**
8
+ * Extracted from playwright.
9
+ * https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
10
+ */
11
+
12
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
13
+ /* eslint-disable max-statements, complexity, max-len, max-depth */
14
+
15
+ const signatureSymbol = Symbol('signature');
16
+ function fixtureParameterNames(fn) {
17
+ if (typeof fn !== 'function') {
18
+ return [];
19
+ }
20
+ ;
21
+ if (!fn[signatureSymbol]) {
22
+ fn[signatureSymbol] = innerFixtureParameterNames(fn);
23
+ }
24
+ return fn[signatureSymbol];
25
+ }
26
+ function innerFixtureParameterNames(fn) {
27
+ const text = filterOutComments(fn.toString());
28
+ const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
29
+ if (!match) {
30
+ return [];
31
+ }
32
+ ;
33
+ const trimmedParams = match[1].trim();
34
+ if (!trimmedParams) {
35
+ return [];
36
+ }
37
+ ;
38
+ const [firstParam] = splitByComma(trimmedParams);
39
+ if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
40
+ throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
41
+ }
42
+ const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
43
+ const colon = prop.indexOf(':');
44
+ return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
45
+ });
46
+ const restProperty = props.find(prop => prop.startsWith('...'));
47
+ if (restProperty) {
48
+ throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
49
+ }
50
+ return props;
51
+ }
52
+ function filterOutComments(s) {
53
+ const result = [];
54
+ let commentState = 'none';
55
+ for (let i = 0; i < s.length; ++i) {
56
+ if (commentState === 'singleline') {
57
+ if (s[i] === '\n') {
58
+ commentState = 'none';
59
+ }
60
+ ;
61
+ } else if (commentState === 'multiline') {
62
+ if (s[i - 1] === '*' && s[i] === '/') {
63
+ commentState = 'none';
64
+ }
65
+ ;
66
+ } else if (commentState === 'none') {
67
+ if (s[i] === '/' && s[i + 1] === '/') {
68
+ commentState = 'singleline';
69
+ } else if (s[i] === '/' && s[i + 1] === '*') {
70
+ commentState = 'multiline';
71
+ i += 2;
72
+ } else {
73
+ result.push(s[i]);
74
+ }
75
+ }
76
+ }
77
+ return result.join('');
78
+ }
79
+ function splitByComma(s) {
80
+ const result = [];
81
+ const stack = [];
82
+ let start = 0;
83
+ for (let i = 0; i < s.length; i++) {
84
+ if (s[i] === '{' || s[i] === '[') {
85
+ stack.push(s[i] === '{' ? '}' : ']');
86
+ } else if (s[i] === stack[stack.length - 1]) {
87
+ stack.pop();
88
+ } else if (!stack.length && s[i] === ',') {
89
+ const token = s.substring(start, i).trim();
90
+ if (token) {
91
+ result.push(token);
92
+ }
93
+ ;
94
+ start = i + 1;
95
+ }
96
+ }
97
+ const lastToken = s.substring(start).trim();
98
+ if (lastToken) {
99
+ result.push(lastToken);
100
+ }
101
+ ;
102
+ return result;
103
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getLocationInFile = getLocationInFile;
8
+ var _url = _interopRequireDefault(require("url"));
9
+ var _utils = require("./utils");
10
+ /**
11
+ * Inspects stacktrace and finds call location in provided file.
12
+ * This function is based on Playwright's getLocationByStacktrace().
13
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
14
+ */
15
+ function getLocationInFile(filePath) {
16
+ const {
17
+ sourceMapSupport
18
+ } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
19
+ const oldPrepareStackTrace = Error.prepareStackTrace;
20
+ Error.prepareStackTrace = (error, stackFrames) => {
21
+ const frameInFile = stackFrames.find(frame => frame.getFileName() === filePath);
22
+ if (!frameInFile) {
23
+ return {
24
+ file: '',
25
+ line: 0,
26
+ column: 0
27
+ };
28
+ }
29
+ ;
30
+ const frame = sourceMapSupport.wrapCallSite(frameInFile);
31
+ const fileName = frame.getFileName();
32
+ // Node error stacks for modules use file:// urls instead of paths.
33
+ const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
34
+ return {
35
+ file,
36
+ line: frame.getLineNumber(),
37
+ column: frame.getColumnNumber()
38
+ };
39
+ };
40
+ // commented stackTraceLImit modification, todo: check if it has perf impact
41
+ // const oldStackTraceLimit = Error.stackTraceLimit;
42
+ // Error.stackTraceLimit = level + 1;
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const obj = {};
45
+ Error.captureStackTrace(obj);
46
+ const location = obj.stack;
47
+ // Error.stackTraceLimit = oldStackTraceLimit;
48
+ Error.prepareStackTrace = oldPrepareStackTrace;
49
+ return location;
50
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.loadConfig = loadConfig;
8
+ exports.resolveConfigFile = resolveConfigFile;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+ var _utils = require("./utils");
12
+ var _transform = require("./transform");
13
+ var _utils2 = require("../utils");
14
+ /**
15
+ * Loading Playwright config.
16
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/configLoader.ts
17
+ */
18
+
19
+ async function loadConfig(cliConfigPath) {
20
+ const resolvedConfigFile = resolveConfigFile(cliConfigPath);
21
+ assertConfigFileExists(resolvedConfigFile, cliConfigPath);
22
+ await (0, _transform.requireTransform)().requireOrImport(resolvedConfigFile);
23
+ return {
24
+ resolvedConfigFile
25
+ };
26
+ }
27
+ function resolveConfigFile(cliConfigPath) {
28
+ const {
29
+ resolveConfigFile
30
+ } = (0, _utils.requirePlaywrightModule)('lib/common/configLoader.js');
31
+ const configFileOrDirectory = getConfigFilePath(cliConfigPath);
32
+ return resolveConfigFile(configFileOrDirectory) || '';
33
+ }
34
+ function getConfigFilePath(cliConfigPath) {
35
+ return cliConfigPath ? _path.default.resolve(process.cwd(), cliConfigPath) : process.cwd();
36
+ }
37
+ function assertConfigFileExists(resolvedConfigFile, cliConfigPath) {
38
+ if (!resolvedConfigFile || !_fs.default.existsSync(resolvedConfigFile)) {
39
+ const configFilePath = getConfigFilePath(cliConfigPath);
40
+ (0, _utils2.exitWithMessage)(`Can't find Playwright config file in: ${configFilePath}`);
41
+ }
42
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTestImpl = getTestImpl;
7
+ exports.isParentChildTest = isParentChildTest;
8
+ var _test = require("@playwright/test");
9
+ var _utils = require("../utils");
10
+ /**
11
+ * Helpers to deal with Playwright test internal stuff.
12
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/testType.ts
13
+ */
14
+
15
+ const testTypeSymbol = (0, _utils.getSymbolByName)(_test.test, 'testType');
16
+
17
+ /**
18
+ * Returns test fixtures using Symbol.
19
+ */
20
+ function getTestFixtures(test) {
21
+ return getTestImpl(test).fixtures;
22
+ }
23
+ function getTestImpl(test) {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ return test[testTypeSymbol];
26
+ }
27
+
28
+ /**
29
+ * Returns true if all fixtures of parent test found in child test.
30
+ */
31
+ function isParentChildTest(parent, child) {
32
+ if (parent === child) {
33
+ return false;
34
+ }
35
+ ;
36
+ const childLocationsSet = new Set(getTestFixtures(child).map(f => locationToString(f.location)));
37
+ return getTestFixtures(parent).every(f => {
38
+ return childLocationsSet.has(locationToString(f.location));
39
+ });
40
+ }
41
+ function locationToString({
42
+ file,
43
+ line,
44
+ column
45
+ }) {
46
+ return `${file}:${line}:${column}`;
47
+ }