@zohodesk/testinglibrary 0.1.8-exp-bdd-v2 → 0.1.8-exp.1

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 (102) hide show
  1. package/.babelrc +18 -18
  2. package/.eslintrc.js +31 -27
  3. package/.prettierrc +5 -5
  4. package/README.md +17 -17
  5. package/bin/cli.js +2 -2
  6. package/build/bdd-framework/cli/commands/env.js +5 -6
  7. package/build/bdd-framework/cli/commands/export.js +1 -2
  8. package/build/bdd-framework/cli/commands/test.js +7 -4
  9. package/build/bdd-framework/cli/options.js +5 -6
  10. package/build/bdd-framework/cli/worker.js +3 -3
  11. package/build/bdd-framework/config/dir.js +6 -6
  12. package/build/bdd-framework/config/env.js +5 -4
  13. package/build/bdd-framework/config/index.js +3 -4
  14. package/build/bdd-framework/config/lang.js +14 -0
  15. package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
  16. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +3 -3
  17. package/build/bdd-framework/cucumber/loadSources.js +9 -9
  18. package/build/bdd-framework/cucumber/loadSteps.js +8 -3
  19. package/build/bdd-framework/decorators.js +6 -10
  20. package/build/bdd-framework/gen/fixtures.js +48 -0
  21. package/build/bdd-framework/gen/formatter.js +64 -17
  22. package/build/bdd-framework/gen/i18n.js +9 -5
  23. package/build/bdd-framework/gen/index.js +9 -8
  24. package/build/bdd-framework/gen/testFile.js +121 -55
  25. package/build/bdd-framework/gen/testNode.js +19 -6
  26. package/build/bdd-framework/gen/testPoms.js +49 -39
  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/playwright/fixtureParameterNames.js +27 -11
  30. package/build/bdd-framework/playwright/getLocationInFile.js +17 -11
  31. package/build/bdd-framework/playwright/loadConfig.js +3 -3
  32. package/build/bdd-framework/playwright/testTypeImpl.js +19 -15
  33. package/build/bdd-framework/playwright/transform.js +10 -6
  34. package/build/bdd-framework/playwright/utils.js +3 -6
  35. package/build/bdd-framework/run/StepInvoker.js +73 -0
  36. package/build/bdd-framework/run/bddFixtures.js +119 -57
  37. package/build/bdd-framework/run/bddWorld.js +24 -36
  38. package/build/bdd-framework/snippets/index.js +5 -4
  39. package/build/bdd-framework/snippets/snippetSyntax.js +3 -1
  40. package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
  41. package/build/bdd-framework/stepDefinitions/createBdd.js +30 -13
  42. package/build/bdd-framework/stepDefinitions/decorators/{poms.js → class.js} +13 -9
  43. package/build/bdd-framework/stepDefinitions/decorators/steps.js +14 -9
  44. package/build/bdd-framework/stepDefinitions/defineStep.js +5 -4
  45. package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
  46. package/build/bdd-framework/utils/exit.js +26 -18
  47. package/build/bdd-framework/utils/index.js +30 -4
  48. package/build/bdd-framework/utils/jsStringWrap.js +9 -9
  49. package/build/bdd-framework/utils/logger.js +6 -5
  50. package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
  51. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  52. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  53. package/build/core/playwright/builtInFixtures/context.js +15 -0
  54. package/build/core/playwright/builtInFixtures/index.js +26 -0
  55. package/build/core/playwright/builtInFixtures/page.js +51 -0
  56. package/build/core/playwright/clear-caches.js +29 -0
  57. package/build/core/playwright/custom-commands.js +1 -2
  58. package/build/core/playwright/index.js +7 -77
  59. package/build/core/playwright/readConfigFile.js +38 -32
  60. package/build/core/playwright/report-generator.js +2 -1
  61. package/build/core/playwright/setup/config-creator.js +48 -24
  62. package/build/core/playwright/setup/config-utils.js +30 -0
  63. package/build/core/playwright/setup/custom-reporter.js +109 -0
  64. package/build/core/playwright/tag-processor.js +68 -0
  65. package/build/core/playwright/test-runner.js +9 -15
  66. package/build/index.d.ts +60 -5
  67. package/build/index.js +18 -12
  68. package/build/lib/cli.js +10 -1
  69. package/build/parser/parser.js +0 -1
  70. package/build/parser/sample.feature +34 -34
  71. package/build/parser/sample.spec.js +18 -18
  72. package/build/setup-folder-structure/helper.js +35 -0
  73. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  74. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  75. package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
  76. package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
  77. package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
  78. package/build/setup-folder-structure/samples/git-ignore.sample.js +36 -32
  79. package/build/setup-folder-structure/samples/uat-config-sample.js +44 -43
  80. package/build/setup-folder-structure/setupProject.js +10 -5
  81. package/build/utils/cliArgsToObject.js +29 -25
  82. package/build/utils/fileUtils.js +15 -4
  83. package/build/utils/logger.js +1 -2
  84. package/build/utils/stepDefinitionsFormatter.js +1 -2
  85. package/changelog.md +137 -74
  86. package/jest.config.js +63 -63
  87. package/npm-shrinkwrap.json +6469 -7215
  88. package/package.json +55 -54
  89. package/playwright.config.js +112 -112
  90. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  91. package/build/bdd-framework/gen/poms.js +0 -46
  92. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -109
  93. package/build/bdd-poc/core-runner/exportMethods.js +0 -20
  94. package/build/bdd-poc/core-runner/stepDefinitions.js +0 -53
  95. package/build/bdd-poc/main.js +0 -10
  96. package/build/bdd-poc/runner.js +0 -19
  97. package/build/bdd-poc/test/cucumber/featureFileParer.js +0 -80
  98. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +0 -35
  99. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +0 -44
  100. package/build/bdd-poc/test/testDataMap.js +0 -98
  101. package/build/bdd-poc/test/testStructure.js +0 -82
  102. package/build/bdd-poc/utils/stringManipulation.js +0 -19
package/.babelrc CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "targets": {
7
- "node": "14"
8
- },
9
- "exclude": ["@babel/plugin-transform-destructuring"]
10
- }
11
- ]
12
- ],
13
- "plugins": [
14
- ["@babel/plugin-transform-runtime"]
15
- ],
16
- "ignore": [
17
- "./src/setup-folder-structure/samples"
18
- ]
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "14"
8
+ },
9
+ "exclude": ["@babel/plugin-transform-destructuring"]
10
+ }
11
+ ]
12
+ ],
13
+ "plugins": [
14
+ ["@babel/plugin-transform-runtime"]
15
+ ],
16
+ "ignore": [
17
+ "./src/setup-folder-structure/samples"
18
+ ]
19
19
  }
package/.eslintrc.js CHANGED
@@ -1,27 +1,31 @@
1
- module.exports = {
2
- "env": {
3
- "node": true,
4
- "es2021": true
5
- },
6
- "extends": "eslint:recommended",
7
- "overrides": [
8
- {
9
- "env": {
10
- "node": true
11
- },
12
- "files": [
13
- ".eslintrc.{js,cjs}"
14
- ],
15
- "parserOptions": {
16
- "sourceType": "script"
17
- }
18
- }
19
- ],
20
- "parserOptions": {
21
- "ecmaVersion": "latest",
22
- "sourceType": "module"
23
- },
24
- "rules": {
25
- "indent": ["error", 2]
26
- }
27
- }
1
+ module.exports = {
2
+ "env": {
3
+ "node": true,
4
+ "es2021": true
5
+ },
6
+ "extends": "eslint:recommended",
7
+ "overrides": [
8
+ {
9
+ "env": {
10
+ "node": true
11
+ },
12
+ "files": [
13
+ ".eslintrc.{js,cjs}"
14
+ ],
15
+ "parserOptions": {
16
+ "sourceType": "script"
17
+ }
18
+ }
19
+ ],
20
+ "parserOptions": {
21
+ "ecmaVersion": "latest",
22
+ "sourceType": "module"
23
+ },
24
+ "rules": {
25
+ "indent": ["error", 2, { "SwitchCase": 1 }],
26
+ "no-empty-pattern": "off",
27
+ "comma-dangle": ["error", "never"],
28
+ "curly": ["error"],
29
+ "brace-style": "error"
30
+ }
31
+ }
package/.prettierrc CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "trailingComma": "none",
3
- "singleQuote": true,
4
- "arrowParens": "avoid",
5
- "jsxSingleQuote": true
1
+ {
2
+ "trailingComma": "none",
3
+ "singleQuote": true,
4
+ "arrowParens": "avoid",
5
+ "jsxSingleQuote": true
6
6
  }
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
- # Testing Framework
2
-
3
- ## Framework that abstracts the configuration for playwright and Jest
4
-
5
- - Playwright
6
- - Jest
7
-
8
- ## Cli
9
-
10
- ## Feature Supported
11
-
12
- ### Run TestCase
13
-
14
- - npm run test
15
- ### Generate Report
16
-
17
- - npm run report
1
+ # Testing Framework
2
+
3
+ ## Framework that abstracts the configuration for playwright and Jest
4
+
5
+ - Playwright
6
+ - Jest
7
+
8
+ ## Cli
9
+
10
+ ## Feature Supported
11
+
12
+ ### Run TestCase
13
+
14
+ - npm run test
15
+ ### Generate Report
16
+
17
+ - npm run report
18
18
 
package/bin/cli.js CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
2
-
1
+ #!/usr/bin/env node
2
+
3
3
  require('../build/lib/cli');
@@ -15,7 +15,7 @@ var _loadConfig = require("../../playwright/loadConfig");
15
15
  const logger = new _logger.Logger({
16
16
  verbose: true
17
17
  });
18
- const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
18
+ const envCommand = exports.envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
19
19
  logger.log(`Playwright-bdd environment info:\n`);
20
20
  logger.log(`platform: ${process.platform}`);
21
21
  logger.log(`node: ${process.version}`);
@@ -24,17 +24,16 @@ const envCommand = new _commander.Command('env').description('Prints environment
24
24
  showPackageVersion('@cucumber/cucumber');
25
25
  showPlaywrightConfigPath(opts.config);
26
26
  });
27
- exports.envCommand = envCommand;
28
27
  function showPackageVersion(packageName) {
29
28
  const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
30
29
  logger.log(`${packageName}: v${version}`);
31
30
  }
32
- /**
33
- * Getting own version by relative path instead of using getPackageVersion(),
34
- * to aneble using directly from /dist in tests.
31
+ /**
32
+ * Getting own version by relative path instead of using getPackageVersion(),
33
+ * to aneble using directly from /dist in tests.
35
34
  */
36
35
  function getOwnVersion() {
37
- return '5.4.0';
36
+ return '5.6.0';
38
37
  }
39
38
  function showPlaywrightConfigPath(cliConfigPath) {
40
39
  const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
@@ -16,7 +16,7 @@ var _gen = require("../../gen");
16
16
  const logger = new _logger.Logger({
17
17
  verbose: true
18
18
  });
19
- const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
19
+ const exportCommand = exports.exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
20
20
  const {
21
21
  resolvedConfigFile
22
22
  } = await (0, _loadConfig.loadConfig)(opts.config);
@@ -25,7 +25,6 @@ const exportCommand = new _commander.Command('export').description('Prints all s
25
25
  (0, _test.assertConfigsCount)(configs);
26
26
  await showStepsForConfigs(configs);
27
27
  });
28
- exports.exportCommand = exportCommand;
29
28
  async function showStepsForConfigs(configs) {
30
29
  // here we don't need workers (as in test command) because if some step files
31
30
  // are already in node cache, we collected them.
@@ -17,13 +17,12 @@ var _config = require("../../config");
17
17
  var _options = require("../options");
18
18
  var _exit = require("../../utils/exit");
19
19
  const GEN_WORKER_PATH = _path.default.resolve(__dirname, '..', 'worker.js');
20
- const testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
20
+ const testCommand = exports.testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
21
21
  await (0, _loadConfig.loadConfig)(opts.config);
22
22
  const configs = readConfigsFromEnv();
23
23
  mergeCliOptions(configs, opts);
24
24
  await generateFilesForConfigs(configs);
25
25
  });
26
- exports.testCommand = testCommand;
27
26
  function readConfigsFromEnv() {
28
27
  const configs = Object.values((0, _env.getEnvConfigs)());
29
28
  assertConfigsCount(configs);
@@ -31,8 +30,12 @@ function readConfigsFromEnv() {
31
30
  }
32
31
  function mergeCliOptions(configs, opts) {
33
32
  configs.forEach(config => {
34
- if ('tags' in opts) config.tags = opts.tags;
35
- if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
33
+ if ('tags' in opts) {
34
+ config.tags = opts.tags;
35
+ }
36
+ if ('verbose' in opts) {
37
+ config.verbose = Boolean(opts.verbose);
38
+ }
36
39
  });
37
40
  }
38
41
  function assertConfigsCount(configs) {
@@ -6,15 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.configOption = void 0;
7
7
  exports.getCliConfigPath = getCliConfigPath;
8
8
  var _commander = require("commander");
9
- /**
10
- * Config option moved to separate file as it used in test run.
9
+ /**
10
+ * Config option moved to separate file as it used in test run.
11
11
  */
12
12
 
13
- const configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
14
- /**
15
- * Helper used in test run to detect config location.
13
+ const configOption = exports.configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
14
+ /**
15
+ * Helper used in test run to detect config location.
16
16
  */
17
- exports.configOption = configOption;
18
17
  function getCliConfigPath() {
19
18
  return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
20
19
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  var _worker_threads = require("worker_threads");
4
4
  var _gen = require("../gen");
5
- /**
6
- * Worker to generate test files with fresh require/import cache
7
- * See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
5
+ /**
6
+ * Worker to generate test files with fresh require/import cache
7
+ * See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
8
8
  */
9
9
 
10
10
  async function main() {
@@ -8,14 +8,14 @@ exports.getPlaywrightConfigDir = getPlaywrightConfigDir;
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _loadConfig = require("../playwright/loadConfig");
10
10
  var _options = require("../cli/options");
11
- /**
12
- * Store playwright config dir in env to provide access to it in workers.
13
- * Important that in workers there is different process.argv, that's why we save it to env.
14
- * Config dir is needed to resolve all paths.
11
+ /**
12
+ * Store playwright config dir in env to provide access to it in workers.
13
+ * Important that in workers there is different process.argv, that's why we save it to env.
14
+ * Config dir is needed to resolve all paths.
15
15
  */
16
16
 
17
- /**
18
- * Resolve playwright config dir considering cli flags.
17
+ /**
18
+ * Resolve playwright config dir considering cli flags.
19
19
  */
20
20
  function getPlaywrightConfigDir() {
21
21
  if (!process.env.PLAYWRIGHT_BDD_CONFIG_DIR) {
@@ -9,9 +9,9 @@ exports.getEnvConfigs = getEnvConfigs;
9
9
  exports.saveConfigToEnv = saveConfigToEnv;
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
  var _exit = require("../utils/exit");
12
- /**
13
- * Storing configs in env var PLAYWRIGHT_BDD_CONFIGS as JSON-stringified values.
14
- * For passing configs to playwright workers and bddgen.
12
+ /**
13
+ * Storing configs in env var PLAYWRIGHT_BDD_CONFIGS as JSON-stringified values.
14
+ * For passing configs to playwright workers and bddgen.
15
15
  */
16
16
 
17
17
  function saveConfigToEnv(config) {
@@ -34,7 +34,8 @@ function getConfigFromEnv(outputDir) {
34
34
  outputDir = _path.default.resolve(outputDir);
35
35
  const config = envConfigs[outputDir];
36
36
  if (!config) {
37
- (0, _exit.exit)(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
37
+ // exit(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
38
+ return {};
38
39
  }
39
40
  return config;
40
41
  }
@@ -11,18 +11,17 @@ var _path = _interopRequireDefault(require("path"));
11
11
  var _env = require("./env");
12
12
  var _dir = require("./dir");
13
13
  var _utils = require("../utils");
14
- /**
15
- * BDD Config.
14
+ /**
15
+ * BDD Config.
16
16
  */
17
17
 
18
- const defaults = {
18
+ const defaults = exports.defaults = {
19
19
  outputDir: '.features-gen',
20
20
  verbose: false,
21
21
  examplesTitleFormat: 'Example #<_index_>',
22
22
  publishQuiet: true,
23
23
  quotes: 'double'
24
24
  };
25
- exports.defaults = defaults;
26
25
  function defineBddConfig(inputConfig) {
27
26
  const config = getConfig(inputConfig);
28
27
  // In main process store config in env to be accessible by workers
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LANG_EN = void 0;
7
+ exports.isEnglish = isEnglish;
8
+ /**
9
+ * Helpers for Cucumber language option.
10
+ */
11
+ const LANG_EN = exports.LANG_EN = 'en';
12
+ function isEnglish(lang) {
13
+ return !lang || lang === LANG_EN;
14
+ }
@@ -8,9 +8,9 @@ exports.buildStepDefinition = buildStepDefinition;
8
8
  var _messages = require("@cucumber/messages");
9
9
  var _cucumberExpressions = require("@cucumber/cucumber-expressions");
10
10
  var _step_definition = _interopRequireDefault(require("@cucumber/cucumber/lib/models/step_definition"));
11
- /**
12
- * Extracted from cucumber SupportCodeLibraryBuilder.
13
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
11
+ /**
12
+ * Extracted from cucumber SupportCodeLibraryBuilder.
13
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
14
14
  */
15
15
 
16
16
  const newId = _messages.IdGenerator.uuid();
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.loadSnippetBuilder = loadSnippetBuilder;
7
7
  var _cucumber = require("@cucumber/cucumber");
8
- /**
9
- * Loads snippet builder
10
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/builder.ts
8
+ /**
9
+ * Loads snippet builder
10
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/builder.ts
11
11
  */
12
12
 
13
13
  async function loadSnippetBuilder(supportCodeLibrary, snippetInterface, snippetSyntax) {
@@ -9,17 +9,17 @@ var _messages = require("@cucumber/messages");
9
9
  var _environment = require("@cucumber/cucumber/lib/api/environment");
10
10
  var _gherkin = require("@cucumber/cucumber/lib/api/gherkin");
11
11
  var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
12
- /**
13
- * Copied from original load_sources, but returns full Pickles.
14
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
12
+ /**
13
+ * Copied from original load_sources, but returns full Pickles.
14
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
15
15
  */
16
16
 
17
- /**
18
- * Load and parse features, produce a filtered and ordered test plan and/or parse errors.
19
- *
20
- * @public
21
- * @param coordinates - Coordinates required to find features
22
- * @param environment - Project environment.
17
+ /**
18
+ * Load and parse features, produce a filtered and ordered test plan and/or parse errors.
19
+ *
20
+ * @public
21
+ * @param coordinates - Coordinates required to find features
22
+ * @param environment - Project environment.
23
23
  */
24
24
  async function loadSources(coordinates, environment = {}) {
25
25
  const {
@@ -25,9 +25,14 @@ function findStepDefinition(supportCodeLibrary, stepText, file) {
25
25
  const matchedSteps = supportCodeLibrary.stepDefinitions.filter(step => {
26
26
  return step.matchesStepName(stepText);
27
27
  });
28
- if (matchedSteps.length === 0) return;
29
- if (matchedSteps.length > 1) (0, _exit.exit)([`Several step definitions found for text: ${stepText} (${file})`, ...matchedSteps.map(s => `- ${s.pattern}`)].join('\n'));
30
- // todo: check stepDefinition.keyword with PickleStepType
28
+ if (matchedSteps.length === 0) {
29
+ return;
30
+ }
31
+ if (matchedSteps.length > 1) {
32
+ (0, _exit.exit)([`Multiple step definitions matched for text: "${stepText}" (${file})`,
33
+ // todo: print location of every step definition (as in cucumber)
34
+ ...matchedSteps.map(s => ` ${s.pattern}`)].join('\n'));
35
+ }
31
36
  return matchedSteps[0];
32
37
  }
33
38
  function hasTsNodeRegister(runConfiguration) {
@@ -6,17 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "Fixture", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _poms.Fixture;
9
+ return _class.Fixture;
10
10
  }
11
11
  });
12
12
  exports.When = exports.Then = exports.Step = exports.Given = void 0;
13
- var _poms = require("./stepDefinitions/decorators/poms");
13
+ var _class = require("./stepDefinitions/decorators/class");
14
14
  var _steps = require("./stepDefinitions/decorators/steps");
15
- const Given = (0, _steps.createStepDecorator)('Given');
16
- exports.Given = Given;
17
- const When = (0, _steps.createStepDecorator)('When');
18
- exports.When = When;
19
- const Then = (0, _steps.createStepDecorator)('Then');
20
- exports.Then = Then;
21
- const Step = (0, _steps.createStepDecorator)('Unknown');
22
- exports.Step = Step;
15
+ const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
16
+ const When = exports.When = (0, _steps.createStepDecorator)('When');
17
+ const Then = exports.Then = (0, _steps.createStepDecorator)('Then');
18
+ const Step = exports.Step = (0, _steps.createStepDecorator)('Unknown');
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.extractFixtureNames = extractFixtureNames;
7
+ exports.extractFixtureNamesFromFnBodyMemo = extractFixtureNamesFromFnBodyMemo;
8
+ var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
9
+ var _bddFixtures = require("../run/bddFixtures");
10
+ var _exit = require("../utils/exit");
11
+ const bodyFixturesSymbol = Symbol('bodyFixtures');
12
+ /**
13
+ * This function is used for playwright-style steps and decorators.
14
+ * It extracts fixtures names from first parameter of function
15
+ * using Playwright's helper.
16
+ */
17
+ function extractFixtureNames(fn) {
18
+ return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
19
+ }
20
+ /**
21
+ * This function is used for cucumber-style steps.
22
+ * It looks for `this.useFixture('xxx')` entries in function body
23
+ * and extracts fixtures names from it.
24
+ */
25
+ function extractFixtureNamesFromFnBodyMemo(fn) {
26
+ if (typeof fn !== 'function') {
27
+ return [];
28
+ }
29
+ const fnWithFixtures = fn;
30
+ if (!fnWithFixtures[bodyFixturesSymbol]) {
31
+ fnWithFixtures[bodyFixturesSymbol] = extractFixtureNamesFromFnBody(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
32
+ }
33
+ return fnWithFixtures[bodyFixturesSymbol];
34
+ }
35
+ function extractFixtureNamesFromFnBody(fn) {
36
+ const matches = fn.toString().matchAll(/this\.useFixture\((.+)\)/gi) || [];
37
+ return [...matches].map(match => getFixtureName(match[1]));
38
+ }
39
+ function getFixtureName(arg) {
40
+ if (!/^['"`]/.test(arg)) {
41
+ // todo: log file location with incorrect useFixture
42
+ (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
43
+ }
44
+ if (arg.startsWith('`') && arg.includes('${')) {
45
+ (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
46
+ }
47
+ return arg.replace(/['"`]/g, '');
48
+ }
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Formatter = void 0;
7
7
  var _jsStringWrap = require("../utils/jsStringWrap");
8
- /**
9
- * Helper to format Playwright test file.
8
+ /**
9
+ * Helper to format Playwright test file.
10
10
  */
11
11
 
12
12
  const TAGS_FIXTURE_TEST_KEY_SEPARATOR = '|';
@@ -18,14 +18,20 @@ class Formatter {
18
18
  fileHeader(uri, importTestFrom) {
19
19
  const file = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary';
20
20
  let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
21
- if (varName !== 'test') varName = `${varName} as test`;
21
+ if (varName !== 'test') {
22
+ varName = `${varName} as test`;
23
+ }
22
24
  return [`/** Generated from: ${uri} */`,
25
+ // prettier-ignore
23
26
  // this.quoted() is not possible for 'import from' as backticks not parsed
24
27
  `import { ${varName} } from ${JSON.stringify(file)};`, ''];
25
28
  }
26
29
  suite(node, children) {
27
- // prettier-ignore
28
- return [`test.describe${this.getSubFn(node)}(${this.quoted(node.title)}, () => {`, '', ...children.map(indent), `});`, ''];
30
+ const firstLine = `test.describe${this.getSubFn(node)}(${this.quoted(node.title)}, () => {`;
31
+ if (!children.length) {
32
+ return [`${firstLine}});`, ''];
33
+ }
34
+ return [firstLine, '', ...children.map(indent), `});`, ''];
29
35
  }
30
36
  beforeEach(fixtures, children) {
31
37
  const fixturesStr = [...fixtures].join(', ');
@@ -34,8 +40,12 @@ class Formatter {
34
40
  }
35
41
  test(node, fixtures, children) {
36
42
  const fixturesStr = [...fixtures].join(', ');
37
- // prettier-ignore
38
- return [`test${this.getSubFn(node)}(${this.quoted(node.title)}, async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
43
+ const title = this.quoted([node.title, ...node.tags].join(' '));
44
+ const firstLine = `test${this.getSubFn(node)}(${title}, async ({ ${fixturesStr} }) => {`;
45
+ if (!children.length) {
46
+ return [`${firstLine}});`, ''];
47
+ }
48
+ return [firstLine, ...children.map(indent), `});`, ''];
39
49
  }
40
50
  // eslint-disable-next-line max-params
41
51
  step(keyword, text, argument, fixtureNames = []) {
@@ -49,32 +59,69 @@ class Formatter {
49
59
  return `// missing step: ${keyword}(${this.quoted(text)});`;
50
60
  }
51
61
  useFixtures(fixtures) {
52
- return fixtures.length > 0 ? ['// == technical section ==', '', 'test.use({', ...fixtures.map(indent), '});'] : [];
62
+ return fixtures.length > 0 ? ['// == technical section ==',
63
+ // prettier-ignore
64
+ '', 'test.use({', ...fixtures.map(indent), '});'] : [];
53
65
  }
54
66
  testFixture() {
55
67
  return ['$test: ({}, use) => use(test),'];
56
68
  }
69
+ bddWorldFixtures() {
70
+ const fixturesObj = {
71
+ page: null,
72
+ context: null,
73
+ browser: null,
74
+ browserName: null,
75
+ request: null
76
+ };
77
+ const fixtures = Object.keys(fixturesObj).join(', ');
78
+ return [`$bddWorldFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
79
+ }
57
80
  tagsFixture(testNodes) {
58
81
  const lines = testNodes.filter(node => node.tags.length).map(node => {
59
82
  // remove first parent as it is the same for all tests: root suite
60
- const key = node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR);
83
+ const key = `${node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR)} ${node.tags.join(" ")}`;
61
84
  return `${JSON.stringify(key)}: ${JSON.stringify(node.tags)},`;
62
85
  });
63
86
  return lines.length > 0 ? ['$tags: ({}, use, testInfo) => use({', ...lines.map(indent),
64
87
  // .slice(2) -> b/c we remove filename and root suite title
65
88
  `}[testInfo.titlePath.slice(2).join(${JSON.stringify(TAGS_FIXTURE_TEST_KEY_SEPARATOR)})] || []),`] : [];
66
89
  }
90
+ scenarioHookFixtures(fixtureNames) {
91
+ if (!fixtureNames.length) {
92
+ return [];
93
+ }
94
+ const fixtures = fixtureNames.join(', ');
95
+ return [`$scenarioHookFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
96
+ }
97
+ workerHookFixtures(fixtureNames) {
98
+ if (!fixtureNames.length) {
99
+ return [];
100
+ }
101
+ const fixtures = fixtureNames.join(', ');
102
+ const scope = this.quoted('worker');
103
+ return [`$workerHookFixtures: [({ ${fixtures} }, use) => use({ ${fixtures} }), { scope: ${scope} }],`];
104
+ }
105
+ langFixture(lang) {
106
+ return [`$lang: ({}, use) => use(${this.quoted(lang)}),`];
107
+ }
67
108
  getSubFn(node) {
68
- if (node.flags.only) return '.only';
69
- if (node.flags.skip) return '.skip';
70
- if (node.flags.fixme) return '.fixme';
109
+ if (node.flags.only) {
110
+ return '.only';
111
+ }
112
+ if (node.flags.skip) {
113
+ return '.skip';
114
+ }
115
+ if (node.flags.fixme) {
116
+ return '.fixme';
117
+ }
71
118
  return '';
72
119
  }
73
- /**
74
- * Apply this function only to string literals (mostly titles here).
75
- * Objects and arrays are handled with JSON.strinigfy,
76
- * b/c object keys can't be in backtiks.
77
- * See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
120
+ /**
121
+ * Apply this function only to string literals (mostly titles here).
122
+ * Objects and arrays are handled with JSON.strinigfy,
123
+ * b/c object keys can't be in backtiks.
124
+ * See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
78
125
  */
79
126
  quoted(str) {
80
127
  return (0, _jsStringWrap.jsStringWrap)(str, {