@zohodesk/testinglibrary 0.0.5-exp.2 → 0.0.5-exp.4
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 +11 -1
- package/build/bdd-framework/cli/commands/env.js +9 -9
- package/build/bdd-framework/cli/commands/export.js +25 -73
- package/build/bdd-framework/cli/commands/test.js +29 -67
- package/build/bdd-framework/cli/index.js +2 -2
- package/build/bdd-framework/cli/options.js +1 -1
- package/build/bdd-framework/cli/worker.js +3 -17
- package/build/bdd-framework/config/dir.js +3 -3
- package/build/bdd-framework/config/env.js +7 -7
- package/build/bdd-framework/config/index.js +29 -28
- package/build/bdd-framework/cucumber/buildStepDefinition.js +18 -17
- package/build/bdd-framework/cucumber/loadConfig.js +9 -24
- package/build/bdd-framework/cucumber/loadFeatures.js +15 -31
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +8 -21
- package/build/bdd-framework/cucumber/loadSources.js +34 -65
- package/build/bdd-framework/cucumber/loadSteps.js +14 -39
- package/build/bdd-framework/decorators.js +5 -5
- package/build/bdd-framework/gen/formatter.js +74 -106
- package/build/bdd-framework/gen/i18n.js +7 -9
- package/build/bdd-framework/gen/index.js +117 -289
- package/build/bdd-framework/gen/poms.js +26 -47
- package/build/bdd-framework/gen/testFile.js +313 -379
- package/build/bdd-framework/gen/testNode.js +25 -39
- package/build/bdd-framework/index.js +4 -4
- package/build/bdd-framework/playwright/fixtureParameterNames.js +18 -24
- package/build/bdd-framework/playwright/getLocationInFile.js +12 -13
- package/build/bdd-framework/playwright/loadConfig.js +16 -30
- package/build/bdd-framework/playwright/testTypeImpl.js +9 -10
- package/build/bdd-framework/playwright/transform.js +39 -40
- package/build/bdd-framework/playwright/utils.js +4 -5
- package/build/bdd-framework/run/bddFixtures.js +79 -136
- package/build/bdd-framework/run/bddWorld.js +65 -140
- package/build/bdd-framework/snippets/index.js +109 -161
- package/build/bdd-framework/snippets/snippetSyntax.js +37 -48
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +21 -31
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +11 -30
- package/build/bdd-framework/stepDefinitions/createBdd.js +17 -19
- package/build/bdd-framework/stepDefinitions/createDecorators.js +40 -53
- package/build/bdd-framework/stepDefinitions/defineStep.js +11 -13
- package/build/bdd-framework/utils/index.js +13 -20
- package/build/bdd-framework/utils/jsStringWrap.js +10 -11
- package/build/bdd-framework/utils/logger.js +5 -7
- package/build/core/jest/preprocessor/jsPreprocessor.js +3 -3
- package/build/core/jest/runner/jest-runner.js +5 -5
- package/build/core/playwright/codegen.js +11 -11
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/env-initializer.js +4 -5
- package/build/core/playwright/index.js +44 -65
- package/build/core/playwright/readConfigFile.js +5 -5
- package/build/core/playwright/report-generator.js +15 -15
- package/build/core/playwright/setup/config-creator.js +39 -42
- package/build/core/playwright/test-runner.js +31 -34
- package/build/index.js +5 -5
- package/build/lib/cli.js +7 -9
- package/build/lib/post-install.js +5 -5
- package/build/lint/index.js +5 -4
- package/build/setup-folder-structure/setupProject.js +24 -22
- package/build/utils/cliArgsToObject.js +9 -9
- package/build/utils/getFilePath.js +3 -3
- package/build/utils/logger.js +16 -26
- package/build/utils/rootPath.js +8 -8
- package/package.json +2 -2
package/.babelrc
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"presets": [
|
|
2
|
+
"presets": [
|
|
3
|
+
[
|
|
4
|
+
"@babel/preset-env",
|
|
5
|
+
{
|
|
6
|
+
"targets": {
|
|
7
|
+
"node": "14"
|
|
8
|
+
},
|
|
9
|
+
"exclude": ["@babel/plugin-transform-destructuring"]
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
],
|
|
3
13
|
"plugins": [
|
|
4
14
|
["@babel/plugin-transform-runtime"]
|
|
5
15
|
]
|
|
@@ -13,10 +13,10 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
13
13
|
var _logger = require("../../utils/logger");
|
|
14
14
|
var _utils = require("../../utils");
|
|
15
15
|
var _loadConfig = require("../../playwright/loadConfig");
|
|
16
|
-
|
|
17
|
-
_logger.logger.log(
|
|
18
|
-
_logger.logger.log(
|
|
19
|
-
_logger.logger.log(
|
|
16
|
+
const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
17
|
+
_logger.logger.log(`Playwright-bdd environment info:\n`);
|
|
18
|
+
_logger.logger.log(`platform: ${process.platform}`);
|
|
19
|
+
_logger.logger.log(`node: ${process.version}`);
|
|
20
20
|
showPackageVersion('playwright-bdd');
|
|
21
21
|
showPackageVersion('@playwright/test');
|
|
22
22
|
showPackageVersion('@cucumber/cucumber');
|
|
@@ -24,8 +24,8 @@ var envCommand = new _commander.Command('env').description('Prints environment i
|
|
|
24
24
|
});
|
|
25
25
|
exports.envCommand = envCommand;
|
|
26
26
|
function showPackageVersion(packageName) {
|
|
27
|
-
|
|
28
|
-
_logger.logger.log(
|
|
27
|
+
const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
28
|
+
_logger.logger.log(`${packageName}: v${version}`);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -38,7 +38,7 @@ function getOwnVersion() {
|
|
|
38
38
|
return '5.2.0';
|
|
39
39
|
}
|
|
40
40
|
function showPlaywrightConfigPath(cliConfigPath) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_logger.logger.log(
|
|
41
|
+
const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
42
|
+
const relPath = _path.default.relative(process.cwd(), resolvedConfigFile);
|
|
43
|
+
_logger.logger.log(`Playwright config file: ${relPath}`);
|
|
44
44
|
}
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.exportCommand = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
9
|
var _commander = require("commander");
|
|
12
10
|
var _options = require("../options");
|
|
@@ -15,81 +13,35 @@ var _logger = require("../../utils/logger");
|
|
|
15
13
|
var _env = require("../../config/env");
|
|
16
14
|
var _test = require("./test");
|
|
17
15
|
var _gen = require("../../gen");
|
|
18
|
-
var _ref, _showStepsForConfigs;
|
|
19
16
|
// filter by project?
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
18
|
+
const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
19
|
+
const {
|
|
20
|
+
resolvedConfigFile
|
|
21
|
+
} = await (0, _loadConfig.loadConfig)(opts.config);
|
|
22
|
+
_logger.logger.log(`List of all steps found by config: ${_path.default.relative(process.cwd(), resolvedConfigFile)}\n`);
|
|
23
|
+
const configs = Object.values((0, _env.getEnvConfigs)());
|
|
24
|
+
(0, _test.assertConfigsCount)(configs);
|
|
25
|
+
await showStepsForConfigs(configs);
|
|
43
26
|
});
|
|
44
27
|
exports.exportCommand = exportCommand;
|
|
45
|
-
function showStepsForConfigs(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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);
|
|
28
|
+
async function showStepsForConfigs(configs) {
|
|
29
|
+
// here we don't need workers (as in test command) because if some step files
|
|
30
|
+
// are already in node cache, we collected them.
|
|
31
|
+
const steps = new Set();
|
|
32
|
+
const tasks = configs.map(async config => {
|
|
33
|
+
const stepDefinitions = await new _gen.TestFilesGenerator(config).extractSteps();
|
|
34
|
+
stepDefinitions.forEach(s => steps.add(`* ${getStepText(s)}`));
|
|
35
|
+
});
|
|
36
|
+
await Promise.all(tasks);
|
|
37
|
+
steps.forEach(stepText => _logger.logger.log(stepText));
|
|
87
38
|
}
|
|
88
|
-
function getStepText(
|
|
89
|
-
|
|
90
|
-
|
|
39
|
+
function getStepText({
|
|
40
|
+
pattern,
|
|
41
|
+
keyword
|
|
42
|
+
}) {
|
|
91
43
|
// for Unknown return When as it looks the most suitable
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
44
|
+
const keywordText = keyword === 'Unknown' ? 'When' : keyword;
|
|
45
|
+
const patternText = typeof pattern === 'string' ? pattern : pattern.source;
|
|
46
|
+
return `${keywordText} ${patternText}`;
|
|
95
47
|
}
|
|
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.assertConfigsCount = assertConfigsCount;
|
|
8
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
9
|
var _worker_threads = require("worker_threads");
|
|
13
10
|
var _events = require("events");
|
|
14
11
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -19,80 +16,45 @@ var _loadConfig = require("../../playwright/loadConfig");
|
|
|
19
16
|
var _env = require("../../config/env");
|
|
20
17
|
var _config = require("../../config");
|
|
21
18
|
var _options = require("../options");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
19
|
+
const GEN_WORKER_PATH = _path.default.resolve(__dirname, '..', 'worker.js');
|
|
20
|
+
const 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: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
|
|
21
|
+
await (0, _loadConfig.loadConfig)(opts.config);
|
|
22
|
+
const configs = Object.values((0, _env.getEnvConfigs)());
|
|
23
|
+
assertConfigsCount(configs);
|
|
24
|
+
const cliOptions = buildCliOptions(opts);
|
|
25
|
+
await generateFilesForConfigs(configs, cliOptions);
|
|
46
26
|
});
|
|
47
27
|
exports.testCommand = testCommand;
|
|
48
28
|
function buildCliOptions(opts) {
|
|
49
|
-
|
|
29
|
+
const config = {};
|
|
50
30
|
if ('tags' in opts) config.tags = opts.tags;
|
|
51
31
|
if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
|
|
52
32
|
return config;
|
|
53
33
|
}
|
|
54
34
|
function assertConfigsCount(configs) {
|
|
55
35
|
if (configs.length === 0) {
|
|
56
|
-
(0, _utils.exitWithMessage)(
|
|
36
|
+
(0, _utils.exitWithMessage)(`No BDD configs found. Did you use defineBddConfig() in playwright.config.ts?`);
|
|
57
37
|
}
|
|
58
38
|
}
|
|
59
|
-
function runInWorker(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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);
|
|
39
|
+
async function runInWorker(config) {
|
|
40
|
+
const worker = new _worker_threads.Worker(GEN_WORKER_PATH, {
|
|
41
|
+
workerData: {
|
|
42
|
+
config
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// todo: check if worker exited with error?
|
|
47
|
+
await (0, _events.once)(worker, 'exit');
|
|
78
48
|
}
|
|
79
|
-
function generateFilesForConfigs(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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);
|
|
49
|
+
async function generateFilesForConfigs(configs, cliConfig) {
|
|
50
|
+
// run first config in main thread and other in workers (to have fresh require cache)
|
|
51
|
+
// See: https://github.com/vitalets/playwright-bdd/issues/32
|
|
52
|
+
const tasks = configs.map((config, index) => {
|
|
53
|
+
const finalConfig = {
|
|
54
|
+
...config,
|
|
55
|
+
...cliConfig
|
|
56
|
+
};
|
|
57
|
+
return index === 0 ? new _gen.TestFilesGenerator(finalConfig).generate() : runInWorker(finalConfig);
|
|
58
|
+
});
|
|
59
|
+
return Promise.all(tasks);
|
|
98
60
|
}
|
|
@@ -5,7 +5,7 @@ var _commander = require("commander");
|
|
|
5
5
|
var _test = require("./commands/test");
|
|
6
6
|
var _env = require("./commands/env");
|
|
7
7
|
var _export = require("./commands/export");
|
|
8
|
-
|
|
9
|
-
program.name('bddgen').description(
|
|
8
|
+
const program = new _commander.Command();
|
|
9
|
+
program.name('bddgen').description(`Playwright-bdd CLI v${(0, _env.getOwnVersion)()}`).addCommand(_test.testCommand, {
|
|
10
10
|
isDefault: true
|
|
11
11
|
}).addCommand(_export.exportCommand).addCommand(_env.envCommand).addHelpCommand(false).parse();
|
|
@@ -10,7 +10,7 @@ var _commander = require("commander");
|
|
|
10
10
|
* Config option moved to separate file as it used in test run.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Helper used in test run to detect config location.
|
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
3
|
var _worker_threads = require("worker_threads");
|
|
7
4
|
var _gen = require("../gen");
|
|
8
|
-
var _main;
|
|
9
5
|
/**
|
|
10
6
|
* Worker to generate test files with fresh require/import cache
|
|
11
7
|
* See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
|
|
12
8
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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);
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
await new _gen.TestFilesGenerator(_worker_threads.workerData.config).generate();
|
|
26
12
|
}
|
|
27
13
|
main();
|
|
@@ -19,9 +19,9 @@ var _options = require("../cli/options");
|
|
|
19
19
|
*/
|
|
20
20
|
function getPlaywrightConfigDir() {
|
|
21
21
|
if (!process.env.PLAYWRIGHT_BDD_CONFIG_DIR) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
process.env.PLAYWRIGHT_BDD_CONFIG_DIR = playwrightConfigFile ? _path
|
|
22
|
+
const cliConfigPath = (0, _options.getCliConfigPath)();
|
|
23
|
+
const playwrightConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
24
|
+
process.env.PLAYWRIGHT_BDD_CONFIG_DIR = playwrightConfigFile ? _path.default.dirname(playwrightConfigFile) : process.cwd();
|
|
25
25
|
}
|
|
26
26
|
return process.env.PLAYWRIGHT_BDD_CONFIG_DIR;
|
|
27
27
|
}
|
|
@@ -15,14 +15,14 @@ var _utils = require("../utils");
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
function saveConfigToEnv(config) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const envConfigs = getEnvConfigs();
|
|
19
|
+
const existingConfig = envConfigs[config.outputDir];
|
|
20
20
|
if (existingConfig) {
|
|
21
21
|
// Playwright config can be evaluated several times.
|
|
22
22
|
// Throw error only if different calls of defineBddConfig() use the same outputDir.
|
|
23
23
|
// See: https://github.com/vitalets/playwright-bdd/issues/39#issuecomment-1653805368
|
|
24
24
|
if (!isSameConfigs(config, existingConfig)) {
|
|
25
|
-
(0, _utils.exitWithMessage)(
|
|
25
|
+
(0, _utils.exitWithMessage)(`When using several calls of defineBddConfig()`, `please manually provide different "outputDir" option.`);
|
|
26
26
|
}
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -30,11 +30,11 @@ function saveConfigToEnv(config) {
|
|
|
30
30
|
saveEnvConfigs(envConfigs);
|
|
31
31
|
}
|
|
32
32
|
function getConfigFromEnv(outputDir) {
|
|
33
|
-
|
|
34
|
-
outputDir = _path
|
|
35
|
-
|
|
33
|
+
const envConfigs = getEnvConfigs();
|
|
34
|
+
outputDir = _path.default.resolve(outputDir);
|
|
35
|
+
const config = envConfigs[outputDir];
|
|
36
36
|
if (!config) {
|
|
37
|
-
(0, _utils.exitWithMessage)(
|
|
37
|
+
(0, _utils.exitWithMessage)(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
|
|
38
38
|
}
|
|
39
39
|
return config;
|
|
40
40
|
}
|
|
@@ -7,16 +7,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.defaults = void 0;
|
|
8
8
|
exports.defineBddConfig = defineBddConfig;
|
|
9
9
|
exports.extractCucumberConfig = extractCucumberConfig;
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
10
|
var _path = _interopRequireDefault(require("path"));
|
|
12
11
|
var _env = require("./env");
|
|
13
12
|
var _dir = require("./dir");
|
|
14
13
|
var _utils = require("../utils");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/**
|
|
15
|
+
* BDD Config.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const defaults = {
|
|
20
19
|
outputDir: '.features-gen',
|
|
21
20
|
verbose: false,
|
|
22
21
|
examplesTitleFormat: 'Example #<_index_>',
|
|
@@ -25,7 +24,7 @@ var defaults = {
|
|
|
25
24
|
};
|
|
26
25
|
exports.defaults = defaults;
|
|
27
26
|
function defineBddConfig(inputConfig) {
|
|
28
|
-
|
|
27
|
+
const config = getConfig(inputConfig);
|
|
29
28
|
|
|
30
29
|
// In main process store config in env to be accessible by workers
|
|
31
30
|
if (!process.env.TEST_WORKER_INDEX) {
|
|
@@ -34,20 +33,21 @@ function defineBddConfig(inputConfig) {
|
|
|
34
33
|
return config.outputDir;
|
|
35
34
|
}
|
|
36
35
|
function getConfig(inputConfig) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
36
|
+
const config = Object.assign({}, defaults, inputConfig);
|
|
37
|
+
const configDir = (0, _dir.getPlaywrightConfigDir)();
|
|
38
|
+
const featuresRoot = config.featuresRoot ? _path.default.resolve(configDir, config.featuresRoot) : configDir;
|
|
39
|
+
return {
|
|
40
|
+
...config,
|
|
41
41
|
// important to resolve outputDir as it is used as unique key for input configs
|
|
42
|
-
outputDir: _path
|
|
42
|
+
outputDir: _path.default.resolve(configDir, config.outputDir),
|
|
43
43
|
importTestFrom: resolveImportTestFrom(configDir, config.importTestFrom),
|
|
44
|
-
featuresRoot
|
|
45
|
-
}
|
|
44
|
+
featuresRoot
|
|
45
|
+
};
|
|
46
46
|
}
|
|
47
47
|
function extractCucumberConfig(config) {
|
|
48
48
|
// todo: find more strict way to omit own config fields
|
|
49
49
|
// see: https://bobbyhadz.com/blog/typescript-object-remove-property
|
|
50
|
-
|
|
50
|
+
const omitProps = {
|
|
51
51
|
outputDir: true,
|
|
52
52
|
importTestFrom: true,
|
|
53
53
|
verbose: true,
|
|
@@ -57,29 +57,30 @@ function extractCucumberConfig(config) {
|
|
|
57
57
|
tags: true,
|
|
58
58
|
featuresRoot: true
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const keys = Object.keys(omitProps);
|
|
61
|
+
const cucumberConfig = {
|
|
62
|
+
...config
|
|
63
|
+
};
|
|
64
|
+
keys.forEach(key => delete cucumberConfig[key]);
|
|
65
65
|
stripPublishQuiet(cucumberConfig);
|
|
66
66
|
return cucumberConfig;
|
|
67
67
|
}
|
|
68
68
|
function resolveImportTestFrom(configDir, importTestFrom) {
|
|
69
69
|
if (importTestFrom) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const {
|
|
71
|
+
file,
|
|
72
|
+
varName
|
|
73
|
+
} = typeof importTestFrom === 'string' ? {
|
|
74
|
+
file: importTestFrom
|
|
75
|
+
} : importTestFrom;
|
|
75
76
|
return {
|
|
76
|
-
file: _path
|
|
77
|
-
varName
|
|
77
|
+
file: _path.default.resolve(configDir, file),
|
|
78
|
+
varName
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
function stripPublishQuiet(cucumberConfig) {
|
|
82
|
-
|
|
83
|
+
const cucumberVersion = (0, _utils.getPackageVersion)('@cucumber/cucumber');
|
|
83
84
|
// Playwright-bdd supports Cucumber from v9+
|
|
84
85
|
// publishQuiet was deprecated in Cucumber 9.4.0.
|
|
85
86
|
// See: https://github.com/cucumber/cucumber-js/pull/2311
|
|
@@ -13,16 +13,17 @@ var _step_definition = _interopRequireDefault(require("@cucumber/cucumber/lib/mo
|
|
|
13
13
|
* See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
function buildStepDefinition(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const newId = _messages.IdGenerator.uuid();
|
|
17
|
+
function buildStepDefinition({
|
|
18
|
+
keyword,
|
|
19
|
+
pattern,
|
|
20
|
+
code,
|
|
21
|
+
line,
|
|
22
|
+
options,
|
|
23
|
+
uri
|
|
24
|
+
}, supportCodeLibrary) {
|
|
24
25
|
// todo: handle error.undefinedParameterTypeName as it's done in cucumber?
|
|
25
|
-
|
|
26
|
+
const expression = typeof pattern === 'string' ? new _cucumberExpressions.CucumberExpression(pattern, supportCodeLibrary.parameterTypeRegistry) : new _cucumberExpressions.RegularExpression(pattern, supportCodeLibrary.parameterTypeRegistry);
|
|
26
27
|
|
|
27
28
|
// skip wrapping code as it is not needed for decorator steps
|
|
28
29
|
// const wrappedCode = this.wrapCode({
|
|
@@ -30,15 +31,15 @@ function buildStepDefinition(_ref, supportCodeLibrary) {
|
|
|
30
31
|
// wrapperOptions: options.wrapperOptions,
|
|
31
32
|
// })
|
|
32
33
|
|
|
33
|
-
return new _step_definition
|
|
34
|
-
code
|
|
35
|
-
expression
|
|
34
|
+
return new _step_definition.default({
|
|
35
|
+
code,
|
|
36
|
+
expression,
|
|
36
37
|
id: newId(),
|
|
37
|
-
line
|
|
38
|
-
options
|
|
39
|
-
keyword
|
|
40
|
-
pattern
|
|
38
|
+
line,
|
|
39
|
+
options,
|
|
40
|
+
keyword,
|
|
41
|
+
pattern,
|
|
41
42
|
unwrappedCode: code,
|
|
42
|
-
uri
|
|
43
|
+
uri
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.loadConfig = loadConfig;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
7
|
var _api = require("@cucumber/cucumber/api");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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);
|
|
8
|
+
const cache = new Map();
|
|
9
|
+
async function loadConfig(options, environment) {
|
|
10
|
+
const cacheKey = JSON.stringify(options);
|
|
11
|
+
let config = cache.get(cacheKey);
|
|
12
|
+
if (!config) {
|
|
13
|
+
config = (0, _api.loadConfiguration)(options, environment);
|
|
14
|
+
cache.set(cacheKey, config);
|
|
15
|
+
}
|
|
16
|
+
return config;
|
|
32
17
|
}
|