@zohodesk/testinglibrary 2.9.1 → 3.0.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 (138) hide show
  1. package/.gitlab-ci.yml +16 -23
  2. package/README.md +32 -1
  3. package/build/core/playwright/constants/fileMutexConfig.js +11 -0
  4. package/build/core/playwright/fixtures.js +24 -0
  5. package/build/core/playwright/helpers/auth/checkAuthCookies.js +2 -8
  6. package/build/core/playwright/helpers/auth/loginSteps.js +25 -18
  7. package/build/core/playwright/helpers/checkAuthDirectory.js +17 -0
  8. package/build/core/playwright/helpers/fileMutex.js +56 -0
  9. package/build/core/playwright/index.js +10 -23
  10. package/build/core/playwright/setup/config-creator.js +3 -3
  11. package/build/core/playwright/setup/config-utils.js +8 -25
  12. package/build/core/playwright/tagProcessor.js +18 -28
  13. package/build/core/playwright/test-runner.js +1 -1
  14. package/build/decorators.d.ts +1 -1
  15. package/build/decorators.js +1 -1
  16. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  17. package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
  18. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  19. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  20. package/build/setup-folder-structure/samples/settings.json +7 -0
  21. package/build/setup-folder-structure/setupProject.js +18 -5
  22. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +94 -0
  23. package/nobdd/uat/conf/default/actors/index.js +1 -4
  24. package/nobdd/uat/conf/default/settings.json +1 -1
  25. package/nobdd/uat/conf/nobdd/uat.config.js +11 -4
  26. package/nobdd/uat/env-config.json +3 -3
  27. package/nobdd/uat/fixtures/setup.teardown.js +2 -1
  28. package/nobdd/uat/modules/nobdd/steps/VerifyNoBDD.feature.spec.js +3 -3
  29. package/nobdd/uat.config.js +8 -3
  30. package/package.json +8 -7
  31. package/build/bdd-framework/cli/commands/env.js +0 -42
  32. package/build/bdd-framework/cli/commands/export.js +0 -62
  33. package/build/bdd-framework/cli/commands/test.js +0 -64
  34. package/build/bdd-framework/cli/index.js +0 -11
  35. package/build/bdd-framework/cli/options.js +0 -19
  36. package/build/bdd-framework/cli/worker.js +0 -13
  37. package/build/bdd-framework/config/configDir.js +0 -35
  38. package/build/bdd-framework/config/enrichReporterData.js +0 -23
  39. package/build/bdd-framework/config/env.js +0 -50
  40. package/build/bdd-framework/config/index.js +0 -94
  41. package/build/bdd-framework/config/lang.js +0 -14
  42. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  43. package/build/bdd-framework/cucumber/createTestStep.js +0 -43
  44. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
  45. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
  46. package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
  47. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
  48. package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
  49. package/build/bdd-framework/cucumber/formatter/index.js +0 -16
  50. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
  51. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  52. package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
  53. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  54. package/build/bdd-framework/cucumber/loadSteps.js +0 -47
  55. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
  56. package/build/bdd-framework/cucumber/stepArguments.js +0 -21
  57. package/build/bdd-framework/cucumber/types.js +0 -5
  58. package/build/bdd-framework/cucumber/valueChecker.js +0 -23
  59. package/build/bdd-framework/decorators.js +0 -18
  60. package/build/bdd-framework/gen/fixtures.js +0 -48
  61. package/build/bdd-framework/gen/formatter.js +0 -167
  62. package/build/bdd-framework/gen/i18n.js +0 -39
  63. package/build/bdd-framework/gen/index.js +0 -197
  64. package/build/bdd-framework/gen/specialTags.js +0 -70
  65. package/build/bdd-framework/gen/testFile.js +0 -470
  66. package/build/bdd-framework/gen/testMeta.js +0 -60
  67. package/build/bdd-framework/gen/testNode.js +0 -35
  68. package/build/bdd-framework/gen/testPoms.js +0 -133
  69. package/build/bdd-framework/hooks/scenario.js +0 -130
  70. package/build/bdd-framework/hooks/worker.js +0 -89
  71. package/build/bdd-framework/index.js +0 -52
  72. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
  73. package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
  74. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  75. package/build/bdd-framework/playwright/loadUtils.js +0 -33
  76. package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
  77. package/build/bdd-framework/playwright/transform.js +0 -88
  78. package/build/bdd-framework/playwright/types.js +0 -12
  79. package/build/bdd-framework/playwright/utils.js +0 -56
  80. package/build/bdd-framework/reporter/cucumber/base.js +0 -52
  81. package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
  82. package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
  83. package/build/bdd-framework/reporter/cucumber/html.js +0 -40
  84. package/build/bdd-framework/reporter/cucumber/index.js +0 -74
  85. package/build/bdd-framework/reporter/cucumber/json.js +0 -312
  86. package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
  87. package/build/bdd-framework/reporter/cucumber/message.js +0 -20
  88. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
  89. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
  90. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
  91. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
  92. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
  93. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
  94. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
  95. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
  96. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
  97. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
  98. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
  99. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
  100. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
  101. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
  102. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
  103. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
  104. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
  105. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
  106. package/build/bdd-framework/run/StepInvoker.js +0 -69
  107. package/build/bdd-framework/run/bddData/index.js +0 -59
  108. package/build/bdd-framework/run/bddData/types.js +0 -5
  109. package/build/bdd-framework/run/bddFixtures.js +0 -192
  110. package/build/bdd-framework/run/bddWorld.js +0 -79
  111. package/build/bdd-framework/run/bddWorldInternal.js +0 -11
  112. package/build/bdd-framework/snippets/index.js +0 -132
  113. package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
  114. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  115. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  116. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
  117. package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
  118. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
  119. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
  120. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  121. package/build/bdd-framework/steps/createBdd.js +0 -78
  122. package/build/bdd-framework/steps/decorators/class.js +0 -68
  123. package/build/bdd-framework/steps/decorators/steps.js +0 -98
  124. package/build/bdd-framework/steps/defineStep.js +0 -62
  125. package/build/bdd-framework/steps/stepConfig.js +0 -24
  126. package/build/bdd-framework/utils/AutofillMap.js +0 -20
  127. package/build/bdd-framework/utils/exit.js +0 -62
  128. package/build/bdd-framework/utils/index.js +0 -93
  129. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  130. package/build/bdd-framework/utils/logger.js +0 -30
  131. package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
  132. package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
  133. package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
  134. package/nobdd/src/App.js +0 -7
  135. package/nobdd/uat/conf/default/actors/beta/custom-module.json +0 -24
  136. package/nobdd/uat/conf/default/actors/beta/index.js +0 -6
  137. package/nobdd/uat/conf/default/actors/beta/parent-child.json +0 -24
  138. package/npm-shrinkwrap.json +0 -6475
@@ -1,130 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getScenarioHooksFixtures = getScenarioHooksFixtures;
8
- exports.hasScenarioHooks = hasScenarioHooks;
9
- exports.runScenarioHooks = runScenarioHooks;
10
- exports.scenarioHookFactory = scenarioHookFactory;
11
- var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
12
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
13
- var _utils = require("../utils");
14
- var _getLocationInFile = require("../playwright/getLocationInFile");
15
- var _testTypeImpl = require("../playwright/testTypeImpl");
16
- /**
17
- * Scenario level hooks: Before / After.
18
- *
19
- * before(async ({ page }) => {})
20
- */
21
-
22
- const scenarioHooks = [];
23
- let scenarioHooksFixtures;
24
- /**
25
- * Returns Before() / After() functions.
26
- */
27
- function scenarioHookFactory(type) {
28
- return (...args) => {
29
- addHook({
30
- type,
31
- options: getOptionsFromArgs(args),
32
- fn: getFnFromArgs(args),
33
- // offset = 3 b/c this call is 3 steps below the user's code
34
- location: (0, _getLocationInFile.getLocationByOffset)(3)
35
- });
36
- };
37
- }
38
- function hasScenarioHooks() {
39
- return scenarioHooks.length > 0;
40
- }
41
- // eslint-disable-next-line complexity, max-statements
42
- async function runScenarioHooks(type, fixtures) {
43
- let error;
44
- for (const hook of scenarioHooks) {
45
- if (hook.type !== type) {
46
- continue;
47
- }
48
- if (hook.tagsExpression && !hook.tagsExpression.evaluate(fixtures.$tags)) {
49
- continue;
50
- }
51
- try {
52
- const hookFn = wrapHookFn(hook, fixtures);
53
- await (0, _testTypeImpl.runStepWithCustomLocation)(fixtures.$bddWorld.test, hook.options.name || '', hook.location, hookFn);
54
- } catch (e) {
55
- if (type === 'before') {
56
- throw e;
57
- }
58
- if (!error) {
59
- error = e;
60
- }
61
- }
62
- }
63
- if (error) {
64
- throw error;
65
- }
66
- }
67
- function getScenarioHooksFixtures() {
68
- if (!scenarioHooksFixtures) {
69
- const fixturesFakeObj = {
70
- $bddWorld: null,
71
- $tags: null,
72
- $testInfo: null
73
- };
74
- const set = new Set();
75
- scenarioHooks.forEach(hook => {
76
- (0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
77
- });
78
- scenarioHooksFixtures = [...set];
79
- }
80
- return scenarioHooksFixtures;
81
- }
82
- /**
83
- * Wraps hook fn with timeout and waiting Cucumber attachments to fulfill.
84
- */
85
- function wrapHookFn(hook, fixtures) {
86
- const {
87
- timeout
88
- } = hook.options;
89
- const {
90
- $bddWorld
91
- } = fixtures;
92
- return async () => {
93
- await (0, _utils.callWithTimeout)(() => hook.fn.call($bddWorld, fixtures), timeout, getTimeoutMessage(hook));
94
- };
95
- }
96
- function getOptionsFromArgs(args) {
97
- if (typeof args[0] === 'string') {
98
- return {
99
- tags: args[0]
100
- };
101
- }
102
- if (typeof args[0] === 'object') {
103
- return args[0];
104
- }
105
- return {};
106
- }
107
- function getFnFromArgs(args) {
108
- return args.length === 1 ? args[0] : args[1];
109
- }
110
- function setTagsExpression(hook) {
111
- if (hook.options.tags) {
112
- hook.tagsExpression = (0, _tagExpressions.default)(hook.options.tags);
113
- }
114
- }
115
- function addHook(hook) {
116
- setTagsExpression(hook);
117
- if (hook.type === 'before') {
118
- scenarioHooks.push(hook);
119
- } else {
120
- // 'after' hooks run in reverse order
121
- scenarioHooks.unshift(hook);
122
- }
123
- }
124
- function getTimeoutMessage(hook) {
125
- const {
126
- timeout,
127
- name: hookName
128
- } = hook.options;
129
- return `${hook.type} hook ${hookName ? `"${hookName}" ` : ''}timeout (${timeout} ms)`;
130
- }
@@ -1,89 +0,0 @@
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, getTimeoutMessage(hook));
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
- }
84
- function getTimeoutMessage(hook) {
85
- const {
86
- timeout
87
- } = hook.options;
88
- return `${hook.type} hook timeout (${timeout} ms)`;
89
- }
@@ -1,52 +0,0 @@
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, "cucumberReporter", {
31
- enumerable: true,
32
- get: function () {
33
- return _helper.cucumberReporter;
34
- }
35
- });
36
- Object.defineProperty(exports, "defineBddConfig", {
37
- enumerable: true,
38
- get: function () {
39
- return _config.defineBddConfig;
40
- }
41
- });
42
- Object.defineProperty(exports, "test", {
43
- enumerable: true,
44
- get: function () {
45
- return _bddFixtures.test;
46
- }
47
- });
48
- var _config = require("./config");
49
- var _createBdd = require("./steps/createBdd");
50
- var _bddFixtures = require("./run/bddFixtures");
51
- var _bddWorld = require("./run/bddWorld");
52
- var _helper = require("./reporter/cucumber/helper");
@@ -1,93 +0,0 @@
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') {
15
- return [];
16
- }
17
- if (!fn[signatureSymbol]) {
18
- fn[signatureSymbol] = innerFixtureParameterNames(fn);
19
- }
20
- return fn[signatureSymbol];
21
- }
22
- function innerFixtureParameterNames(fn) {
23
- const text = filterOutComments(fn.toString());
24
- const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
25
- if (!match) {
26
- return [];
27
- }
28
- const trimmedParams = match[1].trim();
29
- if (!trimmedParams) {
30
- return [];
31
- }
32
- const [firstParam] = splitByComma(trimmedParams);
33
- if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
34
- throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
35
- }
36
- const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
37
- const colon = prop.indexOf(':');
38
- return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
39
- });
40
- const restProperty = props.find(prop => prop.startsWith('...'));
41
- if (restProperty) {
42
- throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
43
- }
44
- return props;
45
- }
46
- function filterOutComments(s) {
47
- const result = [];
48
- let commentState = 'none';
49
- for (let i = 0; i < s.length; ++i) {
50
- if (commentState === 'singleline') {
51
- if (s[i] === '\n') {
52
- commentState = 'none';
53
- }
54
- } else if (commentState === 'multiline') {
55
- if (s[i - 1] === '*' && s[i] === '/') {
56
- commentState = 'none';
57
- }
58
- } else if (commentState === 'none') {
59
- if (s[i] === '/' && s[i + 1] === '/') {
60
- commentState = 'singleline';
61
- } else if (s[i] === '/' && s[i + 1] === '*') {
62
- commentState = 'multiline';
63
- i += 2;
64
- } else {
65
- result.push(s[i]);
66
- }
67
- }
68
- }
69
- return result.join('');
70
- }
71
- function splitByComma(s) {
72
- const result = [];
73
- const stack = [];
74
- let start = 0;
75
- for (let i = 0; i < s.length; i++) {
76
- if (s[i] === '{' || s[i] === '[') {
77
- stack.push(s[i] === '{' ? '}' : ']');
78
- } else if (s[i] === stack[stack.length - 1]) {
79
- stack.pop();
80
- } else if (!stack.length && s[i] === ',') {
81
- const token = s.substring(start, i).trim();
82
- if (token) {
83
- result.push(token);
84
- }
85
- start = i + 1;
86
- }
87
- }
88
- const lastToken = s.substring(start).trim();
89
- if (lastToken) {
90
- result.push(lastToken);
91
- }
92
- return result;
93
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getLocationByOffset = getLocationByOffset;
8
- exports.getLocationInFile = getLocationInFile;
9
- var _url = _interopRequireDefault(require("url"));
10
- var _utils = require("./utils");
11
- /**
12
- * Finds first frame in the callstack that matches provided file.
13
- * Constructs location object from that frame.
14
- *
15
- * Example:
16
- * Calling getLocationInFile('file-3.js');
17
- * Call stack:
18
- * - at <anonymous> (file-1.js:1:2)
19
- * - at myFunction2 (file-2.js:3:4)
20
- * - at myFunction3 (file-3.js:5:6)
21
- * - at myFunction4 (file-4.js:7:8)
22
- *
23
- * Returned value: { file: 'file-3.js', line: 5, column: 6 }
24
- */
25
- function getLocationInFile(filePath) {
26
- const filePathUrl = _url.default.pathToFileURL(filePath).toString();
27
- return getLocationBy(stackFrames => {
28
- return stackFrames.find(frame => {
29
- const frameFile = frame.getFileName();
30
- return frameFile === filePath || frameFile === filePathUrl;
31
- });
32
- });
33
- }
34
- function getLocationByOffset(offset) {
35
- return getLocationBy(stackFrames => stackFrames[offset]);
36
- }
37
- /**
38
- * Iterates stacktrace of the call of this function
39
- * and finds frame using provided findFrame predicate.
40
- * Constructs location object from the found frame.
41
- *
42
- * This function is based on Playwright's wrapFunctionWithLocation().
43
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/transform/transform.ts#L261
44
- */
45
- function getLocationBy(findFrame) {
46
- const {
47
- sourceMapSupport
48
- } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
49
- const oldPrepareStackTrace = Error.prepareStackTrace;
50
- // modify prepareStackTrace to return Location object instead of string
51
- Error.prepareStackTrace = (error, stackFrames) => {
52
- const foundFrame = findFrame(stackFrames);
53
- if (!foundFrame) {
54
- return {
55
- file: '',
56
- line: 0,
57
- column: 0
58
- };
59
- }
60
- const frame = sourceMapSupport.wrapCallSite(foundFrame);
61
- const fileName = frame.getFileName();
62
- // Node error stacks for modules use file:// urls instead of paths.
63
- const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
64
- return {
65
- file,
66
- line: frame.getLineNumber(),
67
- column: frame.getColumnNumber()
68
- };
69
- };
70
- // commented stackTraceLImit modification, todo: check if it has perf impact
71
- // const oldStackTraceLimit = Error.stackTraceLimit;
72
- // Error.stackTraceLimit = level + 1;
73
- const obj = {};
74
- Error.captureStackTrace(obj);
75
- const location = obj.stack;
76
- // Error.stackTraceLimit = oldStackTraceLimit;
77
- Error.prepareStackTrace = oldPrepareStackTrace;
78
- return location;
79
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.requireOrImportDefaultFunction = requireOrImportDefaultFunction;
8
- var _path = _interopRequireDefault(require("path"));
9
- var _transform = require("./transform");
10
- /**
11
- * Partial from: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/runner/loadUtils.ts
12
- */
13
- /* eslint-disable complexity */
14
-
15
- async function requireOrImportDefaultFunction(file, expectConstructor) {
16
- let func = await (0, _transform.requireTransform)().requireOrImport(file);
17
- if (func && typeof func === 'object' && 'default' in func) {
18
- func = func['default'];
19
- }
20
- if (typeof func !== 'function') {
21
- throw errorWithFile(file, `file must export a single ${expectConstructor ? 'class' : 'function'}.`);
22
- }
23
- return func;
24
- }
25
- function relativeFilePath(file) {
26
- if (!_path.default.isAbsolute(file)) {
27
- return file;
28
- }
29
- return _path.default.relative(process.cwd(), file);
30
- }
31
- function errorWithFile(file, message) {
32
- return new Error(`${relativeFilePath(file)}: ${message}`);
33
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isTestContainsSubtest = isTestContainsSubtest;
7
- exports.runStepWithCustomLocation = runStepWithCustomLocation;
8
- var _test = require("@playwright/test");
9
- var _utils = require("../utils");
10
- var _utils2 = require("./utils");
11
- /**
12
- * Helpers to deal with Playwright test internal stuff.
13
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/testType.ts
14
- */
15
-
16
- const testTypeSymbol = (0, _utils.getSymbolByName)(_test.test, 'testType');
17
- /**
18
- * Returns test fixtures using Symbol.
19
- */
20
- function getTestFixtures(test) {
21
- return getTestImpl(test).fixtures;
22
- }
23
- function getTestImpl(test) {
24
- return test[testTypeSymbol];
25
- }
26
- /**
27
- * Run step with location pointing to Given, When, Then call.
28
- */
29
- // eslint-disable-next-line max-params
30
- async function runStepWithCustomLocation(test, stepText, location, body) {
31
- // Since PW 1.43 testInfo._runAsStep was replaced with a more complex logic.
32
- // To run step with a custom location, we hijack testInfo._addStep()
33
- // so that it appends location for the bdd step calls.
34
- // Finally we call test.step(), that internally invokes testInfo._addStep().
35
- // See: https://github.com/microsoft/playwright/issues/30160
36
- // See: https://github.com/microsoft/playwright/blob/release-1.43/packages/playwright/src/common/testType.ts#L262
37
- // See: https://github.com/microsoft/playwright/blob/release-1.43/packages/playwright/src/worker/testInfo.ts#L247
38
- if (_utils2.playwrightVersion >= '1.39.0') {
39
- const testInfo = test.info();
40
- // here we rely on that testInfo._addStep is called synchronously in test.step()
41
- const origAddStep = testInfo._addStep;
42
- testInfo._addStep = function (data) {
43
- data.location = location;
44
- testInfo._addStep = origAddStep;
45
- return origAddStep.call(this, data);
46
- };
47
- return test.step(stepText, body);
48
- } else {
49
- const testInfo = test.info();
50
- return testInfo._runAsStep({
51
- category: 'test.step',
52
- title: stepText,
53
- location
54
- }, async () => {
55
- return await body();
56
- });
57
- }
58
- }
59
- /**
60
- * Returns true if test contains all fixtures of subtest.
61
- * - test was extended from subtest
62
- * - test is a result of mergeTests(subtest, ...)
63
- */
64
- function isTestContainsSubtest(test, subtest) {
65
- if (test === subtest) {
66
- return true;
67
- }
68
- const testFixtures = new Set(getTestFixtures(test).map(f => locationToString(f.location)));
69
- return getTestFixtures(subtest).every(f => {
70
- return testFixtures.has(locationToString(f.location));
71
- });
72
- }
73
- function locationToString({
74
- file,
75
- line,
76
- column
77
- }) {
78
- return `${file}:${line}:${column}`;
79
- }
@@ -1,88 +0,0 @@
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) {
34
- specifier = resolved;
35
- }
36
- }
37
- return originalResolveFilename.call(this, specifier, parent, ...rest);
38
- }
39
- _module.default._resolveFilename = resolveFilename;
40
- const revertPirates = pirates.addHook((code, filename) => {
41
- if (!shouldTransform(filename)) {
42
- return code;
43
- }
44
- // Since PW 1.42 transformHook returns { code, serializedCache } instead of code string
45
- // See: https://github.com/microsoft/playwright/commit/f605a5009b3c75746120a6ec6d940f62624af5ec#diff-0f8a2f313f1572108f59a6e84663858ebb4fc455163410526b56878794001103
46
- // See: https://github.com/vitalets/playwright-bdd/issues/96
47
- const res = transformHook(code, filename);
48
- return typeof res === 'string' ? res : res.code;
49
- }, {
50
- exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
51
- });
52
- return () => {
53
- reverted = true;
54
- _module.default._resolveFilename = originalResolveFilename;
55
- revertPirates();
56
- };
57
- }
58
- function requireTransform() {
59
- const transformPathSince1_35 = (0, _utils.getPlaywrightModulePath)('lib/transform/transform.js');
60
- if (_fs.default.existsSync(transformPathSince1_35)) {
61
- const {
62
- resolveHook,
63
- shouldTransform,
64
- transformHook,
65
- requireOrImport
66
- } = (0, _utils.requirePlaywrightModule)(transformPathSince1_35);
67
- return {
68
- resolveHook,
69
- shouldTransform,
70
- transformHook,
71
- requireOrImport
72
- };
73
- } else {
74
- const {
75
- resolveHook,
76
- transformHook,
77
- requireOrImport
78
- } = (0, _utils.requirePlaywrightModule)('lib/common/transform.js');
79
- // see: https://github.com/microsoft/playwright/blob/b4ffb848de1b00e9a0abad6dacdccce60cce9bed/packages/playwright-test/src/reporters/base.ts#L524
80
- const shouldTransform = file => !file.includes(`${_path.default.sep}node_modules${_path.default.sep}`);
81
- return {
82
- resolveHook,
83
- shouldTransform,
84
- transformHook,
85
- requireOrImport
86
- };
87
- }
88
- }