@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
@@ -7,33 +7,27 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getLocationInFile = getLocationInFile;
8
8
  var _url = _interopRequireDefault(require("url"));
9
9
  var _utils = require("./utils");
10
- /**
11
- * Inspects stacktrace and finds call location in provided file.
12
- * This function is based on Playwright's getLocationByStacktrace().
13
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
10
+ /**
11
+ * Inspects stacktrace and finds call location in provided file.
12
+ * This function is based on Playwright's getLocationByStacktrace().
13
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
14
14
  */
15
15
  function getLocationInFile(filePath) {
16
- const filePathUrl = _url.default.pathToFileURL(filePath).toString();
17
16
  const {
18
17
  sourceMapSupport
19
18
  } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
20
19
  const oldPrepareStackTrace = Error.prepareStackTrace;
21
20
  Error.prepareStackTrace = (error, stackFrames) => {
22
- const frameInFile = stackFrames.find(frame => {
23
- const frameFile = frame.getFileName();
24
- return frameFile === filePath || frameFile === filePathUrl;
25
- });
26
- if (!frameInFile) {
27
- return {
28
- file: '',
29
- line: 0,
30
- column: 0
31
- };
32
- }
21
+ const frameInFile = stackFrames.find(frame => frame.getFileName() === filePath);
22
+ if (!frameInFile) return {
23
+ file: '',
24
+ line: 0,
25
+ column: 0
26
+ };
33
27
  const frame = sourceMapSupport.wrapCallSite(frameInFile);
34
28
  const fileName = frame.getFileName();
35
29
  // Node error stacks for modules use file:// urls instead of paths.
36
- const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
30
+ const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
37
31
  return {
38
32
  file,
39
33
  line: frame.getLineNumber(),
@@ -11,9 +11,9 @@ var _fs = _interopRequireDefault(require("fs"));
11
11
  var _utils = require("./utils");
12
12
  var _transform = require("./transform");
13
13
  var _exit = require("../utils/exit");
14
- /**
15
- * Loading Playwright config.
16
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/configLoader.ts
14
+ /**
15
+ * Loading Playwright config.
16
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/configLoader.ts
17
17
  */
18
18
 
19
19
  async function loadConfig(cliConfigPath) {
@@ -3,18 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isTestContainsSubtest = isTestContainsSubtest;
6
+ exports.isParentChildTest = isParentChildTest;
7
7
  exports.runStepWithCustomLocation = runStepWithCustomLocation;
8
8
  var _test = require("@playwright/test");
9
9
  var _utils = require("../utils");
10
- /**
11
- * Helpers to deal with Playwright test internal stuff.
12
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/testType.ts
10
+ /**
11
+ * Helpers to deal with Playwright test internal stuff.
12
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/testType.ts
13
13
  */
14
14
 
15
15
  const testTypeSymbol = (0, _utils.getSymbolByName)(_test.test, 'testType');
16
- /**
17
- * Returns test fixtures using Symbol.
16
+ /**
17
+ * Returns test fixtures using Symbol.
18
18
  */
19
19
  function getTestFixtures(test) {
20
20
  return getTestImpl(test).fixtures;
@@ -22,8 +22,8 @@ function getTestFixtures(test) {
22
22
  function getTestImpl(test) {
23
23
  return test[testTypeSymbol];
24
24
  }
25
- /**
26
- * Run step with location pointing to Given, When, Then call.
25
+ /**
26
+ * Run step with location pointing to Given, When, Then call.
27
27
  */
28
28
  // eslint-disable-next-line max-params
29
29
  async function runStepWithCustomLocation(test, stepText, location, body) {
@@ -38,18 +38,14 @@ async function runStepWithCustomLocation(test, stepText, location, body) {
38
38
  return await body();
39
39
  });
40
40
  }
41
- /**
42
- * Returns true if test contains all fixtures of subtest.
43
- * - test was extended from subtest
44
- * - test is a result of mergeTests(subtest, ...)
41
+ /**
42
+ * Returns true if all fixtures of parent test found in child test.
45
43
  */
46
- function isTestContainsSubtest(test, subtest) {
47
- if (test === subtest) {
48
- return true;
49
- }
50
- const testFixtures = new Set(getTestFixtures(test).map(f => locationToString(f.location)));
51
- return getTestFixtures(subtest).every(f => {
52
- return testFixtures.has(locationToString(f.location));
44
+ function isParentChildTest(parent, child) {
45
+ if (parent === child) return false;
46
+ const childLocationsSet = new Set(getTestFixtures(child).map(f => locationToString(f.location)));
47
+ return getTestFixtures(parent).every(f => {
48
+ return childLocationsSet.has(locationToString(f.location));
53
49
  });
54
50
  }
55
51
  function locationToString({
@@ -11,10 +11,10 @@ var _fs = _interopRequireDefault(require("fs"));
11
11
  var _path = _interopRequireDefault(require("path"));
12
12
  var _utils = require("./utils");
13
13
  /* eslint-disable max-params */
14
- /**
15
- * Installs require hook to transform ts.
16
- * Extracted from playwright.
17
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/transform/transform.ts
14
+ /**
15
+ * Installs require hook to transform ts.
16
+ * Extracted from playwright.
17
+ * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/transform/transform.ts
18
18
  */
19
19
  function installTransform() {
20
20
  const {
@@ -30,17 +30,13 @@ function installTransform() {
30
30
  function resolveFilename(specifier, parent, ...rest) {
31
31
  if (!reverted && parent) {
32
32
  const resolved = resolveHook(parent.filename, specifier);
33
- if (resolved !== undefined) {
34
- specifier = resolved;
35
- }
33
+ if (resolved !== undefined) specifier = resolved;
36
34
  }
37
35
  return originalResolveFilename.call(this, specifier, parent, ...rest);
38
36
  }
39
37
  _module.default._resolveFilename = resolveFilename;
40
38
  const revertPirates = pirates.addHook((code, filename) => {
41
- if (!shouldTransform(filename)) {
42
- return code;
43
- }
39
+ if (!shouldTransform(filename)) return code;
44
40
  return transformHook(code, filename);
45
41
  }, {
46
42
  exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
@@ -11,8 +11,8 @@ var _path = _interopRequireDefault(require("path"));
11
11
  var _utils = require("../utils");
12
12
  // cache playwright root
13
13
  let playwrightRoot = '';
14
- /**
15
- * Requires Playwright's internal module that is not exported via package.exports.
14
+ /**
15
+ * Requires Playwright's internal module that is not exported via package.exports.
16
16
  */
17
17
  function requirePlaywrightModule(modulePath) {
18
18
  const absPath = _path.default.isAbsolute(modulePath) ? modulePath : getPlaywrightModulePath(modulePath);
@@ -28,7 +28,10 @@ function getPlaywrightRoot() {
28
28
  // See: https://github.com/microsoft/playwright/pull/26946
29
29
  const playwrightTestRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
30
30
  const libDir = _path.default.join(playwrightTestRoot, 'lib');
31
- playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : (0, _utils.resolvePackageRoot)('playwright');
31
+
32
+ // Recently added functionality in playwright
33
+ const playwrightDir = _path.default.join(playwrightTestRoot, 'node_modules', 'playwright');
34
+ playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : playwrightDir;
32
35
  }
33
36
  return playwrightRoot;
34
37
  }
@@ -13,15 +13,12 @@ var _config = require("../config");
13
13
  var _env = require("../config/env");
14
14
  var _steps = require("../stepDefinitions/decorators/steps");
15
15
  var _dir = require("../config/dir");
16
- var _scenario = require("../hooks/scenario");
17
- var _worker = require("../hooks/worker");
18
- var _StepInvoker = require("./StepInvoker");
19
16
  const test = exports.test = _test.test.extend({
20
- // load cucumber once per worker (auto-fixture)
21
- // todo: maybe remove caching in cucumber/loadConfig.ts and cucumber/loadSteps.ts
22
- // as we call it once per worker. Check generation phase.
23
- $cucumber: [async ({}, use, workerInfo) => {
24
- const config = (0, _env.getConfigFromEnv)(workerInfo.project.testDir);
17
+ $bddWorldBase: async ({
18
+ $tags,
19
+ $test
20
+ }, use, testInfo) => {
21
+ const config = (0, _env.getConfigFromEnv)(testInfo.project.testDir);
25
22
  const environment = {
26
23
  cwd: (0, _dir.getPlaywrightConfigDir)()
27
24
  };
@@ -33,37 +30,11 @@ const test = exports.test = _test.test.extend({
33
30
  const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
34
31
  (0, _steps.appendDecoratorSteps)(supportCodeLibrary);
35
32
  const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
36
- await use({
37
- runConfiguration,
38
- supportCodeLibrary,
39
- World
40
- });
41
- }, {
42
- auto: true,
43
- scope: 'worker'
44
- }],
45
- $lang: ({}, use) => use(''),
46
- // init $bddWorldFixtures with empty object, will be owerwritten in test file for cucumber-style
47
- $bddWorldFixtures: ({}, use) => use({}),
48
- $bddWorld: async ({
49
- $tags,
50
- $test,
51
- $bddWorldFixtures,
52
- $cucumber,
53
- $lang
54
- }, use, testInfo) => {
55
- const {
56
- runConfiguration,
57
- supportCodeLibrary,
58
- World
59
- } = $cucumber;
60
33
  const world = new World({
61
34
  testInfo,
62
35
  supportCodeLibrary,
63
36
  $tags,
64
37
  $test,
65
- $bddWorldFixtures,
66
- lang: $lang,
67
38
  parameters: runConfiguration.runtime.worldParameters || {},
68
39
  log: () => {},
69
40
  attach: async () => {}
@@ -72,97 +43,63 @@ const test = exports.test = _test.test.extend({
72
43
  await use(world);
73
44
  await world.destroy();
74
45
  },
46
+ $bddWorld: async ({
47
+ $bddWorldBase,
48
+ page,
49
+ context,
50
+ browser,
51
+ browserName,
52
+ request
53
+ }, use) => {
54
+ $bddWorldBase.builtinFixtures = {
55
+ page,
56
+ context,
57
+ browser,
58
+ browserName,
59
+ request
60
+ };
61
+ await use($bddWorldBase);
62
+ },
63
+ // below fixtures are used in playwright-style
64
+ // and does not automatically init Playwright builtin fixtures
75
65
  Given: ({
76
- $bddWorld
77
- }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Given').invoke),
66
+ $bddWorldBase
67
+ }, use) => use($bddWorldBase.invokeStep),
78
68
  When: ({
79
- $bddWorld
80
- }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'When').invoke),
69
+ $bddWorldBase
70
+ }, use) => use($bddWorldBase.invokeStep),
81
71
  Then: ({
82
- $bddWorld
83
- }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Then').invoke),
72
+ $bddWorldBase
73
+ }, use) => use($bddWorldBase.invokeStep),
84
74
  And: ({
85
- $bddWorld
86
- }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'And').invoke),
75
+ $bddWorldBase
76
+ }, use) => use($bddWorldBase.invokeStep),
87
77
  But: ({
78
+ $bddWorldBase
79
+ }, use) => use($bddWorldBase.invokeStep),
80
+ // below fixtures are used in cucumber-style
81
+ // and automatically init Playwright builtin fixtures
82
+ Given_: ({
83
+ $bddWorld
84
+ }, use) => use($bddWorld.invokeStep),
85
+ When_: ({
86
+ $bddWorld
87
+ }, use) => use($bddWorld.invokeStep),
88
+ Then_: ({
88
89
  $bddWorld
89
- }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'But').invoke),
90
- // init $tags with empty array, can be owerwritten in test file
90
+ }, use) => use($bddWorld.invokeStep),
91
+ And_: ({
92
+ $bddWorld
93
+ }, use) => use($bddWorld.invokeStep),
94
+ But_: ({
95
+ $bddWorld
96
+ }, use) => use($bddWorld.invokeStep),
97
+ // Init $tags fixture with empty array. Can be owerwritten in test file
98
+ // eslint-disable-next-line
91
99
  $tags: ({}, use) => use([]),
92
- // init $test with base test, but it will be always overwritten in test file
93
- $test: ({}, use) => use(_test.test),
94
- // can be owerwritten in test file if there are scenario hooks
95
- $scenarioHookFixtures: ({}, use) => use({}),
96
- $before: [
97
- // Unused dependencies are important:
98
- // 1. $beforeAll / $afterAll: in pw < 1.39 worker-scoped auto-fixtures were called after test-scoped
99
- // 2. $after: to call after hooks in case of errors in before hooks
100
- async ({
101
- $scenarioHookFixtures,
102
- $bddWorld,
103
- $tags,
104
- $beforeAll,
105
- $afterAll,
106
- $after
107
- }, use, $testInfo) => {
108
- await (0, _scenario.runScenarioHooks)('before', {
109
- $bddWorld,
110
- $tags,
111
- $testInfo,
112
- ...$scenarioHookFixtures
113
- });
114
- await use();
115
- }, {
116
- auto: true
117
- }],
118
- $after: [async ({
119
- $scenarioHookFixtures,
120
- $bddWorld,
121
- $tags
122
- }, use, $testInfo) => {
123
- await use();
124
- await (0, _scenario.runScenarioHooks)('after', {
125
- $bddWorld,
126
- $tags,
127
- $testInfo,
128
- ...$scenarioHookFixtures
129
- });
130
- }, {
131
- auto: true
132
- }],
133
- // can be owerwritten in test file if there are worker hooks
134
- $workerHookFixtures: [({}, use) => use({}), {
135
- scope: 'worker'
136
- }],
137
- $beforeAll: [
138
- // Important unused dependencies:
139
- // 1. $afterAll: in pw < 1.39 worker-scoped auto-fixtures are called in incorrect order
140
- // 2. $cucumber: to load hooks before this fixtures
141
- async ({
142
- $workerHookFixtures,
143
- $cucumber
144
- }, use, $workerInfo) => {
145
- await (0, _worker.runWorkerHooks)('beforeAll', {
146
- $workerInfo,
147
- ...$workerHookFixtures
148
- });
149
- await use();
150
- }, {
151
- auto: true,
152
- scope: 'worker'
153
- }],
154
- $afterAll: [async ({
155
- $workerHookFixtures
156
- }, use, $workerInfo) => {
157
- await use();
158
- await (0, _worker.runWorkerHooks)('afterAll', {
159
- $workerInfo,
160
- ...$workerHookFixtures
161
- });
162
- }, {
163
- auto: true,
164
- scope: 'worker'
165
- }]
100
+ // Init $test fixture with base test, but it will be always overwritten in test file
101
+ // eslint-disable-next-line
102
+ $test: ({}, use) => use(_test.test)
166
103
  });
167
104
  const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
168
105
  function isBddAutoInjectFixture(name) {
@@ -6,46 +6,58 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.BddWorld = void 0;
7
7
  exports.getWorldConstructor = getWorldConstructor;
8
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
+ var _defineStep = require("../stepDefinitions/defineStep");
9
13
  class BddWorld extends _cucumber.World {
10
14
  options;
11
- stepFixtures = {};
15
+ builtinFixtures;
16
+ customFixtures;
12
17
  constructor(options) {
13
18
  super(options);
14
19
  this.options = options;
20
+ this.invokeStep = this.invokeStep.bind(this);
15
21
  }
16
- /**
17
- * Use particular fixture in cucumber-style steps.
18
- *
19
- * Note: TS does not support partial generic inference,
20
- * that's why we can't use this.useFixture<typeof test>('xxx');
21
- * The solution is to pass TestType as a generic to BddWorld
22
- * and call useFixture without explicit generic params.
23
- * Finally, it looks even better as there is no need to pass `typeof test`
24
- * in every `this.useFixture` call.
25
- *
26
- * The downside - it's impossible to pass fixtures type directly to `this.useFixture`
27
- * like it's done in @Fixture decorator.
28
- *
29
- * See: https://stackoverflow.com/questions/45509621/specify-only-first-type-argument
30
- * See: https://github.com/Microsoft/TypeScript/pull/26349
31
- */
32
- useFixture(fixtureName) {
33
- return this.stepFixtures[fixtureName];
22
+ async invokeStep(text, argument, customFixtures) {
23
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, text, this.testInfo.file);
24
+ if (!stepDefinition) {
25
+ throw new Error(`Undefined step: "${text}"`);
26
+ }
27
+ // attach custom fixtures to world - the only way to pass them to cucumber step fn
28
+ this.customFixtures = customFixtures;
29
+ const code = (0, _defineStep.getStepCode)(stepDefinition);
30
+ // Get location of step call in generated test file.
31
+ // This call must be exactly here to have correct call stack.
32
+ const location = (0, _getLocationInFile.getLocationInFile)(this.test.info().file);
33
+ const {
34
+ parameters
35
+ } = await stepDefinition.getInvocationParameters({
36
+ hookParameter: {},
37
+ step: {
38
+ text,
39
+ argument
40
+ },
41
+ world: this
42
+ });
43
+ const res = await (0, _testTypeImpl.runStepWithCustomLocation)(this.test, text, location, () => code.apply(this, parameters));
44
+ delete this.customFixtures;
45
+ return res;
34
46
  }
35
47
  get page() {
36
- return this.options.$bddWorldFixtures.page;
48
+ return this.builtinFixtures.page;
37
49
  }
38
50
  get context() {
39
- return this.options.$bddWorldFixtures.context;
51
+ return this.builtinFixtures.context;
40
52
  }
41
53
  get browser() {
42
- return this.options.$bddWorldFixtures.browser;
54
+ return this.builtinFixtures.browser;
43
55
  }
44
56
  get browserName() {
45
- return this.options.$bddWorldFixtures.browserName;
57
+ return this.builtinFixtures.browserName;
46
58
  }
47
59
  get request() {
48
- return this.options.$bddWorldFixtures.request;
60
+ return this.builtinFixtures.request;
49
61
  }
50
62
  get testInfo() {
51
63
  return this.options.testInfo;
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Snippets = void 0;
7
- var _url = require("url");
8
7
  var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
9
8
  var _logger = require("../utils/logger");
10
9
  var _stepConfig = require("../stepDefinitions/stepConfig");
11
- /**
12
- * Generate and show snippets for undefined steps
10
+ /**
11
+ * Generate and show snippets for undefined steps
13
12
  */
14
13
 
15
14
  class Snippets {
@@ -44,8 +43,7 @@ class Snippets {
44
43
  } = this.runConfiguration.formats.options;
45
44
  if (!snippetSyntax && this.isPlaywrightStyle()) {
46
45
  this.bddBuiltInSyntax = true;
47
- const filePath = this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
48
- return (0, _url.pathToFileURL)(filePath).toString();
46
+ return this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
49
47
  } else {
50
48
  return snippetSyntax;
51
49
  }
@@ -27,9 +27,7 @@ class _default {
27
27
  });
28
28
  const allParameterNames = ['{}', ...expressionParameters, ...stepParameters];
29
29
  const functionSignature = `${functionName}('${this.escapeSpecialCharacters(generatedExpression)}', async (${allParameterNames.join(', ')}) => {`;
30
- return [functionSignature,
31
- // prettier-ignore
32
- ` // ...`, '});'].join('\n');
30
+ return [functionSignature, ` // ...`, '});'].join('\n');
33
31
  }
34
32
  escapeSpecialCharacters(generatedExpression) {
35
33
  let source = generatedExpression.source;
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
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.
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
13
  */
14
14
 
15
15
  class _default extends _snippetSyntax.default {
@@ -4,42 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createBdd = createBdd;
7
- exports.hasCustomTest = void 0;
7
+ exports.extractFixtureNames = extractFixtureNames;
8
+ var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
8
9
  var _bddFixtures = require("../run/bddFixtures");
9
10
  var _testTypeImpl = require("../playwright/testTypeImpl");
10
11
  var _defineStep = require("./defineStep");
11
12
  var _exit = require("../utils/exit");
12
- var _scenario = require("../hooks/scenario");
13
- var _worker = require("../hooks/worker");
14
- /**
15
- * Stuff related to writing steps in Playwright-style.
13
+ /**
14
+ * Stuff related to writing steps in Playwright-style.
16
15
  */
17
16
 
18
- // Global flag showing that custom test was passed.
19
- // Used when checking 'importTestFrom' config option.
20
- // todo: https://github.com/vitalets/playwright-bdd/issues/46
21
- let hasCustomTest = exports.hasCustomTest = false;
22
17
  function createBdd(customTest) {
23
- if (!hasCustomTest) {
24
- exports.hasCustomTest = hasCustomTest = isCustomTest(customTest);
25
- }
18
+ const hasCustomTest = isCustomTest(customTest);
26
19
  const Given = defineStepCtor('Given', hasCustomTest);
27
20
  const When = defineStepCtor('When', hasCustomTest);
28
21
  const Then = defineStepCtor('Then', hasCustomTest);
29
22
  const Step = defineStepCtor('Unknown', hasCustomTest);
30
- const Before = (0, _scenario.scenarioHookFactory)('before');
31
- const After = (0, _scenario.scenarioHookFactory)('after');
32
- const BeforeAll = (0, _worker.workerHookFactory)('beforeAll');
33
- const AfterAll = (0, _worker.workerHookFactory)('afterAll');
34
23
  return {
35
24
  Given,
36
25
  When,
37
26
  Then,
38
- Step,
39
- Before,
40
- After,
41
- BeforeAll,
42
- AfterAll
27
+ Step
43
28
  };
44
29
  }
45
30
  function defineStepCtor(keyword, hasCustomTest) {
@@ -52,15 +37,13 @@ function defineStepCtor(keyword, hasCustomTest) {
52
37
  });
53
38
  };
54
39
  }
55
- function isCustomTest(customTest) {
56
- if (!customTest || customTest === _bddFixtures.test) {
57
- return false;
58
- }
59
- assertTestHasBddFixtures(customTest);
60
- return true;
40
+ function extractFixtureNames(fn) {
41
+ return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
61
42
  }
62
- function assertTestHasBddFixtures(customTest) {
63
- if (!(0, _testTypeImpl.isTestContainsSubtest)(customTest, _bddFixtures.test)) {
64
- (0, _exit.exit)(`createBdd() should use 'test' extended from "playwright-bdd"`);
43
+ function isCustomTest(customTest) {
44
+ const isCustomTest = Boolean(customTest && customTest !== _bddFixtures.test);
45
+ if (isCustomTest && customTest && !(0, _testTypeImpl.isParentChildTest)(_bddFixtures.test, customTest)) {
46
+ (0, _exit.exit)(`createBdd() should use test extended from "@zohodesk/testinglibrary"`);
65
47
  }
48
+ return isCustomTest;
66
49
  }