@zohodesk/testinglibrary 0.0.4 → 0.0.5-exp.2
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.
- package/.babelrc +6 -0
- package/bin/cli.js +1 -1
- package/bin/postinstall.js +1 -16
- package/build/bdd-framework/cli/commands/env.js +44 -0
- package/build/bdd-framework/cli/commands/export.js +95 -0
- package/build/bdd-framework/cli/commands/test.js +98 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +21 -0
- package/build/bdd-framework/cli/worker.js +27 -0
- package/build/bdd-framework/config/dir.js +27 -0
- package/build/bdd-framework/config/env.js +49 -0
- package/build/bdd-framework/config/index.js +91 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +44 -0
- package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
- package/build/bdd-framework/cucumber/loadConfig.js +32 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +55 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +33 -0
- package/build/bdd-framework/cucumber/loadSources.js +89 -0
- package/build/bdd-framework/cucumber/loadSteps.js +66 -0
- package/build/bdd-framework/decorators.js +21 -0
- package/build/bdd-framework/gen/formatter.js +124 -0
- package/build/bdd-framework/gen/i18n.js +46 -0
- package/build/bdd-framework/gen/index.js +322 -0
- package/build/bdd-framework/gen/poms.js +68 -0
- package/build/bdd-framework/gen/testFile.js +422 -0
- package/build/bdd-framework/gen/testNode.js +64 -0
- package/build/bdd-framework/index.js +33 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +109 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +51 -0
- package/build/bdd-framework/playwright/loadConfig.js +56 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +48 -0
- package/build/bdd-framework/playwright/transform.js +86 -0
- package/build/bdd-framework/playwright/utils.js +25 -0
- package/build/bdd-framework/run/bddFixtures.js +166 -0
- package/build/bdd-framework/run/bddWorld.js +166 -0
- package/build/bdd-framework/snippets/index.js +184 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +61 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +42 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +37 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +54 -0
- package/build/bdd-framework/stepDefinitions/createDecorators.js +123 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +64 -0
- package/build/bdd-framework/utils/index.js +59 -0
- package/build/bdd-framework/utils/jsStringWrap.js +45 -0
- package/build/bdd-framework/utils/logger.js +23 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
- package/{src → build}/core/jest/runner/jest-runner.js +18 -17
- package/build/core/jest/setup/index.js +9 -0
- package/build/core/playwright/codegen.js +56 -0
- package/build/core/playwright/custom-commands.js +8 -0
- package/build/core/playwright/env-initializer.js +22 -0
- package/build/core/playwright/index.js +117 -0
- package/build/core/playwright/readConfigFile.js +61 -0
- package/build/core/playwright/report-generator.js +43 -0
- package/build/core/playwright/setup/config-creator.js +107 -0
- package/build/core/playwright/test-runner.js +102 -0
- package/build/index.js +37 -0
- package/build/lib/cli.js +47 -0
- package/build/lib/post-install.js +17 -0
- package/build/lint/index.js +6 -0
- package/build/setup-folder-structure/env-config-sample.json +17 -0
- package/build/setup-folder-structure/setupProject.js +102 -0
- package/build/setup-folder-structure/uat-config-sample.js +27 -0
- package/build/setup-folder-structure/user-example.json +3 -0
- package/build/utils/cliArgsToObject.js +64 -0
- package/build/utils/getFilePath.js +11 -0
- package/build/utils/logger.js +66 -0
- package/build/utils/rootPath.js +46 -0
- package/changelog.md +14 -0
- package/npm-shrinkwrap.json +2097 -147
- package/package.json +18 -4
- package/playwright.config.js +1 -1
- package/src/core/jest/preprocessor/jsPreprocessor.js +0 -9
- package/src/core/jest/setup/index.js +0 -165
- package/src/core/playwright/codegen.js +0 -60
- package/src/core/playwright/custom-commands.js +0 -3
- package/src/core/playwright/env-initializer.js +0 -24
- package/src/core/playwright/index.js +0 -82
- package/src/core/playwright/readConfigFile.js +0 -30
- package/src/core/playwright/report-generator.js +0 -43
- package/src/core/playwright/setup/config-creator.js +0 -77
- package/src/core/playwright/test-runner.js +0 -64
- package/src/index.js +0 -9
- package/src/lib/cli.js +0 -35
- package/src/utils/cliArgsToObject.js +0 -35
- package/src/utils/getFilePath.js +0 -9
- package/src/utils/logger.js +0 -28
- package/src/utils/rootPath.js +0 -51
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Snippets = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
var _defineStep = require("../stepDefinitions/defineStep");
|
|
16
|
+
var _logger = require("../utils/logger");
|
|
17
|
+
/**
|
|
18
|
+
* Generate and show snippets for undefined steps
|
|
19
|
+
*/
|
|
20
|
+
var Snippets = /*#__PURE__*/function (_printSnippetsAndExit, _createSnippetBuilder) {
|
|
21
|
+
function Snippets(files, runConfiguration, supportCodeLibrary) {
|
|
22
|
+
(0, _classCallCheck2["default"])(this, Snippets);
|
|
23
|
+
(0, _defineProperty2["default"])(this, "snippetBuilder", void 0);
|
|
24
|
+
(0, _defineProperty2["default"])(this, "bddBuiltInSyntax", false);
|
|
25
|
+
this.files = files;
|
|
26
|
+
this.runConfiguration = runConfiguration;
|
|
27
|
+
this.supportCodeLibrary = supportCodeLibrary;
|
|
28
|
+
}
|
|
29
|
+
(0, _createClass2["default"])(Snippets, [{
|
|
30
|
+
key: "printSnippetsAndExit",
|
|
31
|
+
value: function printSnippetsAndExit() {
|
|
32
|
+
return (_printSnippetsAndExit = _printSnippetsAndExit || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
33
|
+
var snippets;
|
|
34
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_context.next = 2;
|
|
38
|
+
return this.createSnippetBuilder();
|
|
39
|
+
case 2:
|
|
40
|
+
this.snippetBuilder = _context.sent;
|
|
41
|
+
snippets = this.getSnippets();
|
|
42
|
+
this.printHeader();
|
|
43
|
+
this.printSnippets(snippets);
|
|
44
|
+
this.printFooter(snippets);
|
|
45
|
+
case 7:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee, this);
|
|
50
|
+
}))).apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "createSnippetBuilder",
|
|
54
|
+
value: function createSnippetBuilder() {
|
|
55
|
+
return (_createSnippetBuilder = _createSnippetBuilder || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
56
|
+
var snippetInterface, snippetSyntax;
|
|
57
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
58
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
snippetInterface = this.runConfiguration.formats.options.snippetInterface;
|
|
61
|
+
snippetSyntax = this.getSnippetSyntax();
|
|
62
|
+
return _context2.abrupt("return", (0, _loadSnippetBuilder.loadSnippetBuilder)(this.supportCodeLibrary, snippetInterface, snippetSyntax));
|
|
63
|
+
case 3:
|
|
64
|
+
case "end":
|
|
65
|
+
return _context2.stop();
|
|
66
|
+
}
|
|
67
|
+
}, _callee2, this);
|
|
68
|
+
}))).apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "getSnippetSyntax",
|
|
72
|
+
value: function getSnippetSyntax() {
|
|
73
|
+
var snippetSyntax = this.runConfiguration.formats.options.snippetSyntax;
|
|
74
|
+
if (!snippetSyntax && this.isPlaywrightStyle()) {
|
|
75
|
+
this.bddBuiltInSyntax = true;
|
|
76
|
+
return this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
|
|
77
|
+
} else {
|
|
78
|
+
return snippetSyntax;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "getSnippets",
|
|
83
|
+
value: function getSnippets() {
|
|
84
|
+
var _this = this;
|
|
85
|
+
var snippetsSet = new Set();
|
|
86
|
+
var snippets = [];
|
|
87
|
+
this.files.forEach(function (file) {
|
|
88
|
+
file.undefinedSteps.forEach(function (undefinedStep) {
|
|
89
|
+
var _this$getSnippet = _this.getSnippet(file, snippets.length + 1, undefinedStep),
|
|
90
|
+
snippet = _this$getSnippet.snippet,
|
|
91
|
+
snippetWithLocation = _this$getSnippet.snippetWithLocation;
|
|
92
|
+
if (!snippetsSet.has(snippet)) {
|
|
93
|
+
snippetsSet.add(snippet);
|
|
94
|
+
snippets.push(snippetWithLocation);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return snippets;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "getSnippet",
|
|
102
|
+
value: function getSnippet(file, index, undefinedStep) {
|
|
103
|
+
var snippet = this.snippetBuilder.build({
|
|
104
|
+
keywordType: undefinedStep.keywordType,
|
|
105
|
+
pickleStep: undefinedStep.pickleStep
|
|
106
|
+
});
|
|
107
|
+
var _undefinedStep$step$l = undefinedStep.step.location,
|
|
108
|
+
line = _undefinedStep$step$l.line,
|
|
109
|
+
column = _undefinedStep$step$l.column;
|
|
110
|
+
var snippetWithLocation = ["// ".concat(index, ". Missing step definition for \"").concat(file.sourceFile, ":").concat(line, ":").concat(column, "\""), snippet].join('\n');
|
|
111
|
+
return {
|
|
112
|
+
snippet: snippet,
|
|
113
|
+
snippetWithLocation: snippetWithLocation
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "isTypeScript",
|
|
118
|
+
value: function isTypeScript() {
|
|
119
|
+
var _this$supportCodeLibr = this.supportCodeLibrary.originalCoordinates,
|
|
120
|
+
requirePaths = _this$supportCodeLibr.requirePaths,
|
|
121
|
+
importPaths = _this$supportCodeLibr.importPaths;
|
|
122
|
+
return requirePaths.some(function (p) {
|
|
123
|
+
return p.endsWith('.ts');
|
|
124
|
+
}) || importPaths.some(function (p) {
|
|
125
|
+
return p.endsWith('.ts');
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "isPlaywrightStyle",
|
|
130
|
+
value: function isPlaywrightStyle() {
|
|
131
|
+
var stepDefinitions = this.supportCodeLibrary.stepDefinitions;
|
|
132
|
+
return stepDefinitions.length > 0 ? stepDefinitions.some(function (step) {
|
|
133
|
+
return (0, _defineStep.isPlaywrightStyle)(step);
|
|
134
|
+
}) : true;
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "isDecorators",
|
|
138
|
+
value: function isDecorators() {
|
|
139
|
+
var stepDefinitions = this.supportCodeLibrary.stepDefinitions;
|
|
140
|
+
var decoratorSteps = stepDefinitions.filter(function (step) {
|
|
141
|
+
var _getStepConfig;
|
|
142
|
+
return (_getStepConfig = (0, _defineStep.getStepConfig)(step)) === null || _getStepConfig === void 0 ? void 0 : _getStepConfig.isDecorator;
|
|
143
|
+
});
|
|
144
|
+
return decoratorSteps.length > stepDefinitions.length / 2;
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "printHeader",
|
|
148
|
+
value: function printHeader() {
|
|
149
|
+
var lines = ["Missing steps found. Use snippets below:"];
|
|
150
|
+
if (this.bddBuiltInSyntax) {
|
|
151
|
+
if (this.isDecorators()) {
|
|
152
|
+
// TODO: For Decorators support
|
|
153
|
+
lines.push("import { Fixture, Given, When, Then } from 'playwright-bdd/decorators';\n");
|
|
154
|
+
} else {
|
|
155
|
+
lines.push("import { createBdd } from '@zohodesk/testinglibrary';", "const { Given, When, Then } = createBdd();\n");
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
lines.push("import { Given, When, Then } from '@cucumber/cucumber';\n");
|
|
159
|
+
}
|
|
160
|
+
_logger.logger.error(lines.join('\n\n'));
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "printSnippets",
|
|
164
|
+
value: function printSnippets(snippets) {
|
|
165
|
+
_logger.logger.error(snippets.concat(['']).join('\n\n'));
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "printFooter",
|
|
169
|
+
value: function printFooter(snippets) {
|
|
170
|
+
(0, _utils.exitWithMessage)("Missing step definitions (".concat(snippets.length, ")."), 'Use snippets above to create them.', this.getWarnOnZeroScannedFiles());
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "getWarnOnZeroScannedFiles",
|
|
174
|
+
value: function getWarnOnZeroScannedFiles() {
|
|
175
|
+
var _this$supportCodeLibr2 = this.supportCodeLibrary.originalCoordinates,
|
|
176
|
+
requirePaths = _this$supportCodeLibr2.requirePaths,
|
|
177
|
+
importPaths = _this$supportCodeLibr2.importPaths;
|
|
178
|
+
var scannedFilesCount = requirePaths.length + importPaths.length;
|
|
179
|
+
return scannedFilesCount === 0 && !this.isDecorators() ? "\nNote that 0 step definition files found, check the config." : '';
|
|
180
|
+
}
|
|
181
|
+
}]);
|
|
182
|
+
return Snippets;
|
|
183
|
+
}();
|
|
184
|
+
exports.Snippets = Snippets;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
/**
|
|
13
|
+
* Playwright-style snippet syntax.
|
|
14
|
+
*
|
|
15
|
+
* See: https://github.com/cucumber/cucumber-js/blob/main/docs/custom_snippet_syntaxes.md
|
|
16
|
+
*/
|
|
17
|
+
// todo: custom cucumber parameters
|
|
18
|
+
// See: https://github.com/cucumber/cucumber-expressions#custom-parameter-types
|
|
19
|
+
var _default = /*#__PURE__*/function () {
|
|
20
|
+
function _default() {
|
|
21
|
+
(0, _classCallCheck2["default"])(this, _default);
|
|
22
|
+
(0, _defineProperty2["default"])(this, "isTypescript", false);
|
|
23
|
+
}
|
|
24
|
+
(0, _createClass2["default"])(_default, [{
|
|
25
|
+
key: "build",
|
|
26
|
+
value: function build(_ref) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
var generatedExpressions = _ref.generatedExpressions,
|
|
29
|
+
functionName = _ref.functionName,
|
|
30
|
+
stepParameterNames = _ref.stepParameterNames;
|
|
31
|
+
// Always take only first generatedExpression
|
|
32
|
+
// Other expressions are for int/float combinations
|
|
33
|
+
var generatedExpression = generatedExpressions[0];
|
|
34
|
+
var expressionParameters = generatedExpression.parameterNames.map(function (name, i) {
|
|
35
|
+
var argName = "arg".concat(i === 0 ? '' : i);
|
|
36
|
+
var type = name.startsWith('string') ? 'string' : 'number';
|
|
37
|
+
return _this.isTypescript ? "".concat(argName, ": ").concat(type) : argName;
|
|
38
|
+
});
|
|
39
|
+
var stepParameters = stepParameterNames.map(function (argName) {
|
|
40
|
+
var type = argName === 'dataTable' ? 'DataTable' : 'string';
|
|
41
|
+
return _this.isTypescript ? "".concat(argName, ": ").concat(type) : argName;
|
|
42
|
+
});
|
|
43
|
+
var allParameterNames = ['{}'].concat((0, _toConsumableArray2["default"])(expressionParameters), (0, _toConsumableArray2["default"])(stepParameters));
|
|
44
|
+
var functionSignature = "".concat(functionName, "('").concat(this.escapeSpecialCharacters(generatedExpression), "', async (").concat(allParameterNames.join(', '), ") => {");
|
|
45
|
+
return [functionSignature, // prettier-ignore
|
|
46
|
+
" // ...", '});'].join('\n');
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "escapeSpecialCharacters",
|
|
50
|
+
value: function escapeSpecialCharacters(generatedExpression) {
|
|
51
|
+
var source = generatedExpression.source;
|
|
52
|
+
// double up any backslashes because we're in a javascript string
|
|
53
|
+
source = source.replace(/\\/g, '\\\\');
|
|
54
|
+
// escape any single quotes because that's our quote delimiter
|
|
55
|
+
source = source.replace(/'/g, "\\'");
|
|
56
|
+
return source;
|
|
57
|
+
}
|
|
58
|
+
}]);
|
|
59
|
+
return _default;
|
|
60
|
+
}();
|
|
61
|
+
exports["default"] = _default;
|
|
@@ -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["default"] = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
/**
|
|
11
|
+
* Playwright-style snippet syntax for decorators.
|
|
12
|
+
*
|
|
13
|
+
* See: https://github.com/cucumber/cucumber-js/blob/main/docs/custom_snippet_syntaxes.md
|
|
14
|
+
*/
|
|
15
|
+
var _default = /*#__PURE__*/function () {
|
|
16
|
+
function _default() {
|
|
17
|
+
(0, _classCallCheck2["default"])(this, _default);
|
|
18
|
+
}
|
|
19
|
+
(0, _createClass2["default"])(_default, [{
|
|
20
|
+
key: "build",
|
|
21
|
+
value: function build(_ref) {
|
|
22
|
+
var generatedExpressions = _ref.generatedExpressions,
|
|
23
|
+
functionName = _ref.functionName;
|
|
24
|
+
// Always take only first generatedExpression
|
|
25
|
+
// Other expressions are for int/float combinations
|
|
26
|
+
var generatedExpression = generatedExpressions[0];
|
|
27
|
+
return "@".concat(functionName, "('").concat(this.escapeSpecialCharacters(generatedExpression), "')");
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "escapeSpecialCharacters",
|
|
31
|
+
value: function escapeSpecialCharacters(generatedExpression) {
|
|
32
|
+
var source = generatedExpression.source;
|
|
33
|
+
// double up any backslashes because we're in a javascript string
|
|
34
|
+
source = source.replace(/\\/g, '\\\\');
|
|
35
|
+
// escape any single quotes because that's our quote delimiter
|
|
36
|
+
source = source.replace(/'/g, "\\'");
|
|
37
|
+
return source;
|
|
38
|
+
}
|
|
39
|
+
}]);
|
|
40
|
+
return _default;
|
|
41
|
+
}();
|
|
42
|
+
exports["default"] = _default;
|
|
@@ -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["default"] = void 0;
|
|
8
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _snippetSyntax = _interopRequireDefault(require("./snippetSyntax"));
|
|
16
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
17
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /**
|
|
18
|
+
* Playwright-style snippet syntax for typescript.
|
|
19
|
+
* Important to use separate file as it's simplest way to distinguish between js/ts
|
|
20
|
+
* without hooking into cucumber machinery.
|
|
21
|
+
*/
|
|
22
|
+
var _default = /*#__PURE__*/function (_SnippetSyntax) {
|
|
23
|
+
(0, _inherits2["default"])(_default, _SnippetSyntax);
|
|
24
|
+
var _super = _createSuper(_default);
|
|
25
|
+
function _default() {
|
|
26
|
+
var _this;
|
|
27
|
+
(0, _classCallCheck2["default"])(this, _default);
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
args[_key] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
32
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "isTypescript", true);
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
return (0, _createClass2["default"])(_default);
|
|
36
|
+
}(_snippetSyntax["default"]);
|
|
37
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBdd = createBdd;
|
|
7
|
+
exports.extractFixtureNames = extractFixtureNames;
|
|
8
|
+
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
+
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
12
|
+
var _defineStep = require("./defineStep");
|
|
13
|
+
/**
|
|
14
|
+
* Stuff related to writing steps in Playwright-style.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
|
|
18
|
+
|
|
19
|
+
function createBdd(customTest) {
|
|
20
|
+
var hasCustomTest = isCustomTest(customTest);
|
|
21
|
+
var Given = defineStepCtor('Given', hasCustomTest);
|
|
22
|
+
var When = defineStepCtor('When', hasCustomTest);
|
|
23
|
+
var Then = defineStepCtor('Then', hasCustomTest);
|
|
24
|
+
var Step = defineStepCtor('Unknown', hasCustomTest);
|
|
25
|
+
return {
|
|
26
|
+
Given: Given,
|
|
27
|
+
When: When,
|
|
28
|
+
Then: Then,
|
|
29
|
+
Step: Step
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function defineStepCtor(keyword, hasCustomTest) {
|
|
33
|
+
return function (pattern, fn) {
|
|
34
|
+
(0, _defineStep.defineStep)({
|
|
35
|
+
keyword: keyword,
|
|
36
|
+
pattern: pattern,
|
|
37
|
+
fn: fn,
|
|
38
|
+
hasCustomTest: hasCustomTest,
|
|
39
|
+
isDecorator: false
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function extractFixtureNames(fn) {
|
|
44
|
+
return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(function (name) {
|
|
45
|
+
return !(0, _bddFixtures.isBddAutoInjectFixture)(name);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function isCustomTest(customTest) {
|
|
49
|
+
var isCustomTest = Boolean(customTest && customTest !== _bddFixtures.test);
|
|
50
|
+
if (isCustomTest && customTest && !(0, _testTypeImpl.isParentChildTest)(_bddFixtures.test, customTest)) {
|
|
51
|
+
(0, _utils.exitWithMessage)("createBdd() should use test extended from \"playwright-bdd\"");
|
|
52
|
+
}
|
|
53
|
+
return isCustomTest;
|
|
54
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Fixture = Fixture;
|
|
7
|
+
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
8
|
+
exports.createStepDecorator = createStepDecorator;
|
|
9
|
+
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
10
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
+
var _defineStep = require("./defineStep");
|
|
12
|
+
var _buildStepDefinition = require("../cucumber/buildStepDefinition");
|
|
13
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**
|
|
16
|
+
* Define steps via decorators.
|
|
17
|
+
*/ /* eslint-disable @typescript-eslint/ban-types */
|
|
18
|
+
var pomGraph = new Map();
|
|
19
|
+
var decoratedStepSymbol = Symbol('decoratedStep');
|
|
20
|
+
var decoratedSteps = new Set();
|
|
21
|
+
function Fixture(fixtureName) {
|
|
22
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
23
|
+
return function (Ctor, _context) {
|
|
24
|
+
createPomNode(Ctor, fixtureName);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createStepDecorator(keyword) {
|
|
28
|
+
return function (pattern) {
|
|
29
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
30
|
+
return function (method, _context) {
|
|
31
|
+
method[decoratedStepSymbol] = {
|
|
32
|
+
keyword: keyword,
|
|
33
|
+
pattern: pattern,
|
|
34
|
+
fn: method,
|
|
35
|
+
hasCustomTest: true,
|
|
36
|
+
isDecorator: true
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function appendDecoratorSteps(supportCodeLibrary) {
|
|
42
|
+
decoratedSteps.forEach(function (stepConfig) {
|
|
43
|
+
var keyword = stepConfig.keyword,
|
|
44
|
+
pattern = stepConfig.pattern,
|
|
45
|
+
fn = stepConfig.fn;
|
|
46
|
+
stepConfig.fn = function (fixturesArg) {
|
|
47
|
+
var fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
49
|
+
args[_key - 1] = arguments[_key];
|
|
50
|
+
}
|
|
51
|
+
return fn.call.apply(fn, [fixture].concat(args));
|
|
52
|
+
};
|
|
53
|
+
var code = (0, _defineStep.buildCucumberStepFn)(stepConfig);
|
|
54
|
+
var stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
55
|
+
keyword: keyword,
|
|
56
|
+
pattern: pattern,
|
|
57
|
+
code: code,
|
|
58
|
+
line: 0,
|
|
59
|
+
// not used in playwright-bdd
|
|
60
|
+
options: {},
|
|
61
|
+
// not used in playwright-bdd
|
|
62
|
+
uri: '' // not used in playwright-bdd
|
|
63
|
+
}, supportCodeLibrary);
|
|
64
|
+
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
65
|
+
});
|
|
66
|
+
decoratedSteps.clear();
|
|
67
|
+
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getPomNodeByFixtureName(fixtureName) {
|
|
71
|
+
var _iterator = _createForOfIteratorHelper(pomGraph.values()),
|
|
72
|
+
_step;
|
|
73
|
+
try {
|
|
74
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
75
|
+
var pomNode = _step.value;
|
|
76
|
+
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
_iterator.e(err);
|
|
80
|
+
} finally {
|
|
81
|
+
_iterator.f();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function createPomNode(Ctor, fixtureName) {
|
|
85
|
+
var pomNode = {
|
|
86
|
+
fixtureName: fixtureName,
|
|
87
|
+
children: new Set()
|
|
88
|
+
};
|
|
89
|
+
pomGraph.set(Ctor, pomNode);
|
|
90
|
+
getDecoratedSteps(Ctor).forEach(function (stepConfig) {
|
|
91
|
+
stepConfig.pomNode = pomNode;
|
|
92
|
+
decoratedSteps.add(stepConfig);
|
|
93
|
+
});
|
|
94
|
+
var parentCtor = Object.getPrototypeOf(Ctor);
|
|
95
|
+
if (!parentCtor) return;
|
|
96
|
+
var parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
97
|
+
parentPomNode === null || parentPomNode === void 0 || parentPomNode.children.add(pomNode);
|
|
98
|
+
return pomNode;
|
|
99
|
+
}
|
|
100
|
+
function getDecoratedSteps(Ctor) {
|
|
101
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return [];
|
|
102
|
+
var propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
103
|
+
return Object.keys(propertyDescriptors)
|
|
104
|
+
// filter out getters / setters
|
|
105
|
+
.filter(function (methodName) {
|
|
106
|
+
return typeof propertyDescriptors[methodName].value === 'function';
|
|
107
|
+
}).map(function (methodName) {
|
|
108
|
+
return propertyDescriptors[methodName].value[decoratedStepSymbol];
|
|
109
|
+
}).filter(Boolean);
|
|
110
|
+
}
|
|
111
|
+
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
112
|
+
// there should be exatcly one suitable fixture in fixturesArg
|
|
113
|
+
var fixtureNames = Object.keys(fixturesArg).filter(function (fixtureName) {
|
|
114
|
+
return !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName);
|
|
115
|
+
});
|
|
116
|
+
if (fixtureNames.length === 0) {
|
|
117
|
+
throw new Error("No suitable fixtures found for decorator step \"".concat(stepConfig.pattern, "\""));
|
|
118
|
+
}
|
|
119
|
+
if (fixtureNames.length > 1) {
|
|
120
|
+
throw new Error("Several suitable fixtures found for decorator step \"".concat(stepConfig.pattern, "\""));
|
|
121
|
+
}
|
|
122
|
+
return fixturesArg[fixtureNames[0]];
|
|
123
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildCucumberStepFn = buildCucumberStepFn;
|
|
7
|
+
exports.defineStep = defineStep;
|
|
8
|
+
exports.getStepConfig = getStepConfig;
|
|
9
|
+
exports.isPlaywrightStyle = isPlaywrightStyle;
|
|
10
|
+
var _cucumber = require("@cucumber/cucumber");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
function defineStep(stepConfig) {
|
|
13
|
+
var keyword = stepConfig.keyword,
|
|
14
|
+
pattern = stepConfig.pattern;
|
|
15
|
+
var cucumberDefineStepFn = getCucumberDefineStepFn(keyword);
|
|
16
|
+
var code = buildCucumberStepFn(stepConfig);
|
|
17
|
+
try {
|
|
18
|
+
cucumberDefineStepFn(pattern, code);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
// todo: detect that this is import from test file
|
|
21
|
+
// and skip/delay registering cucumber steps until cucumber is loaded
|
|
22
|
+
var isMissingCucumber = /Cucumber that isn't running/i.test(e.message);
|
|
23
|
+
if (isMissingCucumber) {
|
|
24
|
+
(0, _utils.exitWithMessage)("Option \"importTestFrom\" should point to separate file without step definitions", "(e.g. without calls of Given, When, Then)");
|
|
25
|
+
} else {
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function buildCucumberStepFn(stepConfig) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
var code = function code() {
|
|
33
|
+
var _stepConfig$fn;
|
|
34
|
+
var fixturesArg = Object.assign({}, this.customFixtures, {
|
|
35
|
+
$testInfo: this.testInfo,
|
|
36
|
+
$test: this.test,
|
|
37
|
+
$tags: this.tags
|
|
38
|
+
});
|
|
39
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
+
args[_key] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
return (_stepConfig$fn = stepConfig.fn).call.apply(_stepConfig$fn, [this, fixturesArg].concat(args));
|
|
43
|
+
};
|
|
44
|
+
code.stepConfig = stepConfig;
|
|
45
|
+
return code;
|
|
46
|
+
}
|
|
47
|
+
function getStepConfig(step) {
|
|
48
|
+
return step.code.stepConfig;
|
|
49
|
+
}
|
|
50
|
+
function isPlaywrightStyle(step) {
|
|
51
|
+
return Boolean(getStepConfig(step));
|
|
52
|
+
}
|
|
53
|
+
function getCucumberDefineStepFn(keyword) {
|
|
54
|
+
switch (keyword) {
|
|
55
|
+
case 'Given':
|
|
56
|
+
return _cucumber.Given;
|
|
57
|
+
case 'When':
|
|
58
|
+
return _cucumber.When;
|
|
59
|
+
case 'Then':
|
|
60
|
+
return _cucumber.Then;
|
|
61
|
+
default:
|
|
62
|
+
return _cucumber.defineStep;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.exitWithMessage = exitWithMessage;
|
|
8
|
+
exports.getPackageVersion = getPackageVersion;
|
|
9
|
+
exports.getSymbolByName = getSymbolByName;
|
|
10
|
+
exports.removeDuplicates = removeDuplicates;
|
|
11
|
+
exports.resolvePackageRoot = resolvePackageRoot;
|
|
12
|
+
exports.template = template;
|
|
13
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
15
|
+
var _path = _interopRequireDefault(require("path"));
|
|
16
|
+
var _logger = require("./logger");
|
|
17
|
+
function exitWithMessage() {
|
|
18
|
+
for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
19
|
+
messages[_key] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
_logger.logger.error.apply(_logger.logger, ['ERROR:'].concat(messages));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
26
|
+
function getSymbolByName(target, name) {
|
|
27
|
+
var ownKeys = Reflect.ownKeys(target);
|
|
28
|
+
var symbol = ownKeys.find(function (key) {
|
|
29
|
+
return key.toString() === "Symbol(".concat(name, ")");
|
|
30
|
+
});
|
|
31
|
+
if (!symbol) {
|
|
32
|
+
throw new Error("Symbol \"".concat(name, "\" not found in target. ownKeys: ").concat(ownKeys));
|
|
33
|
+
}
|
|
34
|
+
return symbol;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Inserts params into template.
|
|
39
|
+
* Params defined as <param>.
|
|
40
|
+
*/
|
|
41
|
+
function template(t) {
|
|
42
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
43
|
+
return t.replace(/<(.+?)>/g, function (match, key) {
|
|
44
|
+
return params[key] !== undefined ? String(params[key]) : match;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function removeDuplicates(arr) {
|
|
48
|
+
return (0, _toConsumableArray2["default"])(new Set(arr));
|
|
49
|
+
}
|
|
50
|
+
function resolvePackageRoot(packageName) {
|
|
51
|
+
var packageJsonPath = require.resolve("".concat(packageName, "/package.json"));
|
|
52
|
+
return _path["default"].dirname(packageJsonPath);
|
|
53
|
+
}
|
|
54
|
+
function getPackageVersion(packageName) {
|
|
55
|
+
var packageRoot = resolvePackageRoot(packageName);
|
|
56
|
+
var packageJsonPath = _path["default"].join(packageRoot, 'package.json');
|
|
57
|
+
var packageJson = JSON.parse(_fs["default"].readFileSync(packageJsonPath, 'utf8'));
|
|
58
|
+
return packageJson.version || '';
|
|
59
|
+
}
|