@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,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FeaturesLoader = void 0;
7
- var _gherkinStreams = require("@cucumber/gherkin-streams");
8
- var _gherkinUtils = require("@cucumber/gherkin-utils");
9
- /**
10
- * Load features.
11
- *
12
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
13
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts
14
- */
15
-
16
- class FeaturesLoader {
17
- gherkinQuery = new _gherkinUtils.Query();
18
- parseErrors = [];
19
- /**
20
- * Loads and parses feature files.
21
- * - featurePaths should be absolute.
22
- * See: https://github.com/cucumber/gherkin-streams/blob/main/src/GherkinStreams.ts#L36
23
- * - if options.relativeTo is provided, uri in gherkin documents will be relative to it.
24
- * See: https://github.com/cucumber/gherkin-streams/blob/main/src/SourceMessageStream.ts#L31
25
- * - options.defaultDialect is 'en' by default.
26
- * See: https://github.com/cucumber/gherkin-streams/blob/main/src/makeGherkinOptions.ts#L5
27
- */
28
- async load(featurePaths, options) {
29
- this.gherkinQuery = new _gherkinUtils.Query();
30
- this.parseErrors = [];
31
- await gherkinFromPaths(featurePaths, options, envelope => {
32
- this.gherkinQuery.update(envelope);
33
- if (envelope.parseError) {
34
- this.parseErrors.push(envelope.parseError);
35
- }
36
- });
37
- }
38
- getDocumentsCount() {
39
- return this.gherkinQuery.getGherkinDocuments().length;
40
- }
41
- getDocumentsWithPickles() {
42
- return this.gherkinQuery.getGherkinDocuments().map(gherkinDocument => {
43
- const pickles = this.getDocumentPickles(gherkinDocument);
44
- return {
45
- ...gherkinDocument,
46
- pickles
47
- };
48
- });
49
- }
50
- getDocumentPickles(gherkinDocument) {
51
- return this.gherkinQuery.getPickles().filter(pickle => gherkinDocument.uri === pickle.uri).map(pickle => this.getPickleWithLocation(pickle));
52
- }
53
- getPickleWithLocation(pickle) {
54
- const lastAstNodeId = pickle.astNodeIds[pickle.astNodeIds.length - 1];
55
- const location = this.gherkinQuery.getLocation(lastAstNodeId);
56
- return {
57
- ...pickle,
58
- location
59
- };
60
- }
61
- }
62
- exports.FeaturesLoader = FeaturesLoader;
63
- async function gherkinFromPaths(paths, options, onEnvelope) {
64
- return new Promise((resolve, reject) => {
65
- const gherkinMessageStream = _gherkinStreams.GherkinStreams.fromPaths(paths, options);
66
- gherkinMessageStream.on('data', onEnvelope);
67
- gherkinMessageStream.on('end', resolve);
68
- gherkinMessageStream.on('error', reject);
69
- });
70
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadSnippetBuilder = loadSnippetBuilder;
7
- var _cucumber = require("@cucumber/cucumber");
8
- /**
9
- * Loads snippet builder
10
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/builder.ts
11
- */
12
-
13
- async function loadSnippetBuilder(supportCodeLibrary, snippetInterface, snippetSyntax) {
14
- return _cucumber.FormatterBuilder.getStepDefinitionSnippetBuilder({
15
- cwd: process.cwd(),
16
- snippetInterface,
17
- snippetSyntax,
18
- supportCodeLibrary
19
- });
20
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findStepDefinition = findStepDefinition;
7
- exports.hasTsNodeRegister = hasTsNodeRegister;
8
- exports.loadSteps = loadSteps;
9
- var _api = require("@cucumber/cucumber/api");
10
- var _transform = require("../playwright/transform");
11
- var _exit = require("../utils/exit");
12
- const cache = new Map();
13
- async function loadSteps(runConfiguration, environment = {}) {
14
- const cacheKey = JSON.stringify(runConfiguration);
15
- let lib = cache.get(cacheKey);
16
- if (!lib) {
17
- // use Playwright's built-in hook to compile TypeScript steps
18
- const uninstall = !hasTsNodeRegister(runConfiguration) ? (0, _transform.installTransform)() : () => {};
19
- lib = (0, _api.loadSupport)(runConfiguration, environment).finally(() => uninstall());
20
- cache.set(cacheKey, lib);
21
- }
22
- return lib;
23
- }
24
- /**
25
- * Finds step definition by step text.
26
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/runtime/assemble_test_cases.ts#L103
27
- *
28
- * Handling case when several step definitions found:
29
- * https://github.com/cucumber/cucumber-js/blob/main/src/runtime/test_case_runner.ts#L313
30
- */
31
- function findStepDefinition(supportCodeLibrary, stepText, file) {
32
- const matchedSteps = supportCodeLibrary.stepDefinitions.filter(step => {
33
- return step.matchesStepName(stepText);
34
- });
35
- if (matchedSteps.length === 0) {
36
- return;
37
- }
38
- if (matchedSteps.length > 1) {
39
- (0, _exit.exit)([`Multiple step definitions matched for text: "${stepText}" (${file})`,
40
- // todo: print location of every step definition (as in cucumber)
41
- ...matchedSteps.map(s => ` ${s.pattern}`)].join('\n'));
42
- }
43
- return matchedSteps[0];
44
- }
45
- function hasTsNodeRegister(runConfiguration) {
46
- return runConfiguration.support.requireModules.includes('ts-node/register');
47
- }
@@ -1,62 +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.resovleFeaturePaths = resovleFeaturePaths;
8
- var _fs = _interopRequireDefault(require("fs"));
9
- var _path = _interopRequireDefault(require("path"));
10
- var _environment = require("@cucumber/cucumber/lib/api/environment");
11
- var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
12
- var _utils = require("../utils");
13
- /**
14
- * Representation of https://github.com/cucumber/cucumber-js/blob/main/src/paths/paths.ts
15
- * Since Cucumber 10.1 resolvePaths was moved from lib/api/paths to lib/paths/paths.
16
- * This module makes resolvePaths working with any version of Cucumber.
17
- * See: https://github.com/cucumber/cucumber-js/pull/2361/files
18
- *
19
- * todo: replace with own paths resolution.
20
- */
21
-
22
- /**
23
- * Returns list of absolute feature paths.
24
- */
25
- // eslint-disable-next-line max-statements
26
- async function resovleFeaturePaths(runConfiguration, environment = {}) {
27
- const {
28
- cwd,
29
- stderr,
30
- debug
31
- } = (0, _environment.mergeEnvironment)(environment);
32
- const logger = new _console_logger.ConsoleLogger(stderr, debug);
33
- const cucumberRoot = (0, _utils.resolvePackageRoot)('@cucumber/cucumber');
34
- const pathsModuleBefore10_1 = _path.default.join(cucumberRoot, 'lib/api/paths.js');
35
- const pathsModuleAfter10_1 = _path.default.join(cucumberRoot, 'lib/paths/paths.js');
36
- const isNewResolvePaths = _fs.default.existsSync(pathsModuleAfter10_1);
37
- if (isNewResolvePaths) {
38
- const {
39
- resolvePaths
40
- } = require(pathsModuleAfter10_1);
41
- const {
42
- sourcePaths,
43
- unexpandedSourcePaths
44
- } = await resolvePaths(logger, cwd, runConfiguration.sources);
45
- return {
46
- featurePaths: sourcePaths,
47
- unexpandedFeaturePaths: unexpandedSourcePaths
48
- };
49
- } else {
50
- const {
51
- resolvePaths
52
- } = require(pathsModuleBefore10_1);
53
- const {
54
- featurePaths,
55
- unexpandedFeaturePaths
56
- } = await resolvePaths(logger, cwd, runConfiguration.sources);
57
- return {
58
- featurePaths,
59
- unexpandedFeaturePaths
60
- };
61
- }
62
- }
@@ -1,21 +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.parseStepArgument = parseStepArgument;
8
- var _util = _interopRequireDefault(require("util"));
9
- var _valueChecker = require("./valueChecker");
10
- /**
11
- * Based on: https://github.com/cucumber/cucumber-js/blob/main/src/step_arguments.ts
12
- */
13
-
14
- function parseStepArgument(arg, mapping) {
15
- if ((0, _valueChecker.doesHaveValue)(arg.dataTable)) {
16
- return mapping.dataTable(arg.dataTable);
17
- } else if ((0, _valueChecker.doesHaveValue)(arg.docString)) {
18
- return mapping.docString(arg.docString);
19
- }
20
- throw new Error(`Unknown step argument: ${_util.default.inspect(arg)}`);
21
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.doesHaveValue = doesHaveValue;
7
- exports.doesNotHaveValue = doesNotHaveValue;
8
- exports.valueOrDefault = valueOrDefault;
9
- /**
10
- * Based on: https://github.com/cucumber/cucumber-js/blob/main/src/value_checker.ts
11
- */
12
- function doesHaveValue(value) {
13
- return !doesNotHaveValue(value);
14
- }
15
- function doesNotHaveValue(value) {
16
- return value === null || value === undefined;
17
- }
18
- function valueOrDefault(value, defaultValue) {
19
- if (doesHaveValue(value)) {
20
- return value;
21
- }
22
- return defaultValue;
23
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Fixture", {
7
- enumerable: true,
8
- get: function () {
9
- return _class.Fixture;
10
- }
11
- });
12
- exports.When = exports.Then = exports.Step = exports.Given = void 0;
13
- var _class = require("./steps/decorators/class");
14
- var _steps = require("./steps/decorators/steps");
15
- const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
16
- const When = exports.When = (0, _steps.createStepDecorator)('When');
17
- const Then = exports.Then = (0, _steps.createStepDecorator)('Then');
18
- const Step = exports.Step = (0, _steps.createStepDecorator)('Unknown');
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractFixtureNames = extractFixtureNames;
7
- exports.extractFixtureNamesFromFnBodyMemo = extractFixtureNamesFromFnBodyMemo;
8
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
9
- var _bddFixtures = require("../run/bddFixtures");
10
- var _exit = require("../utils/exit");
11
- const bodyFixturesSymbol = Symbol('bodyFixtures');
12
- /**
13
- * This function is used for playwright-style steps and decorators.
14
- * It extracts fixtures names from first parameter of function
15
- * using Playwright's helper.
16
- */
17
- function extractFixtureNames(fn) {
18
- return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
19
- }
20
- /**
21
- * This function is used for cucumber-style steps.
22
- * It looks for `this.useFixture('xxx')` entries in function body
23
- * and extracts fixtures names from it.
24
- */
25
- function extractFixtureNamesFromFnBodyMemo(fn) {
26
- if (typeof fn !== 'function') {
27
- return [];
28
- }
29
- const fnWithFixtures = fn;
30
- if (!fnWithFixtures[bodyFixturesSymbol]) {
31
- fnWithFixtures[bodyFixturesSymbol] = extractFixtureNamesFromFnBody(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
32
- }
33
- return fnWithFixtures[bodyFixturesSymbol];
34
- }
35
- function extractFixtureNamesFromFnBody(fn) {
36
- const matches = fn.toString().matchAll(/this\.useFixture\((.+)\)/gi) || [];
37
- return [...matches].map(match => getFixtureName(match[1]));
38
- }
39
- function getFixtureName(arg) {
40
- if (!/^['"`]/.test(arg)) {
41
- // todo: log file location with incorrect useFixture
42
- (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
43
- }
44
- if (arg.startsWith('`') && arg.includes('${')) {
45
- (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
46
- }
47
- return arg.replace(/['"`]/g, '');
48
- }
@@ -1,167 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Formatter = void 0;
7
- var _jsStringWrap = require("../utils/jsStringWrap");
8
- var _utils = require("../utils");
9
- var _utils2 = require("../playwright/utils");
10
- /**
11
- * Helper to format Playwright test file.
12
- */
13
-
14
- const supportsTags = _utils2.playwrightVersion >= '1.42.0';
15
- class Formatter {
16
- config;
17
- constructor(config) {
18
- this.config = config;
19
- }
20
- fileHeader(featureUri, importTestFrom) {
21
- // always use "/" for imports, see #91
22
- const importTestFromFile = (0, _utils.toPosixPath)((importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary');
23
- let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
24
- if (varName !== 'test') {
25
- varName = `${varName} as test`;
26
- }
27
- return [`/** Generated from: ${featureUri} */`,
28
- // prettier-ignore
29
- // this.quoted() is not possible for 'import from' as backticks not parsed
30
- `import { ${varName} } from ${JSON.stringify(importTestFromFile)};`, ''];
31
- }
32
- describe(node, children) {
33
- const firstLine = `test.${this.getFunction('describe', node)}(${this.quoted(node.title)}, () => {`;
34
- if (!children.length) {
35
- return [`${firstLine}});`, ''];
36
- }
37
- return [firstLine,
38
- // prettier-ignore
39
- ...this.describeConfigure(node).map(indent), '', ...children.map(indent), `});`, ''];
40
- }
41
- beforeEach(fixtures, children) {
42
- const fixturesStr = [...fixtures].join(', ');
43
- // prettier-ignore
44
- return [`test.beforeEach(async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
45
- }
46
- test(node, fixtures, children) {
47
- const fixturesStr = [...fixtures].join(', ');
48
- const title = this.quoted(node.title);
49
- const tags = this.testTags(node);
50
- const firstLine = `${this.getFunction('test', node)}(${title}, ${tags}async ({ ${fixturesStr} }) => {`;
51
- if (!children.length) {
52
- return [`${firstLine}});`, ''];
53
- }
54
- const lines = [firstLine,
55
- // prettier-ignore
56
- ...children.map(indent), `});`, ''];
57
- // wrap test into anonymous describe in case of retries / timeout tags
58
- const specialTagsConfigure = this.describeConfigure(node);
59
- return specialTagsConfigure.length ? ['test.describe(() => {',
60
- // prettier-ignore
61
- ...specialTagsConfigure.map(indent), '', ...lines.map(indent), `});`, ''] : lines;
62
- }
63
- // eslint-disable-next-line max-params
64
- step(keyword, text, argument, fixtureNames = []) {
65
- const fixtures = fixtureNames.length ? `{ ${fixtureNames.join(', ')} }` : '';
66
- const argumentArg = argument ? JSON.stringify(argument) : fixtures ? 'null' : '';
67
- const textArg = this.quoted(text);
68
- const args = [textArg, argumentArg, fixtures].filter(arg => arg !== '').join(', ');
69
- return `await ${keyword}(${args});`;
70
- }
71
- missingStep(keyword, text) {
72
- return `// missing step: ${keyword}(${this.quoted(text)});`;
73
- }
74
- technicalSection(testMetaBuilder, featureUri, fixtures) {
75
- return ['// == technical section ==',
76
- // prettier-ignore
77
- '', 'test.use({', ...['$test: ({}, use) => use(test),', '$testMetaMap: ({}, use) => use(testMetaMap),', `$uri: ({}, use) => use(${this.quoted(featureUri)}),`, ...fixtures].map(indent), '});', '', 'const testMetaMap = {', ...testMetaBuilder.getObjectLines().map(indent), '};'];
78
- }
79
- bddWorldFixtures() {
80
- const fixturesObj = {
81
- page: null,
82
- context: null,
83
- browser: null,
84
- browserName: null,
85
- request: null
86
- };
87
- const fixtures = Object.keys(fixturesObj).join(', ');
88
- return [`$bddWorldFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
89
- }
90
- scenarioHookFixtures(fixtureNames) {
91
- if (!fixtureNames.length) {
92
- return [];
93
- }
94
- const fixtures = fixtureNames.join(', ');
95
- return [`$scenarioHookFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
96
- }
97
- workerHookFixtures(fixtureNames) {
98
- if (!fixtureNames.length) {
99
- return [];
100
- }
101
- const fixtures = fixtureNames.join(', ');
102
- const scope = this.quoted('worker');
103
- return [`$workerHookFixtures: [({ ${fixtures} }, use) => use({ ${fixtures} }), { scope: ${scope} }],`];
104
- }
105
- langFixture(lang) {
106
- return [`$lang: ({}, use) => use(${this.quoted(lang)}),`];
107
- }
108
- // eslint-disable-next-line complexity
109
- getFunction(baseFn, node) {
110
- if (node.specialTags.only) {
111
- return `${baseFn}.only`;
112
- }
113
- // describe.fail is not supported
114
- if (baseFn === 'test' && node.specialTags.fail) {
115
- return `${baseFn}.fail`;
116
- }
117
- if (node.specialTags.skip) {
118
- return `${baseFn}.skip`;
119
- }
120
- if (node.specialTags.fixme) {
121
- return `${baseFn}.fixme`;
122
- }
123
- return baseFn;
124
- }
125
- describeConfigure(node) {
126
- const options = {};
127
- const {
128
- retries,
129
- timeout,
130
- mode
131
- } = node.specialTags;
132
- if (retries !== undefined) {
133
- options.retries = retries;
134
- }
135
- if (timeout !== undefined) {
136
- options.timeout = timeout;
137
- }
138
- if (mode !== undefined) {
139
- options.mode = mode;
140
- }
141
- return Object.keys(options).length ? [`test.describe.configure(${JSON.stringify(options)});`] : [];
142
- }
143
- testTags(node) {
144
- return supportsTags && node.tags.length ? `{ tag: [${node.tags.map(tag => this.quoted(tag)).join(', ')}] }, ` : '';
145
- }
146
- testTimeout(node) {
147
- const {
148
- timeout
149
- } = node.specialTags;
150
- return timeout !== undefined ? [`test.setTimeout(${timeout});`] : [];
151
- }
152
- /**
153
- * Apply this function only to string literals (mostly titles here).
154
- * Objects and arrays are handled with JSON.strinigfy,
155
- * b/c object keys can't be in backticks.
156
- * See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
157
- */
158
- quoted(str) {
159
- return (0, _jsStringWrap.jsStringWrap)(str, {
160
- quotes: this.config.quotes
161
- });
162
- }
163
- }
164
- exports.Formatter = Formatter;
165
- function indent(value) {
166
- return value ? `${' '}${value}` : value;
167
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getKeywordsMap = getKeywordsMap;
7
- var _gherkin = require("@cucumber/gherkin");
8
- /**
9
- * Get i18n keywords.
10
- * See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
11
- */
12
-
13
- function getKeywordsMap(language) {
14
- const origMap = _gherkin.dialects[language];
15
- if (!origMap) {
16
- throw new Error(`Language not found: ${language}`);
17
- }
18
- const targetMap = new Map();
19
- const enKeywords = Object.keys(origMap);
20
- enKeywords.forEach(enKeyword => handleKeyword(enKeyword, origMap, targetMap));
21
- return targetMap;
22
- }
23
- function handleKeyword(enKeyword, origMap, targetMap) {
24
- const nativeKeywords = origMap[enKeyword];
25
- // Array.isArray converts to any[]
26
- if (typeof nativeKeywords === 'string') {
27
- return;
28
- }
29
- nativeKeywords.forEach(nativeKeyword => {
30
- nativeKeyword = nativeKeyword.trim();
31
- if (!nativeKeyword || nativeKeyword === '*') {
32
- return;
33
- }
34
- targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
35
- });
36
- }
37
- function capitalizeFirstLetter(s) {
38
- return s.charAt(0).toUpperCase() + s.slice(1);
39
- }