@zohodesk/testinglibrary 0.1.8-exp-bdd-v1 → 0.1.8-exp-bdd-v3

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 (70) hide show
  1. package/build/bdd-poc/core-runner/stepDefinitions.js +1 -1
  2. package/build/bdd-poc/runner.js +2 -2
  3. package/build/bdd-poc/test/cucumber/featureFileParer.js +4 -5
  4. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +8 -9
  5. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +2 -1
  6. package/build/bdd-poc/test/testDataMap.js +2 -2
  7. package/build/bdd-poc/test/testStructure.js +3 -4
  8. package/build/core/jest/preprocessor/jsPreprocessor.js +3 -2
  9. package/build/core/playwright/custom-commands.js +2 -1
  10. package/build/core/playwright/index.js +8 -18
  11. package/build/core/playwright/readConfigFile.js +2 -1
  12. package/build/core/playwright/setup/config-creator.js +4 -5
  13. package/build/core/playwright/setup/config-utils.js +14 -13
  14. package/build/core/playwright/test-runner.js +33 -27
  15. package/build/decorators.d.ts +1 -1
  16. package/build/decorators.js +2 -16
  17. package/build/parser/parser.js +1 -0
  18. package/build/utils/logger.js +2 -1
  19. package/build/utils/stepDefinitionsFormatter.js +2 -1
  20. package/npm-shrinkwrap.json +4 -570
  21. package/package.json +3 -3
  22. package/build/bdd-framework/cli/commands/env.js +0 -42
  23. package/build/bdd-framework/cli/commands/export.js +0 -47
  24. package/build/bdd-framework/cli/commands/test.js +0 -60
  25. package/build/bdd-framework/cli/index.js +0 -11
  26. package/build/bdd-framework/cli/options.js +0 -19
  27. package/build/bdd-framework/cli/worker.js +0 -13
  28. package/build/bdd-framework/config/dir.js +0 -27
  29. package/build/bdd-framework/config/env.js +0 -49
  30. package/build/bdd-framework/config/index.js +0 -90
  31. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  32. package/build/bdd-framework/cucumber/gherkin.d.js +0 -5
  33. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  34. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  35. package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
  36. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  37. package/build/bdd-framework/cucumber/loadSources.js +0 -57
  38. package/build/bdd-framework/cucumber/loadSteps.js +0 -35
  39. package/build/bdd-framework/decorators.js +0 -18
  40. package/build/bdd-framework/gen/formatter.js +0 -88
  41. package/build/bdd-framework/gen/i18n.js +0 -35
  42. package/build/bdd-framework/gen/index.js +0 -163
  43. package/build/bdd-framework/gen/poms.js +0 -46
  44. package/build/bdd-framework/gen/testFile.js +0 -356
  45. package/build/bdd-framework/gen/testNode.js +0 -48
  46. package/build/bdd-framework/gen/testPoms.js +0 -123
  47. package/build/bdd-framework/index.js +0 -45
  48. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -77
  49. package/build/bdd-framework/playwright/getLocationInFile.js +0 -46
  50. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  51. package/build/bdd-framework/playwright/testTypeImpl.js +0 -57
  52. package/build/bdd-framework/playwright/transform.js +0 -80
  53. package/build/bdd-framework/playwright/types.js +0 -5
  54. package/build/bdd-framework/playwright/utils.js +0 -37
  55. package/build/bdd-framework/run/bddFixtures.js +0 -107
  56. package/build/bdd-framework/run/bddWorld.js +0 -88
  57. package/build/bdd-framework/snippets/index.js +0 -134
  58. package/build/bdd-framework/snippets/snippetSyntax.js +0 -41
  59. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  60. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  61. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -49
  62. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -108
  63. package/build/bdd-framework/stepDefinitions/decorators/poms.js +0 -64
  64. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -93
  65. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -61
  66. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  67. package/build/bdd-framework/utils/exit.js +0 -54
  68. package/build/bdd-framework/utils/index.js +0 -44
  69. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  70. package/build/bdd-framework/utils/logger.js +0 -28
@@ -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 _poms.Fixture;
10
- }
11
- });
12
- exports.When = exports.Then = exports.Step = exports.Given = void 0;
13
- var _poms = require("./stepDefinitions/decorators/poms");
14
- var _steps = require("./stepDefinitions/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,88 +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
- /**
9
- * Helper to format Playwright test file.
10
- */
11
-
12
- const TAGS_FIXTURE_TEST_KEY_SEPARATOR = '|';
13
- class Formatter {
14
- config;
15
- constructor(config) {
16
- this.config = config;
17
- }
18
- fileHeader(uri, importTestFrom) {
19
- const file = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary';
20
- let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
21
- if (varName !== 'test') varName = `${varName} as test`;
22
- return [`/** Generated from: ${uri} */`,
23
- // this.quoted() is not possible for 'import from' as backticks not parsed
24
- `import { ${varName} } from ${JSON.stringify(file)};`, ''];
25
- }
26
- suite(node, children) {
27
- // prettier-ignore
28
- return [`test.describe${this.getSubFn(node)}(${this.quoted(node.title)}, () => {`, '', ...children.map(indent), `});`, ''];
29
- }
30
- beforeEach(fixtures, children) {
31
- const fixturesStr = [...fixtures].join(', ');
32
- // prettier-ignore
33
- return [`test.beforeEach(async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
34
- }
35
- test(node, fixtures, children) {
36
- const fixturesStr = [...fixtures].join(', ');
37
- // prettier-ignore
38
- return [`test${this.getSubFn(node)}(${this.quoted(node.title)}, async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
39
- }
40
- // eslint-disable-next-line max-params
41
- step(keyword, text, argument, fixtureNames = []) {
42
- const fixtures = fixtureNames.length ? `{ ${fixtureNames.join(', ')} }` : '';
43
- const argumentArg = argument ? JSON.stringify(argument) : fixtures ? 'null' : '';
44
- const textArg = this.quoted(text);
45
- const args = [textArg, argumentArg, fixtures].filter(arg => arg !== '').join(', ');
46
- return `await ${keyword}(${args});`;
47
- }
48
- missingStep(keyword, text) {
49
- return `// missing step: ${keyword}(${this.quoted(text)});`;
50
- }
51
- useFixtures(fixtures) {
52
- return fixtures.length > 0 ? ['// == technical section ==', '', 'test.use({', ...fixtures.map(indent), '});'] : [];
53
- }
54
- testFixture() {
55
- return ['$test: ({}, use) => use(test),'];
56
- }
57
- tagsFixture(testNodes) {
58
- const lines = testNodes.filter(node => node.tags.length).map(node => {
59
- // remove first parent as it is the same for all tests: root suite
60
- const key = node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR);
61
- return `${JSON.stringify(key)}: ${JSON.stringify(node.tags)},`;
62
- });
63
- return lines.length > 0 ? ['$tags: ({}, use, testInfo) => use({', ...lines.map(indent),
64
- // .slice(2) -> b/c we remove filename and root suite title
65
- `}[testInfo.titlePath.slice(2).join(${JSON.stringify(TAGS_FIXTURE_TEST_KEY_SEPARATOR)})] || []),`] : [];
66
- }
67
- getSubFn(node) {
68
- if (node.flags.only) return '.only';
69
- if (node.flags.skip) return '.skip';
70
- if (node.flags.fixme) return '.fixme';
71
- return '';
72
- }
73
- /**
74
- * Apply this function only to string literals (mostly titles here).
75
- * Objects and arrays are handled with JSON.strinigfy,
76
- * b/c object keys can't be in backtiks.
77
- * See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
78
- */
79
- quoted(str) {
80
- return (0, _jsStringWrap.jsStringWrap)(str, {
81
- quotes: this.config.quotes
82
- });
83
- }
84
- }
85
- exports.Formatter = Formatter;
86
- function indent(value) {
87
- return value ? `${' '}${value}` : value;
88
- }
@@ -1,35 +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') return;
27
- nativeKeywords.forEach(nativeKeyword => {
28
- nativeKeyword = nativeKeyword.trim();
29
- if (!nativeKeyword || nativeKeyword === '*') return;
30
- targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
31
- });
32
- }
33
- function capitalizeFirstLetter(s) {
34
- return s.charAt(0).toUpperCase() + s.slice(1);
35
- }
@@ -1,163 +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.TestFilesGenerator = void 0;
8
- var _promises = _interopRequireDefault(require("fs/promises"));
9
- var _path = _interopRequireDefault(require("path"));
10
- var _fastGlob = _interopRequireDefault(require("fast-glob"));
11
- var _testFile = require("./testFile");
12
- var _loadConfig = require("../cucumber/loadConfig");
13
- var _loadFeatures = require("../cucumber/loadFeatures");
14
- var _loadSteps = require("../cucumber/loadSteps");
15
- var _config = require("../config");
16
- var _snippets = require("../snippets");
17
- var _steps = require("../stepDefinitions/decorators/steps");
18
- var _transform = require("../playwright/transform");
19
- var _dir = require("../config/dir");
20
- var _logger = require("../utils/logger");
21
- var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
22
- var _exit = require("../utils/exit");
23
- /**
24
- * Generate playwright test files from Gherkin documents.
25
- */
26
-
27
- class TestFilesGenerator {
28
- config;
29
- // all these props are exist
30
- runConfiguration;
31
- features;
32
- supportCodeLibrary;
33
- files = [];
34
- tagsExpression;
35
- logger;
36
- constructor(config) {
37
- this.config = config;
38
- this.logger = new _logger.Logger({
39
- verbose: config.verbose
40
- });
41
- if (config.tags) this.tagsExpression = (0, _tagExpressions.default)(config.tags);
42
- }
43
- async generate() {
44
- await (0, _exit.withExitHandler)(async () => {
45
- await this.loadCucumberConfig();
46
- await Promise.all([this.loadFeatures(), this.loadSteps()]);
47
- this.buildFiles();
48
- await this.checkUndefinedSteps();
49
- this.checkImportCustomTest();
50
- await this.clearOutputDir();
51
- await this.saveFiles();
52
- });
53
- }
54
- async extractSteps() {
55
- await this.loadCucumberConfig();
56
- await this.loadSteps();
57
- return this.supportCodeLibrary.stepDefinitions;
58
- }
59
- async loadCucumberConfig() {
60
- const environment = {
61
- cwd: (0, _dir.getPlaywrightConfigDir)()
62
- };
63
- const {
64
- runConfiguration
65
- } = await (0, _loadConfig.loadConfig)({
66
- provided: (0, _config.extractCucumberConfig)(this.config)
67
- }, environment);
68
- this.runConfiguration = runConfiguration;
69
- this.warnForTsNodeRegister();
70
- }
71
- async loadFeatures() {
72
- const environment = {
73
- cwd: (0, _dir.getPlaywrightConfigDir)()
74
- };
75
- this.logger.log(`Loading features from: ${this.runConfiguration.sources.paths.join(', ')}`);
76
- this.features = await (0, _loadFeatures.loadFeatures)(this.runConfiguration, environment);
77
- this.logger.log(`Loaded features: ${this.features.size}`);
78
- }
79
- async loadSteps() {
80
- const {
81
- requirePaths,
82
- importPaths
83
- } = this.runConfiguration.support;
84
- this.logger.log(`Loading steps from: ${requirePaths.concat(importPaths).join(', ')}`);
85
- const environment = {
86
- cwd: (0, _dir.getPlaywrightConfigDir)()
87
- };
88
- this.supportCodeLibrary = await (0, _loadSteps.loadSteps)(this.runConfiguration, environment);
89
- await this.loadDecoratorSteps();
90
- this.logger.log(`Loaded steps: ${this.supportCodeLibrary.stepDefinitions.length}`);
91
- }
92
- async loadDecoratorSteps() {
93
- const {
94
- importTestFrom
95
- } = this.config;
96
- if (importTestFrom) {
97
- // require importTestFrom for case when it is not required by step definitions
98
- // possible re-require but it's not a problem as it is cached by Node.js
99
- await (0, _transform.requireTransform)().requireOrImport(importTestFrom.file);
100
- (0, _steps.appendDecoratorSteps)(this.supportCodeLibrary);
101
- }
102
- }
103
- buildFiles() {
104
- this.files = [...this.features.entries()].map(([doc, pickles]) => {
105
- return new _testFile.TestFile({
106
- doc,
107
- pickles,
108
- supportCodeLibrary: this.supportCodeLibrary,
109
- outputPath: this.getOutputPath(doc),
110
- config: this.config,
111
- tagsExpression: this.tagsExpression
112
- }).build();
113
- }).filter(file => file.testNodes.length > 0);
114
- }
115
- getOutputPath(doc) {
116
- const configDir = (0, _dir.getPlaywrightConfigDir)();
117
- // doc.uri is always relative to cwd (coming after cucumber handling)
118
- // see: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts#L51
119
- const relFeaturePath = doc.uri;
120
- const absFeaturePath = _path.default.resolve(configDir, relFeaturePath);
121
- const relOutputPath = _path.default.relative(this.config.featuresRoot, absFeaturePath);
122
- if (relOutputPath.startsWith('..')) {
123
- (0, _exit.exit)(`All feature files should be located underneath featuresRoot.`, `Please change featuresRoot or paths in configuration.\n`, `featureFile: ${absFeaturePath}\n`, `featuresRoot: ${this.config.featuresRoot}\n`);
124
- }
125
- const absOutputPath = _path.default.resolve(this.config.outputDir, relOutputPath);
126
- return `${absOutputPath}.spec.js`;
127
- }
128
- async checkUndefinedSteps() {
129
- const undefinedSteps = this.files.reduce((sum, file) => sum + file.undefinedSteps.length, 0);
130
- if (undefinedSteps > 0) {
131
- const snippets = new _snippets.Snippets(this.files, this.runConfiguration, this.supportCodeLibrary);
132
- await snippets.print();
133
- (0, _exit.exit)();
134
- }
135
- }
136
- checkImportCustomTest() {
137
- if (this.config.importTestFrom) return;
138
- const hasCustomTest = this.files.some(file => file.hasCustomTest);
139
- if (hasCustomTest) {
140
- (0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
141
- }
142
- }
143
- async saveFiles() {
144
- this.files.forEach(file => {
145
- file.save();
146
- this.logger.log(`Generated: ${_path.default.relative(process.cwd(), file.outputPath)}`);
147
- });
148
- this.logger.log(`Generated files: ${this.files.length}`);
149
- }
150
- async clearOutputDir() {
151
- const pattern = `${_fastGlob.default.convertPathToPattern(this.config.outputDir)}/**/*.spec.js`;
152
- const testFiles = await (0, _fastGlob.default)(pattern);
153
- this.logger.log(`Clearing output dir: ${testFiles.length} file(s)`);
154
- const tasks = testFiles.map(testFile => _promises.default.rm(testFile));
155
- await Promise.all(tasks);
156
- }
157
- warnForTsNodeRegister() {
158
- if ((0, _loadSteps.hasTsNodeRegister)(this.runConfiguration)) {
159
- this.logger.warn(`WARNING: usage of requireModule: ['ts-node/register'] is not recommended for playwright-bdd.`, `Remove this option from defineBddConfig() and`, `Playwright's built-in loader will be used to compile TypeScript step definitions.`);
160
- }
161
- }
162
- }
163
- exports.TestFilesGenerator = TestFilesGenerator;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.POMS = void 0;
7
- exports.buildFixtureTag = buildFixtureTag;
8
- var _createDecorators = require("../stepDefinitions/createDecorators");
9
- /**
10
- * Handle POMs graph for decorator steps.
11
- */
12
-
13
- const FIXTURE_TAG_PREFIX = '@fixture:';
14
- class POMS {
15
- usedPoms = new Map();
16
- add(pomNode) {
17
- if (pomNode) this.usedPoms.set(pomNode, null);
18
- }
19
- addByFixtureName(fixtureName) {
20
- const pomNode = (0, _createDecorators.getPomNodeByFixtureName)(fixtureName);
21
- if (pomNode) this.add(pomNode);
22
- }
23
- addByTag(tag) {
24
- const fixtureName = extractFixtureName(tag);
25
- if (fixtureName) this.addByFixtureName(fixtureName);
26
- }
27
- resolveFixtureNames(pomNode) {
28
- const resolvedFixtureNames = this.usedPoms.get(pomNode);
29
- if (resolvedFixtureNames) return resolvedFixtureNames;
30
- const fixtureNames = [...pomNode.children].map(child => this.resolveFixtureNames(child)).flat();
31
- if (this.usedPoms.has(pomNode)) {
32
- // if nothing returned from children, use own fixtureName,
33
- // otherwise use what returned from child
34
- if (!fixtureNames.length) fixtureNames.push(pomNode.fixtureName);
35
- this.usedPoms.set(pomNode, fixtureNames);
36
- }
37
- return fixtureNames;
38
- }
39
- }
40
- exports.POMS = POMS;
41
- function extractFixtureName(tag) {
42
- return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
43
- }
44
- function buildFixtureTag(fixtureName) {
45
- return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
46
- }