@zohodesk/testinglibrary 0.1.8-exp-bdd-v3 → 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 (72) hide show
  1. package/build/bdd-framework/cli/commands/env.js +42 -0
  2. package/build/bdd-framework/cli/commands/export.js +47 -0
  3. package/build/bdd-framework/cli/commands/test.js +60 -0
  4. package/build/bdd-framework/cli/index.js +11 -0
  5. package/build/bdd-framework/cli/options.js +19 -0
  6. package/build/bdd-framework/cli/worker.js +13 -0
  7. package/build/bdd-framework/config/dir.js +27 -0
  8. package/build/bdd-framework/config/env.js +49 -0
  9. package/build/bdd-framework/config/index.js +90 -0
  10. package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
  11. package/build/bdd-framework/cucumber/gherkin.d.js +5 -0
  12. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  13. package/build/bdd-framework/cucumber/loadConfig.js +17 -0
  14. package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
  15. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
  16. package/build/bdd-framework/cucumber/loadSources.js +57 -0
  17. package/build/bdd-framework/cucumber/loadSteps.js +35 -0
  18. package/build/bdd-framework/decorators.js +18 -0
  19. package/build/bdd-framework/gen/formatter.js +88 -0
  20. package/build/bdd-framework/gen/i18n.js +35 -0
  21. package/build/bdd-framework/gen/index.js +163 -0
  22. package/build/bdd-framework/gen/poms.js +46 -0
  23. package/build/bdd-framework/gen/testFile.js +356 -0
  24. package/build/bdd-framework/gen/testNode.js +48 -0
  25. package/build/bdd-framework/gen/testPoms.js +123 -0
  26. package/build/bdd-framework/index.js +45 -0
  27. package/build/bdd-framework/playwright/fixtureParameterNames.js +77 -0
  28. package/build/bdd-framework/playwright/getLocationInFile.js +46 -0
  29. package/build/bdd-framework/playwright/loadConfig.js +42 -0
  30. package/build/bdd-framework/playwright/testTypeImpl.js +57 -0
  31. package/build/bdd-framework/playwright/transform.js +80 -0
  32. package/build/bdd-framework/playwright/types.js +5 -0
  33. package/build/bdd-framework/playwright/utils.js +37 -0
  34. package/build/bdd-framework/run/bddFixtures.js +107 -0
  35. package/build/bdd-framework/run/bddWorld.js +88 -0
  36. package/build/bdd-framework/snippets/index.js +134 -0
  37. package/build/bdd-framework/snippets/snippetSyntax.js +41 -0
  38. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
  39. package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
  40. package/build/bdd-framework/stepDefinitions/createBdd.js +49 -0
  41. package/build/bdd-framework/stepDefinitions/createDecorators.js +108 -0
  42. package/build/bdd-framework/stepDefinitions/decorators/poms.js +64 -0
  43. package/build/bdd-framework/stepDefinitions/decorators/steps.js +93 -0
  44. package/build/bdd-framework/stepDefinitions/defineStep.js +61 -0
  45. package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
  46. package/build/bdd-framework/utils/exit.js +54 -0
  47. package/build/bdd-framework/utils/index.js +44 -0
  48. package/build/bdd-framework/utils/jsStringWrap.js +44 -0
  49. package/build/bdd-framework/utils/logger.js +28 -0
  50. package/build/bdd-poc/core-runner/exportMethods.js +6 -12
  51. package/build/bdd-poc/core-runner/stepDefinitions.js +3 -1
  52. package/build/bdd-poc/test/cucumber/featureFileParer.js +5 -4
  53. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +9 -8
  54. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +1 -2
  55. package/build/bdd-poc/test/testDataMap.js +2 -2
  56. package/build/bdd-poc/test/testStructure.js +4 -3
  57. package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
  58. package/build/core/playwright/custom-commands.js +1 -2
  59. package/build/core/playwright/index.js +18 -8
  60. package/build/core/playwright/readConfigFile.js +1 -2
  61. package/build/core/playwright/setup/config-creator.js +7 -10
  62. package/build/core/playwright/setup/config-utils.js +13 -14
  63. package/build/core/playwright/test-runner.js +28 -36
  64. package/build/decorators.d.ts +1 -1
  65. package/build/decorators.js +16 -2
  66. package/build/index.js +14 -10
  67. package/build/parser/parser.js +0 -1
  68. package/build/utils/logger.js +1 -2
  69. package/build/utils/stepDefinitionsFormatter.js +1 -2
  70. package/npm-shrinkwrap.json +570 -4
  71. package/package.json +3 -3
  72. package/build/bdd-poc/runner.js +0 -19
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TestNode = void 0;
7
+ var _utils = require("../utils");
8
+ /**
9
+ * Universal TestNode class of parent-child relations in test file structure.
10
+ * Holds tags and titles path.
11
+ */
12
+
13
+ const SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
14
+ class TestNode {
15
+ title;
16
+ titlePath;
17
+ ownTags = [];
18
+ tags = [];
19
+ flags = {};
20
+ constructor(gherkinNode, parent) {
21
+ this.initOwnTags(gherkinNode);
22
+ this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
23
+ this.title = gherkinNode.name;
24
+ this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
25
+ }
26
+ initOwnTags(gherkinNode) {
27
+ const tagNames = (0, _utils.removeDuplicates)(getTagNames(gherkinNode.tags));
28
+ tagNames.forEach(tag => {
29
+ if (isSpecialTag(tag)) {
30
+ this.setFlag(tag);
31
+ } else {
32
+ this.ownTags.push(tag);
33
+ }
34
+ });
35
+ }
36
+ setFlag(tag) {
37
+ if (tag === '@only') this.flags.only = true;
38
+ if (tag === '@skip') this.flags.skip = true;
39
+ if (tag === '@fixme') this.flags.fixme = true;
40
+ }
41
+ }
42
+ exports.TestNode = TestNode;
43
+ function getTagNames(tags) {
44
+ return tags.map(tag => tag.name);
45
+ }
46
+ function isSpecialTag(tag) {
47
+ return SPECIAL_TAGS.includes(tag);
48
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TestPoms = void 0;
7
+ exports.buildFixtureTag = buildFixtureTag;
8
+ var _poms = require("../stepDefinitions/decorators/poms");
9
+ var _exit = require("../utils/exit");
10
+ /**
11
+ * Track PomNodes used in the particular test.
12
+ * To select correct fixture for decorator steps.
13
+ *
14
+ * Idea: try to use the deepest child fixture for parent steps.
15
+ *
16
+ * Example inheritance tree:
17
+ * A
18
+ * / \
19
+ * B C
20
+ * / \ \
21
+ * D E F
22
+ *
23
+ * If test uses steps from classes A and D:
24
+ * -> resolved fixture will be D, even for steps from A.
25
+ *
26
+ * If test uses steps from classes A, D and C:
27
+ * -> error, b/c A has 2 possible fixtures.
28
+ *
29
+ * If test uses steps from classes A and C, but @fixture tag is D:
30
+ * -> error, b/c A has 2 possible fixtures.
31
+ */
32
+
33
+ const FIXTURE_TAG_PREFIX = '@fixture:';
34
+ class TestPoms {
35
+ title;
36
+ // map of poms used in test
37
+ usedPoms = new Map();
38
+ constructor(title) {
39
+ this.title = title;
40
+ }
41
+ addByStep(pomNode) {
42
+ this.addUsedPom(pomNode, {
43
+ byTag: false
44
+ });
45
+ }
46
+ addByFixtureName(fixtureName) {
47
+ const pomNode = (0, _poms.getPomNodeByFixtureName)(fixtureName);
48
+ this.addUsedPom(pomNode, {
49
+ byTag: false
50
+ });
51
+ }
52
+ addByTag(tag) {
53
+ const fixtureName = extractFixtureName(tag);
54
+ if (fixtureName) {
55
+ const pomNode = (0, _poms.getPomNodeByFixtureName)(fixtureName);
56
+ this.addUsedPom(pomNode, {
57
+ byTag: true
58
+ });
59
+ }
60
+ }
61
+ /**
62
+ * Resolve all used pomNodes to fixtures.
63
+ * This is needed to handle @fixture: tagged pomNodes
64
+ * that does not have steps in the test, but should be considered.
65
+ */
66
+ resolveFixtures() {
67
+ this.usedPoms.forEach((_, pomNode) => {
68
+ this.getResolvedFixtures(pomNode);
69
+ });
70
+ }
71
+ /**
72
+ * Returns fixtures suitable for particular pomNode (actually for step)
73
+ */
74
+ getResolvedFixtures(pomNode) {
75
+ const usedPom = this.usedPoms.get(pomNode);
76
+ if (usedPom !== null && usedPom !== void 0 && usedPom.fixtures) return usedPom.fixtures;
77
+ // Recursively resolve children fixtures, used in test.
78
+ let childFixtures = [...pomNode.children].map(child => this.getResolvedFixtures(child)).flat();
79
+ if (!usedPom) return childFixtures;
80
+ if (childFixtures.length) {
81
+ this.verifyChildFixtures(pomNode, usedPom, childFixtures);
82
+ usedPom.fixtures = childFixtures;
83
+ } else {
84
+ usedPom.fixtures = [{
85
+ name: pomNode.fixtureName,
86
+ byTag: usedPom.byTag
87
+ }];
88
+ }
89
+ return usedPom.fixtures;
90
+ }
91
+ addUsedPom(pomNode, {
92
+ byTag
93
+ }) {
94
+ if (!pomNode) return;
95
+ const usedPom = this.usedPoms.get(pomNode);
96
+ if (usedPom) {
97
+ if (byTag && !usedPom.byTag) usedPom.byTag = true;
98
+ } else {
99
+ this.usedPoms.set(pomNode, {
100
+ byTag
101
+ });
102
+ }
103
+ }
104
+ /**
105
+ * For scenarios with @fixture:xxx tags verify that there are no steps from fixtures,
106
+ * deeper than xxx.
107
+ * @fixture:xxx tag provides maximum fixture that can be used in the scenario.
108
+ */
109
+ verifyChildFixtures(pomNode, usedPom, childFixtures) {
110
+ if (!usedPom.byTag) return;
111
+ const childFixturesBySteps = childFixtures.filter(f => !f.byTag);
112
+ if (childFixturesBySteps.length) {
113
+ (0, _exit.exit)(`Scenario "${this.title}" contains ${childFixturesBySteps.length} step(s)`, `not compatible with required fixture "${pomNode.fixtureName}"`);
114
+ }
115
+ }
116
+ }
117
+ exports.TestPoms = TestPoms;
118
+ function extractFixtureName(tag) {
119
+ return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
120
+ }
121
+ function buildFixtureTag(fixtureName) {
122
+ return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
123
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BDDInputConfig", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _config.BDDInputConfig;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "BddWorld", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _bddWorld.BddWorld;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "BddWorldOptions", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _bddWorld.BddWorldOptions;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "createBdd", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _createBdd.createBdd;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "defineBddConfig", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _config.defineBddConfig;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "test", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _bddFixtures.test;
40
+ }
41
+ });
42
+ var _config = require("./config");
43
+ var _createBdd = require("./stepDefinitions/createBdd");
44
+ var _bddFixtures = require("./run/bddFixtures");
45
+ var _bddWorld = require("./run/bddWorld");
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
10
+ */
11
+ /* eslint-disable max-statements, complexity, max-len, max-depth */
12
+ const signatureSymbol = Symbol('signature');
13
+ function fixtureParameterNames(fn) {
14
+ if (typeof fn !== 'function') return [];
15
+ if (!fn[signatureSymbol]) fn[signatureSymbol] = innerFixtureParameterNames(fn);
16
+ return fn[signatureSymbol];
17
+ }
18
+ function innerFixtureParameterNames(fn) {
19
+ const text = filterOutComments(fn.toString());
20
+ const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
21
+ if (!match) return [];
22
+ const trimmedParams = match[1].trim();
23
+ if (!trimmedParams) return [];
24
+ const [firstParam] = splitByComma(trimmedParams);
25
+ if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
26
+ throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
27
+ }
28
+ const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
29
+ const colon = prop.indexOf(':');
30
+ return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
31
+ });
32
+ const restProperty = props.find(prop => prop.startsWith('...'));
33
+ if (restProperty) {
34
+ throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
35
+ }
36
+ return props;
37
+ }
38
+ function filterOutComments(s) {
39
+ const result = [];
40
+ let commentState = 'none';
41
+ for (let i = 0; i < s.length; ++i) {
42
+ if (commentState === 'singleline') {
43
+ if (s[i] === '\n') commentState = 'none';
44
+ } else if (commentState === 'multiline') {
45
+ if (s[i - 1] === '*' && s[i] === '/') commentState = 'none';
46
+ } else if (commentState === 'none') {
47
+ if (s[i] === '/' && s[i + 1] === '/') {
48
+ commentState = 'singleline';
49
+ } else if (s[i] === '/' && s[i + 1] === '*') {
50
+ commentState = 'multiline';
51
+ i += 2;
52
+ } else {
53
+ result.push(s[i]);
54
+ }
55
+ }
56
+ }
57
+ return result.join('');
58
+ }
59
+ function splitByComma(s) {
60
+ const result = [];
61
+ const stack = [];
62
+ let start = 0;
63
+ for (let i = 0; i < s.length; i++) {
64
+ if (s[i] === '{' || s[i] === '[') {
65
+ stack.push(s[i] === '{' ? '}' : ']');
66
+ } else if (s[i] === stack[stack.length - 1]) {
67
+ stack.pop();
68
+ } else if (!stack.length && s[i] === ',') {
69
+ const token = s.substring(start, i).trim();
70
+ if (token) result.push(token);
71
+ start = i + 1;
72
+ }
73
+ }
74
+ const lastToken = s.substring(start).trim();
75
+ if (lastToken) result.push(lastToken);
76
+ return result;
77
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getLocationInFile = getLocationInFile;
8
+ var _url = _interopRequireDefault(require("url"));
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
14
+ */
15
+ function getLocationInFile(filePath) {
16
+ const {
17
+ sourceMapSupport
18
+ } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
19
+ const oldPrepareStackTrace = Error.prepareStackTrace;
20
+ 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
+ };
27
+ const frame = sourceMapSupport.wrapCallSite(frameInFile);
28
+ const fileName = frame.getFileName();
29
+ // Node error stacks for modules use file:// urls instead of paths.
30
+ const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
31
+ return {
32
+ file,
33
+ line: frame.getLineNumber(),
34
+ column: frame.getColumnNumber()
35
+ };
36
+ };
37
+ // commented stackTraceLImit modification, todo: check if it has perf impact
38
+ // const oldStackTraceLimit = Error.stackTraceLimit;
39
+ // Error.stackTraceLimit = level + 1;
40
+ const obj = {};
41
+ Error.captureStackTrace(obj);
42
+ const location = obj.stack;
43
+ // Error.stackTraceLimit = oldStackTraceLimit;
44
+ Error.prepareStackTrace = oldPrepareStackTrace;
45
+ return location;
46
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.loadConfig = loadConfig;
8
+ exports.resolveConfigFile = resolveConfigFile;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+ var _utils = require("./utils");
12
+ var _transform = require("./transform");
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
17
+ */
18
+
19
+ async function loadConfig(cliConfigPath) {
20
+ const resolvedConfigFile = resolveConfigFile(cliConfigPath);
21
+ assertConfigFileExists(resolvedConfigFile, cliConfigPath);
22
+ await (0, _transform.requireTransform)().requireOrImport(resolvedConfigFile);
23
+ return {
24
+ resolvedConfigFile
25
+ };
26
+ }
27
+ function resolveConfigFile(cliConfigPath) {
28
+ const {
29
+ resolveConfigFile
30
+ } = (0, _utils.requirePlaywrightModule)('lib/common/configLoader.js');
31
+ const configFileOrDirectory = getConfigFilePath(cliConfigPath);
32
+ return resolveConfigFile(configFileOrDirectory) || '';
33
+ }
34
+ function getConfigFilePath(cliConfigPath) {
35
+ return cliConfigPath ? _path.default.resolve(process.cwd(), cliConfigPath) : process.cwd();
36
+ }
37
+ function assertConfigFileExists(resolvedConfigFile, cliConfigPath) {
38
+ if (!resolvedConfigFile || !_fs.default.existsSync(resolvedConfigFile)) {
39
+ const configFilePath = getConfigFilePath(cliConfigPath);
40
+ (0, _exit.exit)(`Can't find Playwright config file in: ${configFilePath}`);
41
+ }
42
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isParentChildTest = isParentChildTest;
7
+ exports.runStepWithCustomLocation = runStepWithCustomLocation;
8
+ var _test = require("@playwright/test");
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
13
+ */
14
+
15
+ const testTypeSymbol = (0, _utils.getSymbolByName)(_test.test, 'testType');
16
+ /**
17
+ * Returns test fixtures using Symbol.
18
+ */
19
+ function getTestFixtures(test) {
20
+ return getTestImpl(test).fixtures;
21
+ }
22
+ function getTestImpl(test) {
23
+ return test[testTypeSymbol];
24
+ }
25
+ /**
26
+ * Run step with location pointing to Given, When, Then call.
27
+ */
28
+ // eslint-disable-next-line max-params
29
+ async function runStepWithCustomLocation(test, stepText, location, body) {
30
+ const testInfo = test.info();
31
+ // See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/common/testType.ts#L221
32
+ // @ts-expect-error _runAsStep is hidden from public
33
+ return testInfo._runAsStep({
34
+ category: 'test.step',
35
+ title: stepText,
36
+ location
37
+ }, async () => {
38
+ return await body();
39
+ });
40
+ }
41
+ /**
42
+ * Returns true if all fixtures of parent test found in child test.
43
+ */
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));
49
+ });
50
+ }
51
+ function locationToString({
52
+ file,
53
+ line,
54
+ column
55
+ }) {
56
+ return `${file}:${line}:${column}`;
57
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.installTransform = installTransform;
8
+ exports.requireTransform = requireTransform;
9
+ var _module = _interopRequireDefault(require("module"));
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+ var _path = _interopRequireDefault(require("path"));
12
+ var _utils = require("./utils");
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
18
+ */
19
+ function installTransform() {
20
+ const {
21
+ pirates
22
+ } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
23
+ const {
24
+ resolveHook,
25
+ shouldTransform,
26
+ transformHook
27
+ } = requireTransform();
28
+ let reverted = false;
29
+ const originalResolveFilename = _module.default._resolveFilename;
30
+ function resolveFilename(specifier, parent, ...rest) {
31
+ if (!reverted && parent) {
32
+ const resolved = resolveHook(parent.filename, specifier);
33
+ if (resolved !== undefined) specifier = resolved;
34
+ }
35
+ return originalResolveFilename.call(this, specifier, parent, ...rest);
36
+ }
37
+ _module.default._resolveFilename = resolveFilename;
38
+ const revertPirates = pirates.addHook((code, filename) => {
39
+ if (!shouldTransform(filename)) return code;
40
+ return transformHook(code, filename);
41
+ }, {
42
+ exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
43
+ });
44
+ return () => {
45
+ reverted = true;
46
+ _module.default._resolveFilename = originalResolveFilename;
47
+ revertPirates();
48
+ };
49
+ }
50
+ function requireTransform() {
51
+ const transformPathSince1_35 = (0, _utils.getPlaywrightModulePath)('lib/transform/transform.js');
52
+ if (_fs.default.existsSync(transformPathSince1_35)) {
53
+ const {
54
+ resolveHook,
55
+ shouldTransform,
56
+ transformHook,
57
+ requireOrImport
58
+ } = (0, _utils.requirePlaywrightModule)(transformPathSince1_35);
59
+ return {
60
+ resolveHook,
61
+ shouldTransform,
62
+ transformHook,
63
+ requireOrImport
64
+ };
65
+ } else {
66
+ const {
67
+ resolveHook,
68
+ transformHook,
69
+ requireOrImport
70
+ } = (0, _utils.requirePlaywrightModule)('lib/common/transform.js');
71
+ // see: https://github.com/microsoft/playwright/blob/b4ffb848de1b00e9a0abad6dacdccce60cce9bed/packages/playwright-test/src/reporters/base.ts#L524
72
+ const shouldTransform = file => !file.includes(`${_path.default.sep}node_modules${_path.default.sep}`);
73
+ return {
74
+ resolveHook,
75
+ shouldTransform,
76
+ transformHook,
77
+ requireOrImport
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getPlaywrightModulePath = getPlaywrightModulePath;
8
+ exports.requirePlaywrightModule = requirePlaywrightModule;
9
+ var _fs = _interopRequireDefault(require("fs"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _utils = require("../utils");
12
+ // cache playwright root
13
+ let playwrightRoot = '';
14
+ /**
15
+ * Requires Playwright's internal module that is not exported via package.exports.
16
+ */
17
+ function requirePlaywrightModule(modulePath) {
18
+ const absPath = _path.default.isAbsolute(modulePath) ? modulePath : getPlaywrightModulePath(modulePath);
19
+ return require(absPath);
20
+ }
21
+ function getPlaywrightModulePath(relativePath) {
22
+ return _path.default.join(getPlaywrightRoot(), relativePath);
23
+ }
24
+ function getPlaywrightRoot() {
25
+ if (!playwrightRoot) {
26
+ // Since 1.38 all modules moved from @playwright/test to playwright.
27
+ // Here we check existance of 'lib' dir instead of checking version.
28
+ // See: https://github.com/microsoft/playwright/pull/26946
29
+ const playwrightTestRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
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;
35
+ }
36
+ return playwrightRoot;
37
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBddAutoInjectFixture = isBddAutoInjectFixture;
7
+ exports.test = void 0;
8
+ var _test = require("@playwright/test");
9
+ var _loadConfig = require("../cucumber/loadConfig");
10
+ var _loadSteps = require("../cucumber/loadSteps");
11
+ var _bddWorld = require("./bddWorld");
12
+ var _config = require("../config");
13
+ var _env = require("../config/env");
14
+ var _steps = require("../stepDefinitions/decorators/steps");
15
+ var _dir = require("../config/dir");
16
+ 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);
22
+ const environment = {
23
+ cwd: (0, _dir.getPlaywrightConfigDir)()
24
+ };
25
+ const {
26
+ runConfiguration
27
+ } = await (0, _loadConfig.loadConfig)({
28
+ provided: (0, _config.extractCucumberConfig)(config)
29
+ }, environment);
30
+ const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
31
+ (0, _steps.appendDecoratorSteps)(supportCodeLibrary);
32
+ const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
33
+ const world = new World({
34
+ testInfo,
35
+ supportCodeLibrary,
36
+ $tags,
37
+ $test,
38
+ parameters: runConfiguration.runtime.worldParameters || {},
39
+ log: () => {},
40
+ attach: async () => {}
41
+ });
42
+ await world.init();
43
+ await use(world);
44
+ await world.destroy();
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
65
+ 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
+ $bddWorld
84
+ }, use) => use($bddWorld.invokeStep),
85
+ When_: ({
86
+ $bddWorld
87
+ }, use) => use($bddWorld.invokeStep),
88
+ Then_: ({
89
+ $bddWorld
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
99
+ $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)
103
+ });
104
+ const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
105
+ function isBddAutoInjectFixture(name) {
106
+ return BDD_AUTO_INJECT_FIXTURES.includes(name);
107
+ }