@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
package/.babelrc
ADDED
package/bin/cli.js
CHANGED
package/bin/postinstall.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const { spawn } = require('child_process');
|
|
3
|
-
const { Logger } = require('../src/utils/logger');
|
|
4
|
-
const getFilePathWithExtension = require('../src/utils/getFilePath');
|
|
5
|
-
|
|
6
|
-
const playwrightPath = path.resolve('node_modules', '.bin', getFilePathWithExtension('playwright'));
|
|
7
|
-
const command = playwrightPath;
|
|
8
|
-
const args = ['install'];
|
|
9
|
-
|
|
10
|
-
Logger.log(Logger.INFO_TYPE, 'Downloading browsers for running tests');
|
|
11
|
-
|
|
12
|
-
const childProcess = spawn(command, args, { stdio: 'inherit' });
|
|
13
|
-
|
|
14
|
-
childProcess.on('error', (error) => {
|
|
15
|
-
Logger.log(Logger.FAILURE_TYPE, error);
|
|
16
|
-
});
|
|
1
|
+
require('../build/lib/post-install');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.envCommand = void 0;
|
|
8
|
+
exports.getOwnVersion = getOwnVersion;
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _commander = require("commander");
|
|
11
|
+
var _options = require("../options");
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _logger = require("../../utils/logger");
|
|
14
|
+
var _utils = require("../../utils");
|
|
15
|
+
var _loadConfig = require("../../playwright/loadConfig");
|
|
16
|
+
var envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(function (opts) {
|
|
17
|
+
_logger.logger.log("Playwright-bdd environment info:\n");
|
|
18
|
+
_logger.logger.log("platform: ".concat(process.platform));
|
|
19
|
+
_logger.logger.log("node: ".concat(process.version));
|
|
20
|
+
showPackageVersion('playwright-bdd');
|
|
21
|
+
showPackageVersion('@playwright/test');
|
|
22
|
+
showPackageVersion('@cucumber/cucumber');
|
|
23
|
+
showPlaywrightConfigPath(opts.config);
|
|
24
|
+
});
|
|
25
|
+
exports.envCommand = envCommand;
|
|
26
|
+
function showPackageVersion(packageName) {
|
|
27
|
+
var version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
28
|
+
_logger.logger.log("".concat(packageName, ": v").concat(version));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Getting own version by relative path instead of using getPackageVersion(),
|
|
33
|
+
* to aneble using directly from /dist in tests.
|
|
34
|
+
*/
|
|
35
|
+
function getOwnVersion() {
|
|
36
|
+
// const packageJsonPath = path.resolve(__dirname, '..', '..', '..', `package.json`);
|
|
37
|
+
// const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
38
|
+
return '5.2.0';
|
|
39
|
+
}
|
|
40
|
+
function showPlaywrightConfigPath(cliConfigPath) {
|
|
41
|
+
var resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
42
|
+
var relPath = _path["default"].relative(process.cwd(), resolvedConfigFile);
|
|
43
|
+
_logger.logger.log("Playwright config file: ".concat(relPath));
|
|
44
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.exportCommand = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _commander = require("commander");
|
|
12
|
+
var _options = require("../options");
|
|
13
|
+
var _loadConfig = require("../../playwright/loadConfig");
|
|
14
|
+
var _logger = require("../../utils/logger");
|
|
15
|
+
var _env = require("../../config/env");
|
|
16
|
+
var _test = require("./test");
|
|
17
|
+
var _gen = require("../../gen");
|
|
18
|
+
var _ref, _showStepsForConfigs;
|
|
19
|
+
// filter by project?
|
|
20
|
+
|
|
21
|
+
var exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(function (_x) {
|
|
22
|
+
return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(opts) {
|
|
23
|
+
var _yield$loadPlaywright, resolvedConfigFile, configs;
|
|
24
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
_context.next = 2;
|
|
28
|
+
return (0, _loadConfig.loadConfig)(opts.config);
|
|
29
|
+
case 2:
|
|
30
|
+
_yield$loadPlaywright = _context.sent;
|
|
31
|
+
resolvedConfigFile = _yield$loadPlaywright.resolvedConfigFile;
|
|
32
|
+
_logger.logger.log("List of all steps found by config: ".concat(_path["default"].relative(process.cwd(), resolvedConfigFile), "\n"));
|
|
33
|
+
configs = Object.values((0, _env.getEnvConfigs)());
|
|
34
|
+
(0, _test.assertConfigsCount)(configs);
|
|
35
|
+
_context.next = 9;
|
|
36
|
+
return showStepsForConfigs(configs);
|
|
37
|
+
case 9:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee);
|
|
42
|
+
}))).apply(this, arguments);
|
|
43
|
+
});
|
|
44
|
+
exports.exportCommand = exportCommand;
|
|
45
|
+
function showStepsForConfigs(_x2) {
|
|
46
|
+
return (_showStepsForConfigs = _showStepsForConfigs || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(configs) {
|
|
47
|
+
var _ref2;
|
|
48
|
+
var steps, tasks;
|
|
49
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
50
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
// here we don't need workers (as in test command) because if some step files
|
|
53
|
+
// are already in node cache, we collected them.
|
|
54
|
+
steps = new Set();
|
|
55
|
+
tasks = configs.map(function (_x3) {
|
|
56
|
+
return (_ref2 = _ref2 || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(config) {
|
|
57
|
+
var stepDefinitions;
|
|
58
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
59
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
_context2.next = 2;
|
|
62
|
+
return new _gen.TestFilesGenerator(config).extractSteps();
|
|
63
|
+
case 2:
|
|
64
|
+
stepDefinitions = _context2.sent;
|
|
65
|
+
stepDefinitions.forEach(function (s) {
|
|
66
|
+
return steps.add("* ".concat(getStepText(s)));
|
|
67
|
+
});
|
|
68
|
+
case 4:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context2.stop();
|
|
71
|
+
}
|
|
72
|
+
}, _callee2);
|
|
73
|
+
}))).apply(this, arguments);
|
|
74
|
+
});
|
|
75
|
+
_context3.next = 4;
|
|
76
|
+
return Promise.all(tasks);
|
|
77
|
+
case 4:
|
|
78
|
+
steps.forEach(function (stepText) {
|
|
79
|
+
return _logger.logger.log(stepText);
|
|
80
|
+
});
|
|
81
|
+
case 5:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context3.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee3);
|
|
86
|
+
}))).apply(this, arguments);
|
|
87
|
+
}
|
|
88
|
+
function getStepText(_ref3) {
|
|
89
|
+
var pattern = _ref3.pattern,
|
|
90
|
+
keyword = _ref3.keyword;
|
|
91
|
+
// for Unknown return When as it looks the most suitable
|
|
92
|
+
var keywordText = keyword === 'Unknown' ? 'When' : keyword;
|
|
93
|
+
var patternText = typeof pattern === 'string' ? pattern : pattern.source;
|
|
94
|
+
return "".concat(keywordText, " ").concat(patternText);
|
|
95
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.assertConfigsCount = assertConfigsCount;
|
|
8
|
+
exports.testCommand = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var _worker_threads = require("worker_threads");
|
|
13
|
+
var _events = require("events");
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
15
|
+
var _commander = require("commander");
|
|
16
|
+
var _gen = require("../../gen");
|
|
17
|
+
var _utils = require("../../utils");
|
|
18
|
+
var _loadConfig = require("../../playwright/loadConfig");
|
|
19
|
+
var _env = require("../../config/env");
|
|
20
|
+
var _config = require("../../config");
|
|
21
|
+
var _options = require("../options");
|
|
22
|
+
var _ref, _runInWorker, _generateFilesForConfigs;
|
|
23
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
25
|
+
var GEN_WORKER_PATH = _path["default"].resolve(__dirname, '..', 'worker.js');
|
|
26
|
+
var testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', "Tags expression to filter scenarios for generation").option('--verbose', "Verbose mode (default: ".concat(Boolean(_config.defaults.verbose), ")")).action(function (_x) {
|
|
27
|
+
return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(opts) {
|
|
28
|
+
var configs, cliOptions;
|
|
29
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.next = 2;
|
|
33
|
+
return (0, _loadConfig.loadConfig)(opts.config);
|
|
34
|
+
case 2:
|
|
35
|
+
configs = Object.values((0, _env.getEnvConfigs)());
|
|
36
|
+
assertConfigsCount(configs);
|
|
37
|
+
cliOptions = buildCliOptions(opts);
|
|
38
|
+
_context.next = 7;
|
|
39
|
+
return generateFilesForConfigs(configs, cliOptions);
|
|
40
|
+
case 7:
|
|
41
|
+
case "end":
|
|
42
|
+
return _context.stop();
|
|
43
|
+
}
|
|
44
|
+
}, _callee);
|
|
45
|
+
}))).apply(this, arguments);
|
|
46
|
+
});
|
|
47
|
+
exports.testCommand = testCommand;
|
|
48
|
+
function buildCliOptions(opts) {
|
|
49
|
+
var config = {};
|
|
50
|
+
if ('tags' in opts) config.tags = opts.tags;
|
|
51
|
+
if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
|
|
52
|
+
return config;
|
|
53
|
+
}
|
|
54
|
+
function assertConfigsCount(configs) {
|
|
55
|
+
if (configs.length === 0) {
|
|
56
|
+
(0, _utils.exitWithMessage)("No BDD configs found. Did you use defineBddConfig() in playwright.config.ts?");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function runInWorker(_x2) {
|
|
60
|
+
return (_runInWorker = _runInWorker || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(config) {
|
|
61
|
+
var worker;
|
|
62
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
63
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
worker = new _worker_threads.Worker(GEN_WORKER_PATH, {
|
|
66
|
+
workerData: {
|
|
67
|
+
config: config
|
|
68
|
+
}
|
|
69
|
+
}); // todo: check if worker exited with error?
|
|
70
|
+
_context2.next = 3;
|
|
71
|
+
return (0, _events.once)(worker, 'exit');
|
|
72
|
+
case 3:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context2.stop();
|
|
75
|
+
}
|
|
76
|
+
}, _callee2);
|
|
77
|
+
}))).apply(this, arguments);
|
|
78
|
+
}
|
|
79
|
+
function generateFilesForConfigs(_x3, _x4) {
|
|
80
|
+
return (_generateFilesForConfigs = _generateFilesForConfigs || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(configs, cliConfig) {
|
|
81
|
+
var tasks;
|
|
82
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
83
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
84
|
+
case 0:
|
|
85
|
+
// run first config in main thread and other in workers (to have fresh require cache)
|
|
86
|
+
// See: https://github.com/vitalets/playwright-bdd/issues/32
|
|
87
|
+
tasks = configs.map(function (config, index) {
|
|
88
|
+
var finalConfig = _objectSpread(_objectSpread({}, config), cliConfig);
|
|
89
|
+
return index === 0 ? new _gen.TestFilesGenerator(finalConfig).generate() : runInWorker(finalConfig);
|
|
90
|
+
});
|
|
91
|
+
return _context3.abrupt("return", Promise.all(tasks));
|
|
92
|
+
case 2:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context3.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee3);
|
|
97
|
+
}))).apply(this, arguments);
|
|
98
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _test = require("./commands/test");
|
|
6
|
+
var _env = require("./commands/env");
|
|
7
|
+
var _export = require("./commands/export");
|
|
8
|
+
var program = new _commander.Command();
|
|
9
|
+
program.name('bddgen').description("Playwright-bdd CLI v".concat((0, _env.getOwnVersion)())).addCommand(_test.testCommand, {
|
|
10
|
+
isDefault: true
|
|
11
|
+
}).addCommand(_export.exportCommand).addCommand(_env.envCommand).addHelpCommand(false).parse();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.configOption = void 0;
|
|
7
|
+
exports.getCliConfigPath = getCliConfigPath;
|
|
8
|
+
var _commander = require("commander");
|
|
9
|
+
/**
|
|
10
|
+
* Config option moved to separate file as it used in test run.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
var configOption = new _commander.Option("-c, --config <file>", "Path to Playwright configuration file (default: playwright.config.(js|ts))");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Helper used in test run to detect config location.
|
|
17
|
+
*/
|
|
18
|
+
exports.configOption = configOption;
|
|
19
|
+
function getCliConfigPath() {
|
|
20
|
+
return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
|
+
var _worker_threads = require("worker_threads");
|
|
7
|
+
var _gen = require("../gen");
|
|
8
|
+
var _main;
|
|
9
|
+
/**
|
|
10
|
+
* Worker to generate test files with fresh require/import cache
|
|
11
|
+
* See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
|
|
12
|
+
*/
|
|
13
|
+
function main() {
|
|
14
|
+
return (_main = _main || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
15
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
_context.next = 2;
|
|
19
|
+
return new _gen.TestFilesGenerator(_worker_threads.workerData.config).generate();
|
|
20
|
+
case 2:
|
|
21
|
+
case "end":
|
|
22
|
+
return _context.stop();
|
|
23
|
+
}
|
|
24
|
+
}, _callee);
|
|
25
|
+
}))).apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
main();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getPlaywrightConfigDir = getPlaywrightConfigDir;
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _loadConfig = require("../playwright/loadConfig");
|
|
10
|
+
var _options = require("../cli/options");
|
|
11
|
+
/**
|
|
12
|
+
* Store playwright config dir in env to provide access to it in workers.
|
|
13
|
+
* Important that in workers there is different process.argv, that's why we save it to env.
|
|
14
|
+
* Config dir is needed to resolve all paths.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolve playwright config dir considering cli flags.
|
|
19
|
+
*/
|
|
20
|
+
function getPlaywrightConfigDir() {
|
|
21
|
+
if (!process.env.PLAYWRIGHT_BDD_CONFIG_DIR) {
|
|
22
|
+
var cliConfigPath = (0, _options.getCliConfigPath)();
|
|
23
|
+
var playwrightConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
24
|
+
process.env.PLAYWRIGHT_BDD_CONFIG_DIR = playwrightConfigFile ? _path["default"].dirname(playwrightConfigFile) : process.cwd();
|
|
25
|
+
}
|
|
26
|
+
return process.env.PLAYWRIGHT_BDD_CONFIG_DIR;
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getConfigFromEnv = getConfigFromEnv;
|
|
8
|
+
exports.getEnvConfigs = getEnvConfigs;
|
|
9
|
+
exports.saveConfigToEnv = saveConfigToEnv;
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
/**
|
|
13
|
+
* Storing configs in env var PLAYWRIGHT_BDD_CONFIGS as JSON-stringified values.
|
|
14
|
+
* For passing configs to playwright workers and bddgen.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function saveConfigToEnv(config) {
|
|
18
|
+
var envConfigs = getEnvConfigs();
|
|
19
|
+
var existingConfig = envConfigs[config.outputDir];
|
|
20
|
+
if (existingConfig) {
|
|
21
|
+
// Playwright config can be evaluated several times.
|
|
22
|
+
// Throw error only if different calls of defineBddConfig() use the same outputDir.
|
|
23
|
+
// See: https://github.com/vitalets/playwright-bdd/issues/39#issuecomment-1653805368
|
|
24
|
+
if (!isSameConfigs(config, existingConfig)) {
|
|
25
|
+
(0, _utils.exitWithMessage)("When using several calls of defineBddConfig()", "please manually provide different \"outputDir\" option.");
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
envConfigs[config.outputDir] = config;
|
|
30
|
+
saveEnvConfigs(envConfigs);
|
|
31
|
+
}
|
|
32
|
+
function getConfigFromEnv(outputDir) {
|
|
33
|
+
var envConfigs = getEnvConfigs();
|
|
34
|
+
outputDir = _path["default"].resolve(outputDir);
|
|
35
|
+
var config = envConfigs[outputDir];
|
|
36
|
+
if (!config) {
|
|
37
|
+
(0, _utils.exitWithMessage)("Config not found for outputDir: \"".concat(outputDir, "\"."), "Available dirs: ".concat(Object.keys(envConfigs).join('\n')));
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
function getEnvConfigs() {
|
|
42
|
+
return JSON.parse(process.env.PLAYWRIGHT_BDD_CONFIGS || '{}');
|
|
43
|
+
}
|
|
44
|
+
function saveEnvConfigs(envConfigs) {
|
|
45
|
+
process.env.PLAYWRIGHT_BDD_CONFIGS = JSON.stringify(envConfigs);
|
|
46
|
+
}
|
|
47
|
+
function isSameConfigs(config1, config2) {
|
|
48
|
+
return JSON.stringify(config1) === JSON.stringify(config2);
|
|
49
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.defaults = void 0;
|
|
8
|
+
exports.defineBddConfig = defineBddConfig;
|
|
9
|
+
exports.extractCucumberConfig = extractCucumberConfig;
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _env = require("./env");
|
|
13
|
+
var _dir = require("./dir");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
|
17
|
+
* BDD Config.
|
|
18
|
+
*/
|
|
19
|
+
var defaults = {
|
|
20
|
+
outputDir: '.features-gen',
|
|
21
|
+
verbose: false,
|
|
22
|
+
examplesTitleFormat: 'Example #<_index_>',
|
|
23
|
+
publishQuiet: true,
|
|
24
|
+
quotes: 'double'
|
|
25
|
+
};
|
|
26
|
+
exports.defaults = defaults;
|
|
27
|
+
function defineBddConfig(inputConfig) {
|
|
28
|
+
var config = getConfig(inputConfig);
|
|
29
|
+
|
|
30
|
+
// In main process store config in env to be accessible by workers
|
|
31
|
+
if (!process.env.TEST_WORKER_INDEX) {
|
|
32
|
+
(0, _env.saveConfigToEnv)(config);
|
|
33
|
+
}
|
|
34
|
+
return config.outputDir;
|
|
35
|
+
}
|
|
36
|
+
function getConfig(inputConfig) {
|
|
37
|
+
var config = Object.assign({}, defaults, inputConfig);
|
|
38
|
+
var configDir = (0, _dir.getPlaywrightConfigDir)();
|
|
39
|
+
var featuresRoot = config.featuresRoot ? _path["default"].resolve(configDir, config.featuresRoot) : configDir;
|
|
40
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
41
|
+
// important to resolve outputDir as it is used as unique key for input configs
|
|
42
|
+
outputDir: _path["default"].resolve(configDir, config.outputDir),
|
|
43
|
+
importTestFrom: resolveImportTestFrom(configDir, config.importTestFrom),
|
|
44
|
+
featuresRoot: featuresRoot
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function extractCucumberConfig(config) {
|
|
48
|
+
// todo: find more strict way to omit own config fields
|
|
49
|
+
// see: https://bobbyhadz.com/blog/typescript-object-remove-property
|
|
50
|
+
var omitProps = {
|
|
51
|
+
outputDir: true,
|
|
52
|
+
importTestFrom: true,
|
|
53
|
+
verbose: true,
|
|
54
|
+
skip: true,
|
|
55
|
+
examplesTitleFormat: true,
|
|
56
|
+
quotes: true,
|
|
57
|
+
tags: true,
|
|
58
|
+
featuresRoot: true
|
|
59
|
+
};
|
|
60
|
+
var keys = Object.keys(omitProps);
|
|
61
|
+
var cucumberConfig = _objectSpread({}, config);
|
|
62
|
+
keys.forEach(function (key) {
|
|
63
|
+
return delete cucumberConfig[key];
|
|
64
|
+
});
|
|
65
|
+
stripPublishQuiet(cucumberConfig);
|
|
66
|
+
return cucumberConfig;
|
|
67
|
+
}
|
|
68
|
+
function resolveImportTestFrom(configDir, importTestFrom) {
|
|
69
|
+
if (importTestFrom) {
|
|
70
|
+
var _ref = typeof importTestFrom === 'string' ? {
|
|
71
|
+
file: importTestFrom
|
|
72
|
+
} : importTestFrom,
|
|
73
|
+
file = _ref.file,
|
|
74
|
+
varName = _ref.varName;
|
|
75
|
+
return {
|
|
76
|
+
file: _path["default"].resolve(configDir, file),
|
|
77
|
+
varName: varName
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function stripPublishQuiet(cucumberConfig) {
|
|
82
|
+
var cucumberVersion = (0, _utils.getPackageVersion)('@cucumber/cucumber');
|
|
83
|
+
// Playwright-bdd supports Cucumber from v9+
|
|
84
|
+
// publishQuiet was deprecated in Cucumber 9.4.0.
|
|
85
|
+
// See: https://github.com/cucumber/cucumber-js/pull/2311
|
|
86
|
+
// Remove publishQuite from Cucumber config to hide deprecation warning.
|
|
87
|
+
// See: https://github.com/vitalets/playwright-bdd/pull/47
|
|
88
|
+
if (!/^9\.[0123]\./.test(cucumberVersion)) {
|
|
89
|
+
delete cucumberConfig.publishQuiet;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.buildStepDefinition = buildStepDefinition;
|
|
8
|
+
var _messages = require("@cucumber/messages");
|
|
9
|
+
var _cucumberExpressions = require("@cucumber/cucumber-expressions");
|
|
10
|
+
var _step_definition = _interopRequireDefault(require("@cucumber/cucumber/lib/models/step_definition"));
|
|
11
|
+
/**
|
|
12
|
+
* Extracted from cucumber SupportCodeLibraryBuilder.
|
|
13
|
+
* See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var newId = _messages.IdGenerator.uuid();
|
|
17
|
+
function buildStepDefinition(_ref, supportCodeLibrary) {
|
|
18
|
+
var keyword = _ref.keyword,
|
|
19
|
+
pattern = _ref.pattern,
|
|
20
|
+
code = _ref.code,
|
|
21
|
+
line = _ref.line,
|
|
22
|
+
options = _ref.options,
|
|
23
|
+
uri = _ref.uri;
|
|
24
|
+
// todo: handle error.undefinedParameterTypeName as it's done in cucumber?
|
|
25
|
+
var expression = typeof pattern === 'string' ? new _cucumberExpressions.CucumberExpression(pattern, supportCodeLibrary.parameterTypeRegistry) : new _cucumberExpressions.RegularExpression(pattern, supportCodeLibrary.parameterTypeRegistry);
|
|
26
|
+
|
|
27
|
+
// skip wrapping code as it is not needed for decorator steps
|
|
28
|
+
// const wrappedCode = this.wrapCode({
|
|
29
|
+
// code,
|
|
30
|
+
// wrapperOptions: options.wrapperOptions,
|
|
31
|
+
// })
|
|
32
|
+
|
|
33
|
+
return new _step_definition["default"]({
|
|
34
|
+
code: code,
|
|
35
|
+
expression: expression,
|
|
36
|
+
id: newId(),
|
|
37
|
+
line: line,
|
|
38
|
+
options: options,
|
|
39
|
+
keyword: keyword,
|
|
40
|
+
pattern: pattern,
|
|
41
|
+
unwrappedCode: code,
|
|
42
|
+
uri: uri
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copied from @cucumber/cucumber/lib/api/gherkin.d.ts
|
|
3
|
+
* Fixes error:
|
|
4
|
+
* Return type of exported function has or is using name 'PickleWithDocument'
|
|
5
|
+
* from external module "../node_modules/@cucumber/cucumber/lib/api/gherkin"
|
|
6
|
+
* but cannot be named
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
Envelope,
|
|
10
|
+
GherkinDocument,
|
|
11
|
+
IdGenerator,
|
|
12
|
+
Location,
|
|
13
|
+
ParseError,
|
|
14
|
+
Pickle,
|
|
15
|
+
} from '@cucumber/messages';
|
|
16
|
+
import { ISourcesCoordinates } from '@cucumber/cucumber/lib/api/types';
|
|
17
|
+
import { ILogger } from '@cucumber/cucumber/lib/logger';
|
|
18
|
+
|
|
19
|
+
declare module '@cucumber/cucumber/lib/api/gherkin' {
|
|
20
|
+
export interface PickleWithDocument {
|
|
21
|
+
gherkinDocument: GherkinDocument;
|
|
22
|
+
location: Location;
|
|
23
|
+
pickle: Pickle;
|
|
24
|
+
}
|
|
25
|
+
export function getFilteredPicklesAndErrors({
|
|
26
|
+
newId,
|
|
27
|
+
cwd,
|
|
28
|
+
logger,
|
|
29
|
+
unexpandedFeaturePaths,
|
|
30
|
+
featurePaths,
|
|
31
|
+
coordinates,
|
|
32
|
+
onEnvelope,
|
|
33
|
+
}: {
|
|
34
|
+
newId: IdGenerator.NewId;
|
|
35
|
+
cwd: string;
|
|
36
|
+
logger: ILogger;
|
|
37
|
+
unexpandedFeaturePaths: string[];
|
|
38
|
+
featurePaths: string[];
|
|
39
|
+
coordinates: ISourcesCoordinates;
|
|
40
|
+
onEnvelope?: (envelope: Envelope) => void;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
filteredPickles: PickleWithDocument[];
|
|
43
|
+
parseErrors: ParseError[];
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _api = require("@cucumber/cucumber/api");
|
|
11
|
+
var _loadConfig;
|
|
12
|
+
var cache = new Map();
|
|
13
|
+
function loadConfig(_x, _x2) {
|
|
14
|
+
return (_loadConfig = _loadConfig || (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(options, environment) {
|
|
15
|
+
var cacheKey, config;
|
|
16
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
cacheKey = JSON.stringify(options);
|
|
20
|
+
config = cache.get(cacheKey);
|
|
21
|
+
if (!config) {
|
|
22
|
+
config = (0, _api.loadConfiguration)(options, environment);
|
|
23
|
+
cache.set(cacheKey, config);
|
|
24
|
+
}
|
|
25
|
+
return _context.abrupt("return", config);
|
|
26
|
+
case 4:
|
|
27
|
+
case "end":
|
|
28
|
+
return _context.stop();
|
|
29
|
+
}
|
|
30
|
+
}, _callee);
|
|
31
|
+
}))).apply(this, arguments);
|
|
32
|
+
}
|