@zohodesk/testinglibrary 0.1.7 → 0.1.8-exp-bdd

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 (91) hide show
  1. package/.babelrc +18 -18
  2. package/.eslintrc.js +27 -31
  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 +2 -6
  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 +4 -5
  12. package/build/bdd-framework/config/index.js +2 -2
  13. package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
  14. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  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 +3 -8
  18. package/build/bdd-framework/decorators.js +2 -2
  19. package/build/bdd-framework/gen/formatter.js +17 -64
  20. package/build/bdd-framework/gen/i18n.js +5 -9
  21. package/build/bdd-framework/gen/index.js +8 -9
  22. package/build/bdd-framework/gen/poms.js +46 -0
  23. package/build/bdd-framework/gen/testFile.js +55 -121
  24. package/build/bdd-framework/gen/testNode.js +6 -19
  25. package/build/bdd-framework/gen/testPoms.js +39 -49
  26. package/build/bdd-framework/playwright/fixtureParameterNames.js +11 -27
  27. package/build/bdd-framework/playwright/getLocationInFile.js +11 -17
  28. package/build/bdd-framework/playwright/loadConfig.js +3 -3
  29. package/build/bdd-framework/playwright/testTypeImpl.js +15 -19
  30. package/build/bdd-framework/playwright/transform.js +6 -10
  31. package/build/bdd-framework/playwright/utils.js +6 -3
  32. package/build/bdd-framework/run/bddFixtures.js +55 -118
  33. package/build/bdd-framework/run/bddWorld.js +36 -24
  34. package/build/bdd-framework/snippets/index.js +3 -5
  35. package/build/bdd-framework/snippets/snippetSyntax.js +1 -3
  36. package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
  37. package/build/bdd-framework/stepDefinitions/createBdd.js +13 -30
  38. package/build/bdd-framework/stepDefinitions/createDecorators.js +108 -0
  39. package/build/bdd-framework/stepDefinitions/decorators/{class.js → poms.js} +9 -13
  40. package/build/bdd-framework/stepDefinitions/decorators/steps.js +8 -14
  41. package/build/bdd-framework/stepDefinitions/defineStep.js +4 -5
  42. package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
  43. package/build/bdd-framework/utils/exit.js +18 -26
  44. package/build/bdd-framework/utils/index.js +4 -30
  45. package/build/bdd-framework/utils/jsStringWrap.js +9 -9
  46. package/build/bdd-framework/utils/logger.js +3 -5
  47. package/build/bdd-poc/core-runner/exportMethods.js +14 -0
  48. package/build/bdd-poc/core-runner/stepDefinitions.js +55 -0
  49. package/build/bdd-poc/main.js +10 -0
  50. package/build/bdd-poc/test/cucumber/featureFileParer.js +81 -0
  51. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +36 -0
  52. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +43 -0
  53. package/build/bdd-poc/test/testDataMap.js +98 -0
  54. package/build/bdd-poc/test/testStructure.js +83 -0
  55. package/build/bdd-poc/utils/stringManipulation.js +19 -0
  56. package/build/core/playwright/custom-commands.js +1 -1
  57. package/build/core/playwright/index.js +0 -15
  58. package/build/core/playwright/readConfigFile.js +30 -37
  59. package/build/core/playwright/report-generator.js +1 -2
  60. package/build/core/playwright/setup/config-creator.js +15 -21
  61. package/build/core/playwright/setup/config-utils.js +0 -30
  62. package/build/core/playwright/test-runner.js +5 -7
  63. package/build/index.d.ts +5 -60
  64. package/build/index.js +3 -5
  65. package/build/lib/cli.js +1 -10
  66. package/build/parser/sample.feature +34 -34
  67. package/build/parser/sample.spec.js +18 -18
  68. package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
  69. package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
  70. package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
  71. package/build/setup-folder-structure/samples/git-ignore.sample.js +32 -36
  72. package/build/setup-folder-structure/samples/uat-config-sample.js +43 -44
  73. package/build/setup-folder-structure/setupProject.js +5 -10
  74. package/build/utils/cliArgsToObject.js +25 -25
  75. package/build/utils/fileUtils.js +0 -12
  76. package/changelog.md +74 -124
  77. package/jest.config.js +63 -63
  78. package/npm-shrinkwrap.json +7781 -6469
  79. package/package.json +54 -55
  80. package/playwright.config.js +112 -112
  81. package/build/bdd-framework/config/lang.js +0 -14
  82. package/build/bdd-framework/gen/fixtures.js +0 -48
  83. package/build/bdd-framework/hooks/scenario.js +0 -107
  84. package/build/bdd-framework/hooks/worker.js +0 -83
  85. package/build/bdd-framework/run/StepInvoker.js +0 -73
  86. package/build/core/playwright/clear-caches.js +0 -29
  87. package/build/core/playwright/setup/custom-reporter.js +0 -100
  88. package/build/core/playwright/tag-processor.js +0 -68
  89. package/build/setup-folder-structure/helper.js +0 -34
  90. package/build/setup-folder-structure/reportEnhancement/addonScript.html +0 -25
  91. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +0 -25
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,31 +1,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
- }
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
+ }
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.6.0';
36
+ return '5.4.0';
37
37
  }
38
38
  function showPlaywrightConfigPath(cliConfigPath) {
39
39
  const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
@@ -30,12 +30,8 @@ function readConfigsFromEnv() {
30
30
  }
31
31
  function mergeCliOptions(configs, opts) {
32
32
  configs.forEach(config => {
33
- if ('tags' in opts) {
34
- config.tags = opts.tags;
35
- }
36
- if ('verbose' in opts) {
37
- config.verbose = Boolean(opts.verbose);
38
- }
33
+ if ('tags' in opts) config.tags = opts.tags;
34
+ if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
39
35
  });
40
36
  }
41
37
  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,8 +34,7 @@ function getConfigFromEnv(outputDir) {
34
34
  outputDir = _path.default.resolve(outputDir);
35
35
  const config = envConfigs[outputDir];
36
36
  if (!config) {
37
- // exit(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
38
- return {};
37
+ (0, _exit.exit)(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
39
38
  }
40
39
  return config;
41
40
  }
@@ -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 = {
@@ -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();
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copied from @cucumber/cucumber/lib/api/gherkin.d.ts
3
+ * Fixes error:
4
+ * Return type of exported function has or is using name 'PickleWithDocument'
5
+ * from external module "../node_modules/@cucumber/cucumber/lib/api/gherkin"
6
+ * but cannot be named
7
+ */
8
+ import {
9
+ Envelope,
10
+ GherkinDocument,
11
+ IdGenerator,
12
+ Location,
13
+ ParseError,
14
+ Pickle,
15
+ } from '@cucumber/messages';
16
+ import { ISourcesCoordinates } from '@cucumber/cucumber/lib/api/types';
17
+ import { ILogger } from '@cucumber/cucumber/lib/logger';
18
+
19
+ declare module '@cucumber/cucumber/lib/api/gherkin' {
20
+ export interface PickleWithDocument {
21
+ gherkinDocument: GherkinDocument;
22
+ location: Location;
23
+ pickle: Pickle;
24
+ }
25
+ export function getFilteredPicklesAndErrors({
26
+ newId,
27
+ cwd,
28
+ logger,
29
+ unexpandedFeaturePaths,
30
+ featurePaths,
31
+ coordinates,
32
+ onEnvelope,
33
+ }: {
34
+ newId: IdGenerator.NewId;
35
+ cwd: string;
36
+ logger: ILogger;
37
+ unexpandedFeaturePaths: string[];
38
+ featurePaths: string[];
39
+ coordinates: ISourcesCoordinates;
40
+ onEnvelope?: (envelope: Envelope) => void;
41
+ }): Promise<{
42
+ filteredPickles: PickleWithDocument[];
43
+ parseErrors: ParseError[];
44
+ }>;
45
+ }
@@ -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,14 +25,9 @@ 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) {
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
- }
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
36
31
  return matchedSteps[0];
37
32
  }
38
33
  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 _class.Fixture;
9
+ return _poms.Fixture;
10
10
  }
11
11
  });
12
12
  exports.When = exports.Then = exports.Step = exports.Given = void 0;
13
- var _class = require("./stepDefinitions/decorators/class");
13
+ var _poms = require("./stepDefinitions/decorators/poms");
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');
@@ -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,20 +18,14 @@ 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') {
22
- varName = `${varName} as test`;
23
- }
21
+ if (varName !== 'test') varName = `${varName} as test`;
24
22
  return [`/** Generated from: ${uri} */`,
25
- // prettier-ignore
26
23
  // this.quoted() is not possible for 'import from' as backticks not parsed
27
24
  `import { ${varName} } from ${JSON.stringify(file)};`, ''];
28
25
  }
29
26
  suite(node, children) {
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), `});`, ''];
27
+ // prettier-ignore
28
+ return [`test.describe${this.getSubFn(node)}(${this.quoted(node.title)}, () => {`, '', ...children.map(indent), `});`, ''];
35
29
  }
36
30
  beforeEach(fixtures, children) {
37
31
  const fixturesStr = [...fixtures].join(', ');
@@ -40,12 +34,8 @@ class Formatter {
40
34
  }
41
35
  test(node, fixtures, children) {
42
36
  const fixturesStr = [...fixtures].join(', ');
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), `});`, ''];
37
+ // prettier-ignore
38
+ return [`test${this.getSubFn(node)}(${this.quoted(node.title)}, async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
49
39
  }
50
40
  // eslint-disable-next-line max-params
51
41
  step(keyword, text, argument, fixtureNames = []) {
@@ -59,69 +49,32 @@ class Formatter {
59
49
  return `// missing step: ${keyword}(${this.quoted(text)});`;
60
50
  }
61
51
  useFixtures(fixtures) {
62
- return fixtures.length > 0 ? ['// == technical section ==',
63
- // prettier-ignore
64
- '', 'test.use({', ...fixtures.map(indent), '});'] : [];
52
+ return fixtures.length > 0 ? ['// == technical section ==', '', 'test.use({', ...fixtures.map(indent), '});'] : [];
65
53
  }
66
54
  testFixture() {
67
55
  return ['$test: ({}, use) => use(test),'];
68
56
  }
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
- }
80
57
  tagsFixture(testNodes) {
81
58
  const lines = testNodes.filter(node => node.tags.length).map(node => {
82
59
  // remove first parent as it is the same for all tests: root suite
83
- const key = `${node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR)} ${node.tags.join(" ")}`;
60
+ const key = node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR);
84
61
  return `${JSON.stringify(key)}: ${JSON.stringify(node.tags)},`;
85
62
  });
86
63
  return lines.length > 0 ? ['$tags: ({}, use, testInfo) => use({', ...lines.map(indent),
87
64
  // .slice(2) -> b/c we remove filename and root suite title
88
65
  `}[testInfo.titlePath.slice(2).join(${JSON.stringify(TAGS_FIXTURE_TEST_KEY_SEPARATOR)})] || []),`] : [];
89
66
  }
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
- }
108
67
  getSubFn(node) {
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
- }
68
+ if (node.flags.only) return '.only';
69
+ if (node.flags.skip) return '.skip';
70
+ if (node.flags.fixme) return '.fixme';
118
71
  return '';
119
72
  }
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
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
125
78
  */
126
79
  quoted(str) {
127
80
  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,14 +23,10 @@ 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') {
27
- return;
28
- }
26
+ if (typeof nativeKeywords === 'string') return;
29
27
  nativeKeywords.forEach(nativeKeyword => {
30
28
  nativeKeyword = nativeKeyword.trim();
31
- if (!nativeKeyword || nativeKeyword === '*') {
32
- return;
33
- }
29
+ if (!nativeKeyword || nativeKeyword === '*') return;
34
30
  targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
35
31
  });
36
32
  }
@@ -20,9 +20,8 @@ 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
- var _createBdd = require("../stepDefinitions/createBdd");
24
- /**
25
- * Generate playwright test files from Gherkin documents.
23
+ /**
24
+ * Generate playwright test files from Gherkin documents.
26
25
  */
27
26
 
28
27
  class TestFilesGenerator {
@@ -39,9 +38,7 @@ class TestFilesGenerator {
39
38
  this.logger = new _logger.Logger({
40
39
  verbose: config.verbose
41
40
  });
42
- if (config.tags) {
43
- this.tagsExpression = (0, _tagExpressions.default)(config.tags);
44
- }
41
+ if (config.tags) this.tagsExpression = (0, _tagExpressions.default)(config.tags);
45
42
  }
46
43
  async generate() {
47
44
  await (0, _exit.withExitHandler)(async () => {
@@ -49,7 +46,7 @@ class TestFilesGenerator {
49
46
  await Promise.all([this.loadFeatures(), this.loadSteps()]);
50
47
  this.buildFiles();
51
48
  await this.checkUndefinedSteps();
52
- this.checkImportTestFrom();
49
+ this.checkImportCustomTest();
53
50
  await this.clearOutputDir();
54
51
  await this.saveFiles();
55
52
  });
@@ -136,8 +133,10 @@ class TestFilesGenerator {
136
133
  (0, _exit.exit)();
137
134
  }
138
135
  }
139
- checkImportTestFrom() {
140
- if (_createBdd.hasCustomTest && !this.config.importTestFrom) {
136
+ checkImportCustomTest() {
137
+ if (this.config.importTestFrom) return;
138
+ const hasCustomTest = this.files.some(file => file.hasCustomTest);
139
+ if (hasCustomTest) {
141
140
  (0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
142
141
  }
143
142
  }