@zohodesk/testinglibrary 0.1.8-exp-bdd-v1 → 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 (97) 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 +4 -4
  7. package/build/bdd-framework/cli/commands/test.js +6 -2
  8. package/build/bdd-framework/cli/options.js +4 -4
  9. package/build/bdd-framework/cli/worker.js +3 -3
  10. package/build/bdd-framework/config/dir.js +6 -6
  11. package/build/bdd-framework/config/env.js +5 -4
  12. package/build/bdd-framework/config/index.js +2 -2
  13. package/build/bdd-framework/config/lang.js +14 -0
  14. package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
  15. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +3 -3
  16. package/build/bdd-framework/cucumber/loadSources.js +9 -9
  17. package/build/bdd-framework/cucumber/loadSteps.js +8 -3
  18. package/build/bdd-framework/decorators.js +2 -2
  19. package/build/bdd-framework/gen/fixtures.js +48 -0
  20. package/build/bdd-framework/gen/formatter.js +64 -17
  21. package/build/bdd-framework/gen/i18n.js +9 -5
  22. package/build/bdd-framework/gen/index.js +9 -8
  23. package/build/bdd-framework/gen/testFile.js +121 -55
  24. package/build/bdd-framework/gen/testNode.js +19 -6
  25. package/build/bdd-framework/gen/testPoms.js +49 -39
  26. package/build/bdd-framework/hooks/scenario.js +107 -0
  27. package/build/bdd-framework/hooks/worker.js +83 -0
  28. package/build/bdd-framework/playwright/fixtureParameterNames.js +27 -11
  29. package/build/bdd-framework/playwright/getLocationInFile.js +17 -11
  30. package/build/bdd-framework/playwright/loadConfig.js +3 -3
  31. package/build/bdd-framework/playwright/testTypeImpl.js +19 -15
  32. package/build/bdd-framework/playwright/transform.js +10 -6
  33. package/build/bdd-framework/playwright/utils.js +3 -6
  34. package/build/bdd-framework/run/StepInvoker.js +73 -0
  35. package/build/bdd-framework/run/bddFixtures.js +118 -55
  36. package/build/bdd-framework/run/bddWorld.js +24 -36
  37. package/build/bdd-framework/snippets/index.js +5 -3
  38. package/build/bdd-framework/snippets/snippetSyntax.js +3 -1
  39. package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
  40. package/build/bdd-framework/stepDefinitions/createBdd.js +30 -13
  41. package/build/bdd-framework/stepDefinitions/decorators/{poms.js → class.js} +13 -9
  42. package/build/bdd-framework/stepDefinitions/decorators/steps.js +14 -8
  43. package/build/bdd-framework/stepDefinitions/defineStep.js +5 -4
  44. package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
  45. package/build/bdd-framework/utils/exit.js +26 -18
  46. package/build/bdd-framework/utils/index.js +30 -4
  47. package/build/bdd-framework/utils/jsStringWrap.js +9 -9
  48. package/build/bdd-framework/utils/logger.js +5 -3
  49. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  50. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  51. package/build/core/playwright/builtInFixtures/context.js +15 -0
  52. package/build/core/playwright/builtInFixtures/index.js +26 -0
  53. package/build/core/playwright/builtInFixtures/page.js +51 -0
  54. package/build/core/playwright/clear-caches.js +29 -0
  55. package/build/core/playwright/custom-commands.js +1 -1
  56. package/build/core/playwright/index.js +6 -74
  57. package/build/core/playwright/readConfigFile.js +37 -30
  58. package/build/core/playwright/report-generator.js +2 -1
  59. package/build/core/playwright/setup/config-creator.js +43 -20
  60. package/build/core/playwright/setup/config-utils.js +30 -0
  61. package/build/core/playwright/setup/custom-reporter.js +109 -0
  62. package/build/core/playwright/tag-processor.js +68 -0
  63. package/build/core/playwright/test-runner.js +8 -12
  64. package/build/index.d.ts +60 -5
  65. package/build/index.js +18 -12
  66. package/build/lib/cli.js +10 -1
  67. package/build/parser/sample.feature +34 -34
  68. package/build/parser/sample.spec.js +18 -18
  69. package/build/setup-folder-structure/helper.js +35 -0
  70. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  71. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  72. package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
  73. package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
  74. package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
  75. package/build/setup-folder-structure/samples/git-ignore.sample.js +36 -32
  76. package/build/setup-folder-structure/samples/uat-config-sample.js +44 -43
  77. package/build/setup-folder-structure/setupProject.js +10 -5
  78. package/build/utils/cliArgsToObject.js +29 -25
  79. package/build/utils/fileUtils.js +15 -4
  80. package/changelog.md +137 -74
  81. package/jest.config.js +63 -63
  82. package/npm-shrinkwrap.json +6469 -7781
  83. package/package.json +55 -54
  84. package/playwright.config.js +112 -112
  85. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  86. package/build/bdd-framework/gen/poms.js +0 -46
  87. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -108
  88. package/build/bdd-poc/core-runner/exportMethods.js +0 -20
  89. package/build/bdd-poc/core-runner/stepDefinitions.js +0 -53
  90. package/build/bdd-poc/main.js +0 -10
  91. package/build/bdd-poc/runner.js +0 -19
  92. package/build/bdd-poc/test/cucumber/featureFileParer.js +0 -81
  93. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +0 -36
  94. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +0 -43
  95. package/build/bdd-poc/test/testDataMap.js +0 -98
  96. package/build/bdd-poc/test/testStructure.js +0 -83
  97. 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');
@@ -28,12 +28,12 @@ function showPackageVersion(packageName) {
28
28
  const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
29
29
  logger.log(`${packageName}: v${version}`);
30
30
  }
31
- /**
32
- * Getting own version by relative path instead of using getPackageVersion(),
33
- * 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.
34
34
  */
35
35
  function getOwnVersion() {
36
- return '5.4.0';
36
+ return '5.6.0';
37
37
  }
38
38
  function showPlaywrightConfigPath(cliConfigPath) {
39
39
  const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
@@ -30,8 +30,12 @@ function readConfigsFromEnv() {
30
30
  }
31
31
  function mergeCliOptions(configs, opts) {
32
32
  configs.forEach(config => {
33
- if ('tags' in opts) config.tags = opts.tags;
34
- 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
+ }
35
39
  });
36
40
  }
37
41
  function assertConfigsCount(configs) {
@@ -6,13 +6,13 @@ 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
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.
14
+ /**
15
+ * Helper used in test run to detect config location.
16
16
  */
17
17
  function getCliConfigPath() {
18
18
  return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
@@ -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,8 +11,8 @@ 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
18
  const defaults = exports.defaults = {
@@ -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,11 +6,11 @@ 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
15
  const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
16
16
  const When = exports.When = (0, _steps.createStepDecorator)('When');
@@ -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, {
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getKeywordsMap = getKeywordsMap;
7
7
  var _gherkin = require("@cucumber/gherkin");
8
- /**
9
- * Get i18n keywords.
10
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
8
+ /**
9
+ * Get i18n keywords.
10
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
11
11
  */
12
12
 
13
13
  function getKeywordsMap(language) {
@@ -23,10 +23,14 @@ function getKeywordsMap(language) {
23
23
  function handleKeyword(enKeyword, origMap, targetMap) {
24
24
  const nativeKeywords = origMap[enKeyword];
25
25
  // Array.isArray converts to any[]
26
- if (typeof nativeKeywords === 'string') return;
26
+ if (typeof nativeKeywords === 'string') {
27
+ return;
28
+ }
27
29
  nativeKeywords.forEach(nativeKeyword => {
28
30
  nativeKeyword = nativeKeyword.trim();
29
- if (!nativeKeyword || nativeKeyword === '*') return;
31
+ if (!nativeKeyword || nativeKeyword === '*') {
32
+ return;
33
+ }
30
34
  targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
31
35
  });
32
36
  }
@@ -20,8 +20,9 @@ var _dir = require("../config/dir");
20
20
  var _logger = require("../utils/logger");
21
21
  var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
22
22
  var _exit = require("../utils/exit");
23
- /**
24
- * Generate playwright test files from Gherkin documents.
23
+ var _createBdd = require("../stepDefinitions/createBdd");
24
+ /**
25
+ * Generate playwright test files from Gherkin documents.
25
26
  */
26
27
 
27
28
  class TestFilesGenerator {
@@ -38,7 +39,9 @@ class TestFilesGenerator {
38
39
  this.logger = new _logger.Logger({
39
40
  verbose: config.verbose
40
41
  });
41
- if (config.tags) this.tagsExpression = (0, _tagExpressions.default)(config.tags);
42
+ if (config.tags) {
43
+ this.tagsExpression = (0, _tagExpressions.default)(config.tags);
44
+ }
42
45
  }
43
46
  async generate() {
44
47
  await (0, _exit.withExitHandler)(async () => {
@@ -46,7 +49,7 @@ class TestFilesGenerator {
46
49
  await Promise.all([this.loadFeatures(), this.loadSteps()]);
47
50
  this.buildFiles();
48
51
  await this.checkUndefinedSteps();
49
- this.checkImportCustomTest();
52
+ this.checkImportTestFrom();
50
53
  await this.clearOutputDir();
51
54
  await this.saveFiles();
52
55
  });
@@ -133,10 +136,8 @@ class TestFilesGenerator {
133
136
  (0, _exit.exit)();
134
137
  }
135
138
  }
136
- checkImportCustomTest() {
137
- if (this.config.importTestFrom) return;
138
- const hasCustomTest = this.files.some(file => file.hasCustomTest);
139
- if (hasCustomTest) {
139
+ checkImportTestFrom() {
140
+ if (_createBdd.hasCustomTest && !this.config.importTestFrom) {
140
141
  (0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
141
142
  }
142
143
  }