@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
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getWorkerHooksFixtures = getWorkerHooksFixtures;
7
+ exports.runWorkerHooks = runWorkerHooks;
8
+ exports.workerHookFactory = workerHookFactory;
9
+ var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
10
+ var _utils = require("../utils");
11
+ /**
12
+ * Worker-level hooks: BeforeAll / AfterAll.
13
+ */
14
+
15
+ const workerHooks = [];
16
+ let workerHooksFixtures;
17
+ /**
18
+ * Returns BeforeAll() / AfterAll() functions.
19
+ */
20
+ function workerHookFactory(type) {
21
+ return (...args) => {
22
+ addHook({
23
+ type,
24
+ options: getOptionsFromArgs(args),
25
+ fn: getFnFromArgs(args)
26
+ });
27
+ };
28
+ }
29
+ // eslint-disable-next-line complexity
30
+ async function runWorkerHooks(type, fixtures) {
31
+ let error;
32
+ for (const hook of workerHooks) {
33
+ if (hook.type !== type) {
34
+ continue;
35
+ }
36
+ const {
37
+ timeout
38
+ } = hook.options;
39
+ try {
40
+ await (0, _utils.callWithTimeout)(() => hook.fn(fixtures), timeout, `${type} hook timeout (${timeout} ms)`);
41
+ } catch (e) {
42
+ if (type === 'beforeAll') {
43
+ throw e;
44
+ }
45
+ if (!error) {
46
+ error = e;
47
+ }
48
+ }
49
+ }
50
+ if (error) {
51
+ throw error;
52
+ }
53
+ }
54
+ function getWorkerHooksFixtures() {
55
+ if (!workerHooksFixtures) {
56
+ const fixturesFakeObj = {
57
+ $workerInfo: null
58
+ };
59
+ const set = new Set();
60
+ workerHooks.forEach(hook => {
61
+ (0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
62
+ });
63
+ workerHooksFixtures = [...set];
64
+ }
65
+ return workerHooksFixtures;
66
+ }
67
+ function getOptionsFromArgs(args) {
68
+ if (typeof args[0] === 'object') {
69
+ return args[0];
70
+ }
71
+ return {};
72
+ }
73
+ function getFnFromArgs(args) {
74
+ return args.length === 1 ? args[0] : args[1];
75
+ }
76
+ function addHook(hook) {
77
+ if (hook.type === 'beforeAll') {
78
+ workerHooks.push(hook);
79
+ } else {
80
+ // 'afterAll' hooks run in reverse order
81
+ workerHooks.unshift(hook);
82
+ }
83
+ }
@@ -4,23 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.fixtureParameterNames = fixtureParameterNames;
7
- /**
8
- * Extracted from playwright.
9
- * https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
7
+ /**
8
+ * Extracted from playwright.
9
+ * https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
10
10
  */
11
11
  /* eslint-disable max-statements, complexity, max-len, max-depth */
12
12
  const signatureSymbol = Symbol('signature');
13
13
  function fixtureParameterNames(fn) {
14
- if (typeof fn !== 'function') return [];
15
- if (!fn[signatureSymbol]) fn[signatureSymbol] = innerFixtureParameterNames(fn);
14
+ if (typeof fn !== 'function') {
15
+ return [];
16
+ }
17
+ if (!fn[signatureSymbol]) {
18
+ fn[signatureSymbol] = innerFixtureParameterNames(fn);
19
+ }
16
20
  return fn[signatureSymbol];
17
21
  }
18
22
  function innerFixtureParameterNames(fn) {
19
23
  const text = filterOutComments(fn.toString());
20
24
  const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
21
- if (!match) return [];
25
+ if (!match) {
26
+ return [];
27
+ }
22
28
  const trimmedParams = match[1].trim();
23
- if (!trimmedParams) return [];
29
+ if (!trimmedParams) {
30
+ return [];
31
+ }
24
32
  const [firstParam] = splitByComma(trimmedParams);
25
33
  if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
26
34
  throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
@@ -40,9 +48,13 @@ function filterOutComments(s) {
40
48
  let commentState = 'none';
41
49
  for (let i = 0; i < s.length; ++i) {
42
50
  if (commentState === 'singleline') {
43
- if (s[i] === '\n') commentState = 'none';
51
+ if (s[i] === '\n') {
52
+ commentState = 'none';
53
+ }
44
54
  } else if (commentState === 'multiline') {
45
- if (s[i - 1] === '*' && s[i] === '/') commentState = 'none';
55
+ if (s[i - 1] === '*' && s[i] === '/') {
56
+ commentState = 'none';
57
+ }
46
58
  } else if (commentState === 'none') {
47
59
  if (s[i] === '/' && s[i + 1] === '/') {
48
60
  commentState = 'singleline';
@@ -67,11 +79,15 @@ function splitByComma(s) {
67
79
  stack.pop();
68
80
  } else if (!stack.length && s[i] === ',') {
69
81
  const token = s.substring(start, i).trim();
70
- if (token) result.push(token);
82
+ if (token) {
83
+ result.push(token);
84
+ }
71
85
  start = i + 1;
72
86
  }
73
87
  }
74
88
  const lastToken = s.substring(start).trim();
75
- if (lastToken) result.push(lastToken);
89
+ if (lastToken) {
90
+ result.push(lastToken);
91
+ }
76
92
  return result;
77
93
  }
@@ -7,27 +7,33 @@ 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();
16
17
  const {
17
18
  sourceMapSupport
18
19
  } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
19
20
  const oldPrepareStackTrace = Error.prepareStackTrace;
20
21
  Error.prepareStackTrace = (error, stackFrames) => {
21
- const frameInFile = stackFrames.find(frame => frame.getFileName() === filePath);
22
- if (!frameInFile) return {
23
- file: '',
24
- line: 0,
25
- column: 0
26
- };
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
+ }
27
33
  const frame = sourceMapSupport.wrapCallSite(frameInFile);
28
34
  const fileName = frame.getFileName();
29
35
  // Node error stacks for modules use file:// urls instead of paths.
30
- const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
36
+ const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
31
37
  return {
32
38
  file,
33
39
  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.isParentChildTest = isParentChildTest;
6
+ exports.isTestContainsSubtest = isTestContainsSubtest;
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,14 +38,18 @@ async function runStepWithCustomLocation(test, stepText, location, body) {
38
38
  return await body();
39
39
  });
40
40
  }
41
- /**
42
- * Returns true if all fixtures of parent test found in child test.
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, ...)
43
45
  */
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));
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));
49
53
  });
50
54
  }
51
55
  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,13 +30,17 @@ 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) specifier = resolved;
33
+ if (resolved !== undefined) {
34
+ specifier = resolved;
35
+ }
34
36
  }
35
37
  return originalResolveFilename.call(this, specifier, parent, ...rest);
36
38
  }
37
39
  _module.default._resolveFilename = resolveFilename;
38
40
  const revertPirates = pirates.addHook((code, filename) => {
39
- if (!shouldTransform(filename)) return code;
41
+ if (!shouldTransform(filename)) {
42
+ return code;
43
+ }
40
44
  return transformHook(code, filename);
41
45
  }, {
42
46
  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,10 +28,7 @@ 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
-
32
- // Recently added functionality in playwright
33
- const playwrightDir = _path.default.join(playwrightTestRoot, 'node_modules', 'playwright');
34
- playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : playwrightDir;
31
+ playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : (0, _utils.resolvePackageRoot)('playwright');
35
32
  }
36
33
  return playwrightRoot;
37
34
  }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StepInvoker = void 0;
7
+ var _loadSteps = require("../cucumber/loadSteps");
8
+ var _getLocationInFile = require("../playwright/getLocationInFile");
9
+ var _testTypeImpl = require("../playwright/testTypeImpl");
10
+ var _defineStep = require("../stepDefinitions/defineStep");
11
+ var _lang = require("../config/lang");
12
+ /**
13
+ * Class to invoke steps in generated files.
14
+ */
15
+
16
+ class StepInvoker {
17
+ world;
18
+ keyword;
19
+ text = '';
20
+ argument;
21
+ constructor(world, keyword) {
22
+ this.world = world;
23
+ this.keyword = keyword;
24
+ this.invoke = this.invoke.bind(this);
25
+ }
26
+ async invoke(text, argument, stepFixtures) {
27
+ this.text = text;
28
+ this.argument = argument;
29
+ const {
30
+ world
31
+ } = this;
32
+ world.stepFixtures = stepFixtures || {};
33
+ const stepDefinition = this.getStepDefinition();
34
+ // Get location of step call in generated test file.
35
+ // This call must be exactly here to have correct call stack (before async calls)
36
+ const location = (0, _getLocationInFile.getLocationInFile)(world.test.info().file);
37
+ const stepTitle = this.getStepTitle();
38
+ const code = (0, _defineStep.getStepCode)(stepDefinition);
39
+ const parameters = await this.getStepParameters(stepDefinition);
40
+ return (0, _testTypeImpl.runStepWithCustomLocation)(world.test, stepTitle, location, () => code.apply(world, parameters));
41
+ }
42
+ getStepDefinition() {
43
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.world.options.supportCodeLibrary, this.text, this.world.testInfo.file);
44
+ if (!stepDefinition) {
45
+ throw new Error(`Undefined step: "${this.text}"`);
46
+ }
47
+ return stepDefinition;
48
+ }
49
+ async getStepParameters(stepDefinition) {
50
+ const {
51
+ text,
52
+ argument,
53
+ world
54
+ } = this;
55
+ const {
56
+ parameters
57
+ } = await stepDefinition.getInvocationParameters({
58
+ hookParameter: {},
59
+ step: {
60
+ text,
61
+ argument
62
+ },
63
+ world
64
+ });
65
+ return parameters;
66
+ }
67
+ getStepTitle() {
68
+ // Currently prepend keyword only for English.
69
+ // For other langs it's more complex as we need to pass original keyword from step.
70
+ return (0, _lang.isEnglish)(this.world.options.lang) ? `${this.keyword} ${this.text}` : this.text;
71
+ }
72
+ }
73
+ exports.StepInvoker = StepInvoker;
@@ -13,12 +13,15 @@ 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");
16
19
  const test = exports.test = _test.test.extend({
17
- $bddWorldBase: async ({
18
- $tags,
19
- $test
20
- }, use, testInfo) => {
21
- const config = (0, _env.getConfigFromEnv)(testInfo.project.testDir);
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);
22
25
  const environment = {
23
26
  cwd: (0, _dir.getPlaywrightConfigDir)()
24
27
  };
@@ -30,11 +33,37 @@ const test = exports.test = _test.test.extend({
30
33
  const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
31
34
  (0, _steps.appendDecoratorSteps)(supportCodeLibrary);
32
35
  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;
33
60
  const world = new World({
34
61
  testInfo,
35
62
  supportCodeLibrary,
36
63
  $tags,
37
64
  $test,
65
+ $bddWorldFixtures,
66
+ lang: $lang,
38
67
  parameters: runConfiguration.runtime.worldParameters || {},
39
68
  log: () => {},
40
69
  attach: async () => {}
@@ -43,63 +72,97 @@ const test = exports.test = _test.test.extend({
43
72
  await use(world);
44
73
  await world.destroy();
45
74
  },
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
65
75
  Given: ({
66
- $bddWorldBase
67
- }, use) => use($bddWorldBase.invokeStep),
68
- When: ({
69
- $bddWorldBase
70
- }, use) => use($bddWorldBase.invokeStep),
71
- Then: ({
72
- $bddWorldBase
73
- }, use) => use($bddWorldBase.invokeStep),
74
- And: ({
75
- $bddWorldBase
76
- }, use) => use($bddWorldBase.invokeStep),
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
76
  $bddWorld
84
- }, use) => use($bddWorld.invokeStep),
85
- When_: ({
77
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Given').invoke),
78
+ When: ({
86
79
  $bddWorld
87
- }, use) => use($bddWorld.invokeStep),
88
- Then_: ({
80
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'When').invoke),
81
+ Then: ({
89
82
  $bddWorld
90
- }, use) => use($bddWorld.invokeStep),
91
- And_: ({
83
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Then').invoke),
84
+ And: ({
92
85
  $bddWorld
93
- }, use) => use($bddWorld.invokeStep),
94
- But_: ({
86
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'And').invoke),
87
+ But: ({
95
88
  $bddWorld
96
- }, use) => use($bddWorld.invokeStep),
97
- // Init $tags fixture with empty array. Can be owerwritten in test file
98
- // eslint-disable-next-line
89
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'But').invoke),
90
+ // init $tags with empty array, can be owerwritten in test file
99
91
  $tags: ({}, use) => use([]),
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)
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
+ }]
103
166
  });
104
167
  const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
105
168
  function isBddAutoInjectFixture(name) {