@zohodesk/testinglibrary 0.1.8-exp-bdd-v3 → 0.1.8-exp-bdd-v4

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 (92) hide show
  1. package/.eslintrc.js +5 -1
  2. package/build/bdd-framework/cli/commands/env.js +42 -0
  3. package/build/bdd-framework/cli/commands/export.js +47 -0
  4. package/build/bdd-framework/cli/commands/test.js +64 -0
  5. package/build/bdd-framework/cli/index.js +11 -0
  6. package/build/bdd-framework/cli/options.js +19 -0
  7. package/build/bdd-framework/cli/worker.js +13 -0
  8. package/build/bdd-framework/config/dir.js +27 -0
  9. package/build/bdd-framework/config/env.js +50 -0
  10. package/build/bdd-framework/config/index.js +90 -0
  11. package/build/bdd-framework/config/lang.js +14 -0
  12. package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
  13. package/build/bdd-framework/cucumber/gherkin.d.js +5 -0
  14. package/build/bdd-framework/cucumber/loadConfig.js +17 -0
  15. package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
  16. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
  17. package/build/bdd-framework/cucumber/loadSources.js +57 -0
  18. package/build/bdd-framework/cucumber/loadSteps.js +40 -0
  19. package/build/bdd-framework/decorators.js +18 -0
  20. package/build/bdd-framework/gen/fixtures.js +48 -0
  21. package/build/bdd-framework/gen/formatter.js +135 -0
  22. package/build/bdd-framework/gen/i18n.js +39 -0
  23. package/build/bdd-framework/gen/index.js +164 -0
  24. package/build/bdd-framework/gen/testFile.js +422 -0
  25. package/build/bdd-framework/gen/testNode.js +61 -0
  26. package/build/bdd-framework/gen/testPoms.js +133 -0
  27. package/build/bdd-framework/hooks/scenario.js +107 -0
  28. package/build/bdd-framework/hooks/worker.js +83 -0
  29. package/build/bdd-framework/index.js +45 -0
  30. package/build/bdd-framework/playwright/fixtureParameterNames.js +93 -0
  31. package/build/bdd-framework/playwright/getLocationInFile.js +52 -0
  32. package/build/bdd-framework/playwright/loadConfig.js +42 -0
  33. package/build/bdd-framework/playwright/testTypeImpl.js +61 -0
  34. package/build/bdd-framework/playwright/transform.js +84 -0
  35. package/build/bdd-framework/playwright/types.js +5 -0
  36. package/build/bdd-framework/playwright/utils.js +34 -0
  37. package/build/bdd-framework/run/StepInvoker.js +73 -0
  38. package/build/bdd-framework/run/bddFixtures.js +170 -0
  39. package/build/bdd-framework/run/bddWorld.js +76 -0
  40. package/build/bdd-framework/snippets/index.js +136 -0
  41. package/build/bdd-framework/snippets/snippetSyntax.js +43 -0
  42. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
  43. package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
  44. package/build/bdd-framework/stepDefinitions/createBdd.js +66 -0
  45. package/build/bdd-framework/stepDefinitions/decorators/class.js +68 -0
  46. package/build/bdd-framework/stepDefinitions/decorators/steps.js +99 -0
  47. package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
  48. package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
  49. package/build/bdd-framework/utils/exit.js +58 -0
  50. package/build/bdd-framework/utils/index.js +70 -0
  51. package/build/bdd-framework/utils/jsStringWrap.js +44 -0
  52. package/build/bdd-framework/utils/logger.js +30 -0
  53. package/build/bdd-poc/core-runner/main.js +10 -0
  54. package/build/bdd-poc/core-runner/stepDefinitions.js +0 -1
  55. package/build/bdd-poc/index.js +26 -0
  56. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +6 -6
  57. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +1 -2
  58. package/build/bdd-poc/test/testDataMap.js +5 -5
  59. package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
  60. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  61. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  62. package/build/core/playwright/builtInFixtures/context.js +15 -0
  63. package/build/core/playwright/builtInFixtures/index.js +26 -0
  64. package/build/core/playwright/builtInFixtures/page.js +51 -0
  65. package/build/core/playwright/clear-caches.js +29 -0
  66. package/build/core/playwright/custom-commands.js +1 -2
  67. package/build/core/playwright/index.js +10 -79
  68. package/build/core/playwright/readConfigFile.js +12 -6
  69. package/build/core/playwright/report-generator.js +2 -1
  70. package/build/core/playwright/setup/config-creator.js +23 -17
  71. package/build/core/playwright/setup/config-utils.js +32 -1
  72. package/build/core/playwright/setup/custom-reporter.js +109 -0
  73. package/build/core/playwright/tag-processor.js +68 -0
  74. package/build/core/playwright/test-runner.js +10 -10
  75. package/build/index.d.ts +59 -4
  76. package/build/index.js +10 -9
  77. package/build/lib/cli.js +10 -1
  78. package/build/parser/parser.js +0 -1
  79. package/build/setup-folder-structure/helper.js +34 -0
  80. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  81. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  82. package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
  83. package/build/setup-folder-structure/samples/uat-config-sample.js +3 -2
  84. package/build/setup-folder-structure/setupProject.js +10 -5
  85. package/build/utils/fileUtils.js +15 -4
  86. package/build/utils/logger.js +1 -2
  87. package/build/utils/stepDefinitionsFormatter.js +1 -2
  88. package/changelog.md +57 -0
  89. package/npm-shrinkwrap.json +1426 -2172
  90. package/package.json +5 -4
  91. package/build/bdd-poc/main.js +0 -10
  92. /package/build/bdd-poc/{runner.js → core-runner/runner.js} +0 -0
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBddAutoInjectFixture = isBddAutoInjectFixture;
7
+ exports.test = void 0;
8
+ var _test = require("@playwright/test");
9
+ var _loadConfig = require("../cucumber/loadConfig");
10
+ var _loadSteps = require("../cucumber/loadSteps");
11
+ var _bddWorld = require("./bddWorld");
12
+ var _config = require("../config");
13
+ var _env = require("../config/env");
14
+ var _steps = require("../stepDefinitions/decorators/steps");
15
+ var _dir = require("../config/dir");
16
+ var _scenario = require("../hooks/scenario");
17
+ var _worker = require("../hooks/worker");
18
+ var _StepInvoker = require("./StepInvoker");
19
+ const test = exports.test = _test.test.extend({
20
+ // load cucumber once per worker (auto-fixture)
21
+ // todo: maybe remove caching in cucumber/loadConfig.ts and cucumber/loadSteps.ts
22
+ // as we call it once per worker. Check generation phase.
23
+ $cucumber: [async ({}, use, workerInfo) => {
24
+ const config = (0, _env.getConfigFromEnv)(workerInfo.project.testDir);
25
+ const environment = {
26
+ cwd: (0, _dir.getPlaywrightConfigDir)()
27
+ };
28
+ const {
29
+ runConfiguration
30
+ } = await (0, _loadConfig.loadConfig)({
31
+ provided: (0, _config.extractCucumberConfig)(config)
32
+ }, environment);
33
+ const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
34
+ (0, _steps.appendDecoratorSteps)(supportCodeLibrary);
35
+ const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
36
+ await use({
37
+ runConfiguration,
38
+ supportCodeLibrary,
39
+ World
40
+ });
41
+ }, {
42
+ auto: true,
43
+ scope: 'worker'
44
+ }],
45
+ $lang: ({}, use) => use(''),
46
+ // init $bddWorldFixtures with empty object, will be owerwritten in test file for cucumber-style
47
+ $bddWorldFixtures: ({}, use) => use({}),
48
+ $bddWorld: async ({
49
+ $tags,
50
+ $test,
51
+ $bddWorldFixtures,
52
+ $cucumber,
53
+ $lang
54
+ }, use, testInfo) => {
55
+ const {
56
+ runConfiguration,
57
+ supportCodeLibrary,
58
+ World
59
+ } = $cucumber;
60
+ const world = new World({
61
+ testInfo,
62
+ supportCodeLibrary,
63
+ $tags,
64
+ $test,
65
+ $bddWorldFixtures,
66
+ lang: $lang,
67
+ parameters: runConfiguration.runtime.worldParameters || {},
68
+ log: () => {},
69
+ attach: async () => {}
70
+ });
71
+ await world.init();
72
+ await use(world);
73
+ await world.destroy();
74
+ },
75
+ Given: ({
76
+ $bddWorld
77
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Given').invoke),
78
+ When: ({
79
+ $bddWorld
80
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'When').invoke),
81
+ Then: ({
82
+ $bddWorld
83
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Then').invoke),
84
+ And: ({
85
+ $bddWorld
86
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'And').invoke),
87
+ But: ({
88
+ $bddWorld
89
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'But').invoke),
90
+ // init $tags with empty array, can be owerwritten in test file
91
+ $tags: ({}, use) => use([]),
92
+ // init $test with base test, but it will be always overwritten in test file
93
+ $test: ({}, use) => use(_test.test),
94
+ // can be owerwritten in test file if there are scenario hooks
95
+ $scenarioHookFixtures: ({}, use) => use({}),
96
+ $before: [
97
+ // Unused dependencies are important:
98
+ // 1. $beforeAll / $afterAll: in pw < 1.39 worker-scoped auto-fixtures were called after test-scoped
99
+ // 2. $after: to call after hooks in case of errors in before hooks
100
+ async ({
101
+ $scenarioHookFixtures,
102
+ $bddWorld,
103
+ $tags,
104
+ $beforeAll,
105
+ $afterAll,
106
+ $after
107
+ }, use, $testInfo) => {
108
+ await (0, _scenario.runScenarioHooks)('before', {
109
+ $bddWorld,
110
+ $tags,
111
+ $testInfo,
112
+ ...$scenarioHookFixtures
113
+ });
114
+ await use();
115
+ }, {
116
+ auto: true
117
+ }],
118
+ $after: [async ({
119
+ $scenarioHookFixtures,
120
+ $bddWorld,
121
+ $tags
122
+ }, use, $testInfo) => {
123
+ await use();
124
+ await (0, _scenario.runScenarioHooks)('after', {
125
+ $bddWorld,
126
+ $tags,
127
+ $testInfo,
128
+ ...$scenarioHookFixtures
129
+ });
130
+ }, {
131
+ auto: true
132
+ }],
133
+ // can be owerwritten in test file if there are worker hooks
134
+ $workerHookFixtures: [({}, use) => use({}), {
135
+ scope: 'worker'
136
+ }],
137
+ $beforeAll: [
138
+ // Important unused dependencies:
139
+ // 1. $afterAll: in pw < 1.39 worker-scoped auto-fixtures are called in incorrect order
140
+ // 2. $cucumber: to load hooks before this fixtures
141
+ async ({
142
+ $workerHookFixtures,
143
+ $cucumber
144
+ }, use, $workerInfo) => {
145
+ await (0, _worker.runWorkerHooks)('beforeAll', {
146
+ $workerInfo,
147
+ ...$workerHookFixtures
148
+ });
149
+ await use();
150
+ }, {
151
+ auto: true,
152
+ scope: 'worker'
153
+ }],
154
+ $afterAll: [async ({
155
+ $workerHookFixtures
156
+ }, use, $workerInfo) => {
157
+ await use();
158
+ await (0, _worker.runWorkerHooks)('afterAll', {
159
+ $workerInfo,
160
+ ...$workerHookFixtures
161
+ });
162
+ }, {
163
+ auto: true,
164
+ scope: 'worker'
165
+ }]
166
+ });
167
+ const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
168
+ function isBddAutoInjectFixture(name) {
169
+ return BDD_AUTO_INJECT_FIXTURES.includes(name);
170
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BddWorld = void 0;
7
+ exports.getWorldConstructor = getWorldConstructor;
8
+ var _cucumber = require("@cucumber/cucumber");
9
+ class BddWorld extends _cucumber.World {
10
+ options;
11
+ stepFixtures = {};
12
+ constructor(options) {
13
+ super(options);
14
+ this.options = options;
15
+ }
16
+ /**
17
+ * Use particular fixture in cucumber-style steps.
18
+ *
19
+ * Note: TS does not support partial generic inference,
20
+ * that's why we can't use this.useFixture<typeof test>('xxx');
21
+ * The solution is to pass TestType as a generic to BddWorld
22
+ * and call useFixture without explicit generic params.
23
+ * Finally, it looks even better as there is no need to pass `typeof test`
24
+ * in every `this.useFixture` call.
25
+ *
26
+ * The downside - it's impossible to pass fixtures type directly to `this.useFixture`
27
+ * like it's done in @Fixture decorator.
28
+ *
29
+ * See: https://stackoverflow.com/questions/45509621/specify-only-first-type-argument
30
+ * See: https://github.com/Microsoft/TypeScript/pull/26349
31
+ */
32
+ useFixture(fixtureName) {
33
+ return this.stepFixtures[fixtureName];
34
+ }
35
+ get page() {
36
+ return this.options.$bddWorldFixtures.page;
37
+ }
38
+ get context() {
39
+ return this.options.$bddWorldFixtures.context;
40
+ }
41
+ get browser() {
42
+ return this.options.$bddWorldFixtures.browser;
43
+ }
44
+ get browserName() {
45
+ return this.options.$bddWorldFixtures.browserName;
46
+ }
47
+ get request() {
48
+ return this.options.$bddWorldFixtures.request;
49
+ }
50
+ get testInfo() {
51
+ return this.options.testInfo;
52
+ }
53
+ get tags() {
54
+ return this.options.$tags;
55
+ }
56
+ get test() {
57
+ return this.options.$test;
58
+ }
59
+ async init() {
60
+ // async setup before each test
61
+ }
62
+ async destroy() {
63
+ // async teardown after each test
64
+ }
65
+ }
66
+ exports.BddWorld = BddWorld;
67
+ function getWorldConstructor(supportCodeLibrary) {
68
+ // setWorldConstructor was not called
69
+ if (supportCodeLibrary.World === _cucumber.World) {
70
+ return BddWorld;
71
+ }
72
+ if (!Object.prototype.isPrototypeOf.call(BddWorld, supportCodeLibrary.World)) {
73
+ throw new Error(`CustomWorld should inherit from playwright-bdd World`);
74
+ }
75
+ return supportCodeLibrary.World;
76
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Snippets = void 0;
7
+ var _url = require("url");
8
+ var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
9
+ var _logger = require("../utils/logger");
10
+ var _stepConfig = require("../stepDefinitions/stepConfig");
11
+ /**
12
+ * Generate and show snippets for undefined steps
13
+ */
14
+
15
+ class Snippets {
16
+ files;
17
+ runConfiguration;
18
+ supportCodeLibrary;
19
+ snippetBuilder;
20
+ bddBuiltInSyntax = false;
21
+ constructor(files, runConfiguration, supportCodeLibrary) {
22
+ this.files = files;
23
+ this.runConfiguration = runConfiguration;
24
+ this.supportCodeLibrary = supportCodeLibrary;
25
+ }
26
+ async print() {
27
+ this.snippetBuilder = await this.createSnippetBuilder();
28
+ const snippets = this.getSnippets();
29
+ this.printHeader();
30
+ this.printSnippets(snippets);
31
+ this.printFooter(snippets);
32
+ // exit();
33
+ }
34
+ async createSnippetBuilder() {
35
+ const {
36
+ snippetInterface
37
+ } = this.runConfiguration.formats.options;
38
+ const snippetSyntax = this.getSnippetSyntax();
39
+ return (0, _loadSnippetBuilder.loadSnippetBuilder)(this.supportCodeLibrary, snippetInterface, snippetSyntax);
40
+ }
41
+ getSnippetSyntax() {
42
+ const {
43
+ snippetSyntax
44
+ } = this.runConfiguration.formats.options;
45
+ if (!snippetSyntax && this.isPlaywrightStyle()) {
46
+ this.bddBuiltInSyntax = true;
47
+ const filePath = this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
48
+ return (0, _url.pathToFileURL)(filePath).toString();
49
+ } else {
50
+ return snippetSyntax;
51
+ }
52
+ }
53
+ getSnippets() {
54
+ const snippetsSet = new Set();
55
+ const snippets = [];
56
+ this.files.forEach(file => {
57
+ file.undefinedSteps.forEach(undefinedStep => {
58
+ const {
59
+ snippet,
60
+ snippetWithLocation
61
+ } = this.getSnippet(file, snippets.length + 1, undefinedStep);
62
+ if (!snippetsSet.has(snippet)) {
63
+ snippetsSet.add(snippet);
64
+ snippets.push(snippetWithLocation);
65
+ }
66
+ });
67
+ });
68
+ return snippets;
69
+ }
70
+ getSnippet(file, index, undefinedStep) {
71
+ const snippet = this.snippetBuilder.build({
72
+ keywordType: undefinedStep.keywordType,
73
+ pickleStep: undefinedStep.pickleStep
74
+ });
75
+ const {
76
+ line,
77
+ column
78
+ } = undefinedStep.step.location;
79
+ const snippetWithLocation = [`// ${index}. Missing step definition for "${file.sourceFile}:${line}:${column}"`, snippet].join('\n');
80
+ return {
81
+ snippet,
82
+ snippetWithLocation
83
+ };
84
+ }
85
+ isTypeScript() {
86
+ const {
87
+ requirePaths,
88
+ importPaths
89
+ } = this.supportCodeLibrary.originalCoordinates;
90
+ return requirePaths.some(p => p.endsWith('.ts')) || importPaths.some(p => p.endsWith('.ts'));
91
+ }
92
+ isPlaywrightStyle() {
93
+ const {
94
+ stepDefinitions
95
+ } = this.supportCodeLibrary;
96
+ return stepDefinitions.length > 0 ? stepDefinitions.some(step => (0, _stepConfig.isPlaywrightStyle)((0, _stepConfig.getStepConfig)(step))) : true;
97
+ }
98
+ isDecorators() {
99
+ const {
100
+ stepDefinitions
101
+ } = this.supportCodeLibrary;
102
+ const decoratorSteps = stepDefinitions.filter(step => (0, _stepConfig.isDecorator)((0, _stepConfig.getStepConfig)(step)));
103
+ return decoratorSteps.length > stepDefinitions.length / 2;
104
+ }
105
+ printHeader() {
106
+ const lines = [`Missing steps found. Use snippets below:`];
107
+ if (this.bddBuiltInSyntax) {
108
+ if (this.isDecorators()) {
109
+ lines.push(`import { Fixture, Given, When, Then } from 'playwright-bdd/decorators';\n`);
110
+ } else {
111
+ lines.push(`import { createBdd } from '@zohodesk/testinglibrary';`, `const { Given, When, Then } = createBdd();\n`);
112
+ }
113
+ } else {
114
+ lines.push(`import { Given, When, Then } from '@cucumber/cucumber';\n`);
115
+ }
116
+ _logger.logger.error(lines.join('\n\n'));
117
+ }
118
+ printSnippets(snippets) {
119
+ _logger.logger.error(snippets.concat(['']).join('\n\n'));
120
+ }
121
+ printFooter(snippets) {
122
+ _logger.logger.error(`Missing step definitions (${snippets.length}).`, `Use snippets above to create them.`);
123
+ this.printWarningOnZeroScannedFiles();
124
+ }
125
+ printWarningOnZeroScannedFiles() {
126
+ const {
127
+ requirePaths,
128
+ importPaths
129
+ } = this.supportCodeLibrary.originalCoordinates;
130
+ const scannedFilesCount = requirePaths.length + importPaths.length;
131
+ if (scannedFilesCount === 0 && !this.isDecorators()) {
132
+ _logger.logger.error(`Note that 0 step definition files found, check the config.`);
133
+ }
134
+ }
135
+ }
136
+ exports.Snippets = Snippets;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // todo: custom cucumber parameters
8
+ // See: https://github.com/cucumber/cucumber-expressions#custom-parameter-types
9
+ class _default {
10
+ isTypescript = false;
11
+ build({
12
+ generatedExpressions,
13
+ functionName,
14
+ stepParameterNames
15
+ }) {
16
+ // Always take only first generatedExpression
17
+ // Other expressions are for int/float combinations
18
+ const generatedExpression = generatedExpressions[0];
19
+ const expressionParameters = generatedExpression.parameterNames.map((name, i) => {
20
+ const argName = `arg${i === 0 ? '' : i}`;
21
+ const type = name.startsWith('string') ? 'string' : 'number';
22
+ return this.isTypescript ? `${argName}: ${type}` : argName;
23
+ });
24
+ const stepParameters = stepParameterNames.map(argName => {
25
+ const type = argName === 'dataTable' ? 'DataTable' : 'string';
26
+ return this.isTypescript ? `${argName}: ${type}` : argName;
27
+ });
28
+ const allParameterNames = ['{}', ...expressionParameters, ...stepParameters];
29
+ const functionSignature = `${functionName}('${this.escapeSpecialCharacters(generatedExpression)}', async (${allParameterNames.join(', ')}) => {`;
30
+ return [functionSignature,
31
+ // prettier-ignore
32
+ ` // ...`, '});'].join('\n');
33
+ }
34
+ escapeSpecialCharacters(generatedExpression) {
35
+ let source = generatedExpression.source;
36
+ // double up any backslashes because we're in a javascript string
37
+ source = source.replace(/\\/g, '\\\\');
38
+ // escape any single quotes because that's our quote delimiter
39
+ source = source.replace(/'/g, "\\'");
40
+ return source;
41
+ }
42
+ }
43
+ exports.default = _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ class _default {
8
+ build({
9
+ generatedExpressions,
10
+ functionName
11
+ }) {
12
+ // Always take only first generatedExpression
13
+ // Other expressions are for int/float combinations
14
+ const generatedExpression = generatedExpressions[0];
15
+ return `@${functionName}('${this.escapeSpecialCharacters(generatedExpression)}')`;
16
+ }
17
+ escapeSpecialCharacters(generatedExpression) {
18
+ let source = generatedExpression.source;
19
+ // double up any backslashes because we're in a javascript string
20
+ source = source.replace(/\\/g, '\\\\');
21
+ // escape any single quotes because that's our quote delimiter
22
+ source = source.replace(/'/g, "\\'");
23
+ return source;
24
+ }
25
+ }
26
+ exports.default = _default;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _snippetSyntax = _interopRequireDefault(require("./snippetSyntax"));
9
+ /**
10
+ * Playwright-style snippet syntax for typescript.
11
+ * Important to use separate file as it's simplest way to distinguish between js/ts
12
+ * without hooking into cucumber machinery.
13
+ */
14
+
15
+ class _default extends _snippetSyntax.default {
16
+ isTypescript = true;
17
+ }
18
+ exports.default = _default;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBdd = createBdd;
7
+ exports.hasCustomTest = void 0;
8
+ var _bddFixtures = require("../run/bddFixtures");
9
+ var _testTypeImpl = require("../playwright/testTypeImpl");
10
+ var _defineStep = require("./defineStep");
11
+ var _exit = require("../utils/exit");
12
+ var _scenario = require("../hooks/scenario");
13
+ var _worker = require("../hooks/worker");
14
+ /**
15
+ * Stuff related to writing steps in Playwright-style.
16
+ */
17
+
18
+ // Global flag showing that custom test was passed.
19
+ // Used when checking 'importTestFrom' config option.
20
+ // todo: https://github.com/vitalets/playwright-bdd/issues/46
21
+ let hasCustomTest = exports.hasCustomTest = false;
22
+ function createBdd(customTest) {
23
+ if (!hasCustomTest) {
24
+ exports.hasCustomTest = hasCustomTest = isCustomTest(customTest);
25
+ }
26
+ const Given = defineStepCtor('Given', hasCustomTest);
27
+ const When = defineStepCtor('When', hasCustomTest);
28
+ const Then = defineStepCtor('Then', hasCustomTest);
29
+ const Step = defineStepCtor('Unknown', hasCustomTest);
30
+ const Before = (0, _scenario.scenarioHookFactory)('before');
31
+ const After = (0, _scenario.scenarioHookFactory)('after');
32
+ const BeforeAll = (0, _worker.workerHookFactory)('beforeAll');
33
+ const AfterAll = (0, _worker.workerHookFactory)('afterAll');
34
+ return {
35
+ Given,
36
+ When,
37
+ Then,
38
+ Step,
39
+ Before,
40
+ After,
41
+ BeforeAll,
42
+ AfterAll
43
+ };
44
+ }
45
+ function defineStepCtor(keyword, hasCustomTest) {
46
+ return (pattern, fn) => {
47
+ (0, _defineStep.defineStep)({
48
+ keyword,
49
+ pattern,
50
+ fn,
51
+ hasCustomTest
52
+ });
53
+ };
54
+ }
55
+ function isCustomTest(customTest) {
56
+ if (!customTest || customTest === _bddFixtures.test) {
57
+ return false;
58
+ }
59
+ assertTestHasBddFixtures(customTest);
60
+ return true;
61
+ }
62
+ function assertTestHasBddFixtures(customTest) {
63
+ if (!(0, _testTypeImpl.isTestContainsSubtest)(customTest, _bddFixtures.test)) {
64
+ (0, _exit.exit)(`createBdd() should use 'test' extended from "playwright-bdd"`);
65
+ }
66
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Fixture = Fixture;
7
+ exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
8
+ var _steps = require("./steps");
9
+ var _exit = require("../../utils/exit");
10
+ /**
11
+ * Class level @Fixture decorator.
12
+ */
13
+
14
+ /**
15
+ * Graph of POM class inheritance.
16
+ * Allows to guess correct fixture by step text.
17
+ */
18
+ const pomGraph = new Map();
19
+ /**
20
+ * @Fixture decorator.
21
+ */
22
+ function Fixture(fixtureName) {
23
+ // context parameter is required for decorator by TS even though it's not used
24
+ return Ctor => {
25
+ createPomNode(Ctor, fixtureName);
26
+ };
27
+ }
28
+ function createPomNode(Ctor, fixtureName) {
29
+ const pomNode = {
30
+ fixtureName,
31
+ className: Ctor.name,
32
+ children: new Set()
33
+ };
34
+ ensureUniqueFixtureName(pomNode);
35
+ pomGraph.set(Ctor, pomNode);
36
+ (0, _steps.linkStepsWithPomNode)(Ctor, pomNode);
37
+ linkParentWithPomNode(Ctor, pomNode);
38
+ return pomNode;
39
+ }
40
+ function ensureUniqueFixtureName({
41
+ fixtureName,
42
+ className
43
+ }) {
44
+ if (!fixtureName) {
45
+ return;
46
+ }
47
+ const existingPom = getPomNodeByFixtureName(fixtureName);
48
+ if (existingPom) {
49
+ (0, _exit.exit)(`Duplicate fixture name "${fixtureName}"`, `defined for classes: ${existingPom.className}, ${className}`);
50
+ }
51
+ }
52
+ function linkParentWithPomNode(Ctor, pomNode) {
53
+ const parentCtor = Object.getPrototypeOf(Ctor);
54
+ if (!parentCtor) {
55
+ return;
56
+ }
57
+ // if parentCtor is not in pomGraph, add it.
58
+ // Case: parent class is not marked with @Fixture, but has decorator steps (base class)
59
+ const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
60
+ parentPomNode.children.add(pomNode);
61
+ }
62
+ function getPomNodeByFixtureName(fixtureName) {
63
+ for (const pomNode of pomGraph.values()) {
64
+ if (pomNode.fixtureName === fixtureName) {
65
+ return pomNode;
66
+ }
67
+ }
68
+ }