@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,85 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.installTransform = installTransform;
8
+ exports.requireTransform = requireTransform;
9
+ var _module = _interopRequireDefault(require("module"));
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+ var _path = _interopRequireDefault(require("path"));
12
+ var _utils = require("./utils");
13
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
14
+ /* eslint-disable max-params */
15
+ /**
16
+ * Installs require hook to transform ts.
17
+ * Extracted from playwright.
18
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/transform/transform.ts
19
+ */
20
+ function installTransform() {
21
+ const {
22
+ pirates
23
+ } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
24
+ const {
25
+ resolveHook,
26
+ shouldTransform,
27
+ transformHook
28
+ } = requireTransform();
29
+ let reverted = false;
30
+ const originalResolveFilename = _module.default._resolveFilename;
31
+ function resolveFilename(specifier, parent, ...rest) {
32
+ if (!reverted && parent) {
33
+ const resolved = resolveHook(parent.filename, specifier);
34
+ if (resolved !== undefined) {
35
+ specifier = resolved;
36
+ }
37
+ }
38
+ return originalResolveFilename.call(this, specifier, parent, ...rest);
39
+ }
40
+ _module.default._resolveFilename = resolveFilename;
41
+ const revertPirates = pirates.addHook((code, filename) => {
42
+ if (!shouldTransform(filename)) {
43
+ return code;
44
+ }
45
+ return transformHook(code, filename);
46
+ }, {
47
+ exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
48
+ });
49
+ return () => {
50
+ reverted = true;
51
+ _module.default._resolveFilename = originalResolveFilename;
52
+ revertPirates();
53
+ };
54
+ }
55
+ function requireTransform() {
56
+ const transformPathSince1_35 = (0, _utils.getPlaywrightModulePath)('lib/transform/transform.js');
57
+ if (_fs.default.existsSync(transformPathSince1_35)) {
58
+ const {
59
+ resolveHook,
60
+ shouldTransform,
61
+ transformHook,
62
+ requireOrImport
63
+ } = (0, _utils.requirePlaywrightModule)(transformPathSince1_35);
64
+ return {
65
+ resolveHook,
66
+ shouldTransform,
67
+ transformHook,
68
+ requireOrImport
69
+ };
70
+ } else {
71
+ const {
72
+ resolveHook,
73
+ transformHook,
74
+ requireOrImport
75
+ } = (0, _utils.requirePlaywrightModule)('lib/common/transform.js');
76
+ // see: https://github.com/microsoft/playwright/blob/b4ffb848de1b00e9a0abad6dacdccce60cce9bed/packages/playwright-test/src/reporters/base.ts#L524
77
+ const shouldTransform = file => !file.includes(`${_path.default.sep}node_modules${_path.default.sep}`);
78
+ return {
79
+ resolveHook,
80
+ shouldTransform,
81
+ transformHook,
82
+ requireOrImport
83
+ };
84
+ }
85
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getPlaywrightModulePath = getPlaywrightModulePath;
8
+ exports.requirePlaywrightModule = requirePlaywrightModule;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _utils = require("../utils");
11
+ const playwrightRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
12
+
13
+ /**
14
+ * Requires Playwright's internal module that is not exported via package.exports.
15
+ */
16
+ function requirePlaywrightModule(modulePath) {
17
+ const absPath = _path.default.isAbsolute(modulePath) ? modulePath : getPlaywrightModulePath(modulePath);
18
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
19
+ return require(absPath);
20
+ }
21
+ function getPlaywrightModulePath(relativePath) {
22
+ const parts = relativePath.split('/');
23
+ return _path.default.join(playwrightRoot, ...parts);
24
+ }
@@ -0,0 +1,109 @@
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 _createDecorators = require("../stepDefinitions/createDecorators");
15
+ var _dir = require("../config/dir");
16
+ const test = _test.test.extend({
17
+ $bddWorldBase: async ({
18
+ $tags,
19
+ $test
20
+ }, use, testInfo) => {
21
+ const config = (0, _env.getConfigFromEnv)(testInfo.project.testDir);
22
+ const environment = {
23
+ cwd: (0, _dir.getPlaywrightConfigDir)()
24
+ };
25
+ const {
26
+ runConfiguration
27
+ } = await (0, _loadConfig.loadConfig)({
28
+ provided: (0, _config.extractCucumberConfig)(config)
29
+ }, environment);
30
+ const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
31
+ (0, _createDecorators.appendDecoratorSteps)(supportCodeLibrary);
32
+ const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
33
+ const world = new World({
34
+ testInfo,
35
+ supportCodeLibrary,
36
+ $tags,
37
+ $test,
38
+ parameters: runConfiguration.runtime.worldParameters || {},
39
+ log: () => {},
40
+ attach: async () => {} // eslint-disable-line @typescript-eslint/no-empty-function
41
+ });
42
+
43
+ await world.init();
44
+ await use(world);
45
+ await world.destroy();
46
+ },
47
+ $bddWorld: async ({
48
+ $bddWorldBase,
49
+ page,
50
+ context,
51
+ browser,
52
+ browserName,
53
+ request
54
+ }, use) => {
55
+ $bddWorldBase.builtinFixtures = {
56
+ page,
57
+ context,
58
+ browser,
59
+ browserName,
60
+ request
61
+ };
62
+ await use($bddWorldBase);
63
+ },
64
+ // below fixtures are used in playwright-style
65
+ // and does not automatically init Playwright builtin fixtures
66
+ Given: ({
67
+ $bddWorldBase
68
+ }, use) => use($bddWorldBase.invokeStep),
69
+ When: ({
70
+ $bddWorldBase
71
+ }, use) => use($bddWorldBase.invokeStep),
72
+ Then: ({
73
+ $bddWorldBase
74
+ }, use) => use($bddWorldBase.invokeStep),
75
+ And: ({
76
+ $bddWorldBase
77
+ }, use) => use($bddWorldBase.invokeStep),
78
+ But: ({
79
+ $bddWorldBase
80
+ }, use) => use($bddWorldBase.invokeStep),
81
+ // below fixtures are used in cucumber-style
82
+ // and automatically init Playwright builtin fixtures
83
+ Given_: ({
84
+ $bddWorld
85
+ }, use) => use($bddWorld.invokeStep),
86
+ When_: ({
87
+ $bddWorld
88
+ }, use) => use($bddWorld.invokeStep),
89
+ Then_: ({
90
+ $bddWorld
91
+ }, use) => use($bddWorld.invokeStep),
92
+ And_: ({
93
+ $bddWorld
94
+ }, use) => use($bddWorld.invokeStep),
95
+ But_: ({
96
+ $bddWorld
97
+ }, use) => use($bddWorld.invokeStep),
98
+ // Init $tags fixture with empty array. Can be owerwritten in test file
99
+ // eslint-disable-next-line
100
+ $tags: ({}, use) => use([]),
101
+ // Init $test fixture with base test, but it will be always overwritten in test file
102
+ // eslint-disable-next-line
103
+ $test: ({}, use) => use(_test.test)
104
+ });
105
+ exports.test = test;
106
+ const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
107
+ function isBddAutoInjectFixture(name) {
108
+ return BDD_AUTO_INJECT_FIXTURES.includes(name);
109
+ }
@@ -0,0 +1,91 @@
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
+ var _loadSteps = require("../cucumber/loadSteps");
10
+ var _getLocationInFile = require("../playwright/getLocationInFile");
11
+ var _testTypeImpl = require("../playwright/testTypeImpl");
12
+ // See: https://playwright.dev/docs/test-fixtures#built-in-fixtures
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ class BddWorld extends _cucumber.World {
17
+ builtinFixtures;
18
+ customFixtures;
19
+ constructor(options) {
20
+ super(options);
21
+ this.options = options;
22
+ this.invokeStep = this.invokeStep.bind(this);
23
+ }
24
+ async invokeStep(text, argument, customFixtures) {
25
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, text, this.testInfo.file);
26
+ if (!stepDefinition) {
27
+ throw new Error(`Undefined step: "${text}"`);
28
+ }
29
+
30
+ // attach custom fixtures to world - the only way to pass them to cucumber step fn
31
+ this.customFixtures = customFixtures;
32
+ const code = stepDefinition.code;
33
+
34
+ // get location of step call in generated test file
35
+ const location = (0, _getLocationInFile.getLocationInFile)(this.test.info().file);
36
+ const {
37
+ parameters
38
+ } = await stepDefinition.getInvocationParameters({
39
+ hookParameter: {},
40
+ step: {
41
+ text,
42
+ argument
43
+ },
44
+ world: this
45
+ });
46
+ const res = await (0, _testTypeImpl.getTestImpl)(this.test)._step(location, text, () => code.apply(this, parameters));
47
+ delete this.customFixtures;
48
+ return res;
49
+ }
50
+ get page() {
51
+ return this.builtinFixtures.page;
52
+ }
53
+ get context() {
54
+ return this.builtinFixtures.context;
55
+ }
56
+ get browser() {
57
+ return this.builtinFixtures.browser;
58
+ }
59
+ get browserName() {
60
+ return this.builtinFixtures.browserName;
61
+ }
62
+ get request() {
63
+ return this.builtinFixtures.request;
64
+ }
65
+ get testInfo() {
66
+ return this.options.testInfo;
67
+ }
68
+ get tags() {
69
+ return this.options.$tags;
70
+ }
71
+ get test() {
72
+ return this.options.$test;
73
+ }
74
+ async init() {
75
+ // async setup before each test
76
+ }
77
+ async destroy() {
78
+ // async teardown after each test
79
+ }
80
+ }
81
+ exports.BddWorld = BddWorld;
82
+ function getWorldConstructor(supportCodeLibrary) {
83
+ // setWorldConstructor was not called
84
+ if (supportCodeLibrary.World === _cucumber.World) {
85
+ return BddWorld;
86
+ }
87
+ if (!Object.prototype.isPrototypeOf.call(BddWorld, supportCodeLibrary.World)) {
88
+ throw new Error(`CustomWorld should inherit from playwright-bdd World`);
89
+ }
90
+ return supportCodeLibrary.World;
91
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Snippets = void 0;
7
+ var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
8
+ var _utils = require("../utils");
9
+ var _defineStep = require("../stepDefinitions/defineStep");
10
+ var _logger = require("../utils/logger");
11
+ /**
12
+ * Generate and show snippets for undefined steps
13
+ */
14
+
15
+ class Snippets {
16
+ snippetBuilder;
17
+ bddBuiltInSyntax = false;
18
+ constructor(files, runConfiguration, supportCodeLibrary) {
19
+ this.files = files;
20
+ this.runConfiguration = runConfiguration;
21
+ this.supportCodeLibrary = supportCodeLibrary;
22
+ }
23
+ async printSnippetsAndExit() {
24
+ this.snippetBuilder = await this.createSnippetBuilder();
25
+ const snippets = this.getSnippets();
26
+ this.printHeader();
27
+ this.printSnippets(snippets);
28
+ this.printFooter(snippets);
29
+ }
30
+ async createSnippetBuilder() {
31
+ const {
32
+ snippetInterface
33
+ } = this.runConfiguration.formats.options;
34
+ const snippetSyntax = this.getSnippetSyntax();
35
+ return (0, _loadSnippetBuilder.loadSnippetBuilder)(this.supportCodeLibrary, snippetInterface, snippetSyntax);
36
+ }
37
+ getSnippetSyntax() {
38
+ const {
39
+ snippetSyntax
40
+ } = this.runConfiguration.formats.options;
41
+ if (!snippetSyntax && this.isPlaywrightStyle()) {
42
+ this.bddBuiltInSyntax = true;
43
+ return this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
44
+ } else {
45
+ return snippetSyntax;
46
+ }
47
+ }
48
+ getSnippets() {
49
+ const snippetsSet = new Set();
50
+ const snippets = [];
51
+ this.files.forEach(file => {
52
+ file.undefinedSteps.forEach(undefinedStep => {
53
+ const {
54
+ snippet,
55
+ snippetWithLocation
56
+ } = this.getSnippet(file, snippets.length + 1, undefinedStep);
57
+ if (!snippetsSet.has(snippet)) {
58
+ snippetsSet.add(snippet);
59
+ snippets.push(snippetWithLocation);
60
+ }
61
+ });
62
+ });
63
+ return snippets;
64
+ }
65
+ getSnippet(file, index, undefinedStep) {
66
+ const snippet = this.snippetBuilder.build({
67
+ keywordType: undefinedStep.keywordType,
68
+ pickleStep: undefinedStep.pickleStep
69
+ });
70
+ const {
71
+ line,
72
+ column
73
+ } = undefinedStep.step.location;
74
+ const snippetWithLocation = [`// ${index}. Missing step definition for "${file.sourceFile}:${line}:${column}"`, snippet].join('\n');
75
+ return {
76
+ snippet,
77
+ snippetWithLocation
78
+ };
79
+ }
80
+ isTypeScript() {
81
+ const {
82
+ requirePaths,
83
+ importPaths
84
+ } = this.supportCodeLibrary.originalCoordinates;
85
+ return requirePaths.some(p => p.endsWith('.ts')) || importPaths.some(p => p.endsWith('.ts'));
86
+ }
87
+ isPlaywrightStyle() {
88
+ const {
89
+ stepDefinitions
90
+ } = this.supportCodeLibrary;
91
+ return stepDefinitions.length > 0 ? stepDefinitions.some(step => (0, _defineStep.isPlaywrightStyle)(step)) : true;
92
+ }
93
+ isDecorators() {
94
+ const {
95
+ stepDefinitions
96
+ } = this.supportCodeLibrary;
97
+ const decoratorSteps = stepDefinitions.filter(step => {
98
+ var _getStepConfig;
99
+ return (_getStepConfig = (0, _defineStep.getStepConfig)(step)) === null || _getStepConfig === void 0 ? void 0 : _getStepConfig.isDecorator;
100
+ });
101
+ return decoratorSteps.length > stepDefinitions.length / 2;
102
+ }
103
+ printHeader() {
104
+ const lines = [`Missing steps found. Use snippets below:`];
105
+ if (this.bddBuiltInSyntax) {
106
+ if (this.isDecorators()) {
107
+ // TODO: For Decorators support
108
+ lines.push(`import { Fixture, Given, When, Then } from 'playwright-bdd/decorators';\n`);
109
+ } else {
110
+ lines.push(`import { createBdd } from '@zohodesk/testinglibrary';`, `const { Given, When, Then } = createBdd();\n`);
111
+ }
112
+ } else {
113
+ lines.push(`import { Given, When, Then } from '@cucumber/cucumber';\n`);
114
+ }
115
+ _logger.logger.error(lines.join('\n\n'));
116
+ }
117
+ printSnippets(snippets) {
118
+ _logger.logger.error(snippets.concat(['']).join('\n\n'));
119
+ }
120
+ printFooter(snippets) {
121
+ (0, _utils.exitWithMessage)(`Missing step definitions (${snippets.length}).`, 'Use snippets above to create them.', this.getWarnOnZeroScannedFiles());
122
+ }
123
+ getWarnOnZeroScannedFiles() {
124
+ const {
125
+ requirePaths,
126
+ importPaths
127
+ } = this.supportCodeLibrary.originalCoordinates;
128
+ const scannedFilesCount = requirePaths.length + importPaths.length;
129
+ return scannedFilesCount === 0 && !this.isDecorators() ? `\nNote that 0 step definition files found, check the config.` : '';
130
+ }
131
+ }
132
+ exports.Snippets = Snippets;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Playwright-style snippet syntax.
9
+ *
10
+ * See: https://github.com/cucumber/cucumber-js/blob/main/docs/custom_snippet_syntaxes.md
11
+ */
12
+
13
+ // todo: custom cucumber parameters
14
+ // See: https://github.com/cucumber/cucumber-expressions#custom-parameter-types
15
+
16
+ class _default {
17
+ isTypescript = false;
18
+ build({
19
+ generatedExpressions,
20
+ functionName,
21
+ stepParameterNames
22
+ }) {
23
+ // Always take only first generatedExpression
24
+ // Other expressions are for int/float combinations
25
+ const generatedExpression = generatedExpressions[0];
26
+ const expressionParameters = generatedExpression.parameterNames.map((name, i) => {
27
+ const argName = `arg${i === 0 ? '' : i}`;
28
+ const type = name.startsWith('string') ? 'string' : 'number';
29
+ return this.isTypescript ? `${argName}: ${type}` : argName;
30
+ });
31
+ const stepParameters = stepParameterNames.map(argName => {
32
+ const type = argName === 'dataTable' ? 'DataTable' : 'string';
33
+ return this.isTypescript ? `${argName}: ${type}` : argName;
34
+ });
35
+ const allParameterNames = ['{}', ...expressionParameters, ...stepParameters];
36
+ const functionSignature = `${functionName}('${this.escapeSpecialCharacters(generatedExpression)}', async (${allParameterNames.join(', ')}) => {`;
37
+ return [functionSignature,
38
+ // prettier-ignore
39
+ ` // ...`, '});'].join('\n');
40
+ }
41
+ escapeSpecialCharacters(generatedExpression) {
42
+ let source = generatedExpression.source;
43
+ // double up any backslashes because we're in a javascript string
44
+ source = source.replace(/\\/g, '\\\\');
45
+ // escape any single quotes because that's our quote delimiter
46
+ source = source.replace(/'/g, "\\'");
47
+ return source;
48
+ }
49
+ }
50
+ exports.default = _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Playwright-style snippet syntax for decorators.
9
+ *
10
+ * See: https://github.com/cucumber/cucumber-js/blob/main/docs/custom_snippet_syntaxes.md
11
+ */
12
+
13
+ class _default {
14
+ build({
15
+ generatedExpressions,
16
+ functionName
17
+ }) {
18
+ // Always take only first generatedExpression
19
+ // Other expressions are for int/float combinations
20
+ const generatedExpression = generatedExpressions[0];
21
+ return `@${functionName}('${this.escapeSpecialCharacters(generatedExpression)}')`;
22
+ }
23
+ escapeSpecialCharacters(generatedExpression) {
24
+ let source = generatedExpression.source;
25
+ // double up any backslashes because we're in a javascript string
26
+ source = source.replace(/\\/g, '\\\\');
27
+ // escape any single quotes because that's our quote delimiter
28
+ source = source.replace(/'/g, "\\'");
29
+ return source;
30
+ }
31
+ }
32
+ 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,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBdd = createBdd;
7
+ exports.extractFixtureNames = extractFixtureNames;
8
+ var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
9
+ var _utils = require("../utils");
10
+ var _bddFixtures = require("../run/bddFixtures");
11
+ var _testTypeImpl = require("../playwright/testTypeImpl");
12
+ var _defineStep = require("./defineStep");
13
+ /**
14
+ * Stuff related to writing steps in Playwright-style.
15
+ */
16
+
17
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
18
+
19
+ function createBdd(customTest) {
20
+ const hasCustomTest = isCustomTest(customTest);
21
+ const Given = defineStepCtor('Given', hasCustomTest);
22
+ const When = defineStepCtor('When', hasCustomTest);
23
+ const Then = defineStepCtor('Then', hasCustomTest);
24
+ const Step = defineStepCtor('Unknown', hasCustomTest);
25
+ return {
26
+ Given,
27
+ When,
28
+ Then,
29
+ Step
30
+ };
31
+ }
32
+ function defineStepCtor(keyword, hasCustomTest) {
33
+ return (pattern, fn) => {
34
+ (0, _defineStep.defineStep)({
35
+ keyword,
36
+ pattern,
37
+ fn,
38
+ hasCustomTest,
39
+ isDecorator: false
40
+ });
41
+ };
42
+ }
43
+ function extractFixtureNames(fn) {
44
+ return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
45
+ }
46
+ function isCustomTest(customTest) {
47
+ const isCustomTest = Boolean(customTest && customTest !== _bddFixtures.test);
48
+ if (isCustomTest && customTest && !(0, _testTypeImpl.isParentChildTest)(_bddFixtures.test, customTest)) {
49
+ (0, _utils.exitWithMessage)(`createBdd() should use test extended from "playwright-bdd"`);
50
+ }
51
+ return isCustomTest;
52
+ }