@zohodesk/testinglibrary 0.0.4 → 0.0.5-exp.10
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 +16 -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 +47 -0
- package/build/bdd-framework/cli/commands/test.js +60 -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 +13 -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 +92 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +45 -0
- package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
- package/build/bdd-framework/cucumber/loadConfig.js +17 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
- package/build/bdd-framework/cucumber/loadSources.js +58 -0
- package/build/bdd-framework/cucumber/loadSteps.js +41 -0
- package/build/bdd-framework/decorators.js +21 -0
- package/build/bdd-framework/gen/formatter.js +92 -0
- package/build/bdd-framework/gen/i18n.js +44 -0
- package/build/bdd-framework/gen/index.js +150 -0
- package/build/bdd-framework/gen/poms.js +47 -0
- package/build/bdd-framework/gen/testFile.js +356 -0
- package/build/bdd-framework/gen/testNode.js +50 -0
- package/build/bdd-framework/index.js +33 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +103 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +50 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +47 -0
- package/build/bdd-framework/playwright/transform.js +85 -0
- package/build/bdd-framework/playwright/utils.js +24 -0
- package/build/bdd-framework/run/bddFixtures.js +109 -0
- package/build/bdd-framework/run/bddWorld.js +91 -0
- package/build/bdd-framework/snippets/index.js +132 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +50 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +32 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +52 -0
- package/build/bdd-framework/stepDefinitions/createDecorators.js +110 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
- package/build/bdd-framework/utils/index.js +52 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +21 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
- package/{src → build}/core/jest/runner/jest-runner.js +16 -15
- 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 +21 -0
- package/{src → build}/core/playwright/index.js +51 -21
- package/build/core/playwright/readConfigFile.js +64 -0
- package/build/core/playwright/report-generator.js +43 -0
- package/build/core/playwright/setup/config-creator.js +106 -0
- package/build/core/playwright/test-runner.js +106 -0
- package/build/index.js +37 -0
- package/build/lib/cli.js +45 -0
- package/build/lib/post-install.js +17 -0
- package/build/lint/index.js +7 -0
- package/build/setup-folder-structure/env-config-sample.json +17 -0
- package/build/setup-folder-structure/git-ignore.sample.js +39 -0
- package/build/setup-folder-structure/setupProject.js +104 -0
- package/build/setup-folder-structure/uat-config-sample.js +31 -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 +56 -0
- package/build/utils/rootPath.js +46 -0
- package/changelog.md +27 -0
- package/npm-shrinkwrap.json +2097 -147
- package/package.json +20 -5
- package/playwright.config.js +6 -6
- 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/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
|
+
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
|
+
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
|
+
const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
28
|
+
_logger.logger.log(`${packageName}: v${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
|
+
const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
42
|
+
const relPath = _path.default.relative(process.cwd(), resolvedConfigFile);
|
|
43
|
+
_logger.logger.log(`Playwright config file: ${relPath}`);
|
|
44
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _commander = require("commander");
|
|
10
|
+
var _options = require("../options");
|
|
11
|
+
var _loadConfig = require("../../playwright/loadConfig");
|
|
12
|
+
var _logger = require("../../utils/logger");
|
|
13
|
+
var _env = require("../../config/env");
|
|
14
|
+
var _test = require("./test");
|
|
15
|
+
var _gen = require("../../gen");
|
|
16
|
+
// filter by project?
|
|
17
|
+
|
|
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);
|
|
26
|
+
});
|
|
27
|
+
exports.exportCommand = exportCommand;
|
|
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));
|
|
38
|
+
}
|
|
39
|
+
function getStepText({
|
|
40
|
+
pattern,
|
|
41
|
+
keyword
|
|
42
|
+
}) {
|
|
43
|
+
// for Unknown return When as it looks the most suitable
|
|
44
|
+
const keywordText = keyword === 'Unknown' ? 'When' : keyword;
|
|
45
|
+
const patternText = typeof pattern === 'string' ? pattern : pattern.source;
|
|
46
|
+
return `${keywordText} ${patternText}`;
|
|
47
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 _worker_threads = require("worker_threads");
|
|
10
|
+
var _events = require("events");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _commander = require("commander");
|
|
13
|
+
var _gen = require("../../gen");
|
|
14
|
+
var _utils = require("../../utils");
|
|
15
|
+
var _loadConfig = require("../../playwright/loadConfig");
|
|
16
|
+
var _env = require("../../config/env");
|
|
17
|
+
var _config = require("../../config");
|
|
18
|
+
var _options = require("../options");
|
|
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);
|
|
26
|
+
});
|
|
27
|
+
exports.testCommand = testCommand;
|
|
28
|
+
function buildCliOptions(opts) {
|
|
29
|
+
const config = {};
|
|
30
|
+
if ('tags' in opts) config.tags = opts.tags;
|
|
31
|
+
if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
function assertConfigsCount(configs) {
|
|
35
|
+
if (configs.length === 0) {
|
|
36
|
+
(0, _utils.exitWithMessage)(`No BDD configs found. Did you use defineBddConfig() in playwright.config.ts?`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
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');
|
|
48
|
+
}
|
|
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);
|
|
60
|
+
}
|
|
@@ -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
|
+
const program = new _commander.Command();
|
|
9
|
+
program.name('bddgen').description(`Playwright-bdd CLI v${(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
|
+
const 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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _worker_threads = require("worker_threads");
|
|
4
|
+
var _gen = require("../gen");
|
|
5
|
+
/**
|
|
6
|
+
* Worker to generate test files with fresh require/import cache
|
|
7
|
+
* See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
await new _gen.TestFilesGenerator(_worker_threads.workerData.config).generate();
|
|
12
|
+
}
|
|
13
|
+
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
|
+
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
|
+
}
|
|
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
|
+
const envConfigs = getEnvConfigs();
|
|
19
|
+
const 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
|
+
const envConfigs = getEnvConfigs();
|
|
34
|
+
outputDir = _path.default.resolve(outputDir);
|
|
35
|
+
const config = envConfigs[outputDir];
|
|
36
|
+
if (!config) {
|
|
37
|
+
(0, _utils.exitWithMessage)(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${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,92 @@
|
|
|
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 _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _env = require("./env");
|
|
12
|
+
var _dir = require("./dir");
|
|
13
|
+
var _utils = require("../utils");
|
|
14
|
+
/**
|
|
15
|
+
* BDD Config.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const defaults = {
|
|
19
|
+
outputDir: '.features-gen',
|
|
20
|
+
verbose: false,
|
|
21
|
+
examplesTitleFormat: 'Example #<_index_>',
|
|
22
|
+
publishQuiet: true,
|
|
23
|
+
quotes: 'double'
|
|
24
|
+
};
|
|
25
|
+
exports.defaults = defaults;
|
|
26
|
+
function defineBddConfig(inputConfig) {
|
|
27
|
+
const config = getConfig(inputConfig);
|
|
28
|
+
|
|
29
|
+
// In main process store config in env to be accessible by workers
|
|
30
|
+
if (!process.env.TEST_WORKER_INDEX) {
|
|
31
|
+
(0, _env.saveConfigToEnv)(config);
|
|
32
|
+
}
|
|
33
|
+
return config.outputDir;
|
|
34
|
+
}
|
|
35
|
+
function getConfig(inputConfig) {
|
|
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
|
+
// 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
|
|
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
|
+
const 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
|
+
const keys = Object.keys(omitProps);
|
|
61
|
+
const cucumberConfig = {
|
|
62
|
+
...config
|
|
63
|
+
};
|
|
64
|
+
keys.forEach(key => delete cucumberConfig[key]);
|
|
65
|
+
stripPublishQuiet(cucumberConfig);
|
|
66
|
+
return cucumberConfig;
|
|
67
|
+
}
|
|
68
|
+
function resolveImportTestFrom(configDir, importTestFrom) {
|
|
69
|
+
if (importTestFrom) {
|
|
70
|
+
const {
|
|
71
|
+
file,
|
|
72
|
+
varName
|
|
73
|
+
} = typeof importTestFrom === 'string' ? {
|
|
74
|
+
file: importTestFrom
|
|
75
|
+
} : importTestFrom;
|
|
76
|
+
return {
|
|
77
|
+
file: _path.default.resolve(configDir, file),
|
|
78
|
+
varName
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function stripPublishQuiet(cucumberConfig) {
|
|
83
|
+
const cucumberVersion = (0, _utils.getPackageVersion)('@cucumber/cucumber');
|
|
84
|
+
// Playwright-bdd supports Cucumber from v9+
|
|
85
|
+
// publishQuiet was deprecated in Cucumber 9.4.0.
|
|
86
|
+
// See: https://github.com/cucumber/cucumber-js/pull/2311
|
|
87
|
+
// Remove publishQuite from Cucumber config to hide deprecation warning.
|
|
88
|
+
// See: https://github.com/vitalets/playwright-bdd/pull/47
|
|
89
|
+
if (!/^9\.[0123]\./.test(cucumberVersion)) {
|
|
90
|
+
delete cucumberConfig.publishQuiet;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const newId = _messages.IdGenerator.uuid();
|
|
17
|
+
function buildStepDefinition({
|
|
18
|
+
keyword,
|
|
19
|
+
pattern,
|
|
20
|
+
code,
|
|
21
|
+
line,
|
|
22
|
+
options,
|
|
23
|
+
uri
|
|
24
|
+
}, supportCodeLibrary) {
|
|
25
|
+
// todo: handle error.undefinedParameterTypeName as it's done in cucumber?
|
|
26
|
+
const expression = typeof pattern === 'string' ? new _cucumberExpressions.CucumberExpression(pattern, supportCodeLibrary.parameterTypeRegistry) : new _cucumberExpressions.RegularExpression(pattern, supportCodeLibrary.parameterTypeRegistry);
|
|
27
|
+
|
|
28
|
+
// skip wrapping code as it is not needed for decorator steps
|
|
29
|
+
// const wrappedCode = this.wrapCode({
|
|
30
|
+
// code,
|
|
31
|
+
// wrapperOptions: options.wrapperOptions,
|
|
32
|
+
// })
|
|
33
|
+
|
|
34
|
+
return new _step_definition.default({
|
|
35
|
+
code,
|
|
36
|
+
expression,
|
|
37
|
+
id: newId(),
|
|
38
|
+
line,
|
|
39
|
+
options,
|
|
40
|
+
keyword,
|
|
41
|
+
pattern,
|
|
42
|
+
unwrappedCode: code,
|
|
43
|
+
uri
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -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,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
var _api = require("@cucumber/cucumber/api");
|
|
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;
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadFeatures = loadFeatures;
|
|
7
|
+
var _loadSources = require("./loadSources");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
async function loadFeatures(runConfiguration, environment) {
|
|
10
|
+
const {
|
|
11
|
+
filteredPickles,
|
|
12
|
+
parseErrors
|
|
13
|
+
} = await (0, _loadSources.loadSources)(runConfiguration.sources, environment);
|
|
14
|
+
handleParseErrors(parseErrors);
|
|
15
|
+
return groupByDocument(filteredPickles);
|
|
16
|
+
}
|
|
17
|
+
function groupByDocument(filteredPickles) {
|
|
18
|
+
const features = new Map();
|
|
19
|
+
filteredPickles.forEach(({
|
|
20
|
+
pickle,
|
|
21
|
+
gherkinDocument
|
|
22
|
+
}) => {
|
|
23
|
+
let pickles = features.get(gherkinDocument);
|
|
24
|
+
if (!pickles) {
|
|
25
|
+
pickles = [];
|
|
26
|
+
features.set(gherkinDocument, pickles);
|
|
27
|
+
}
|
|
28
|
+
pickles.push(pickle);
|
|
29
|
+
});
|
|
30
|
+
return features;
|
|
31
|
+
}
|
|
32
|
+
function handleParseErrors(parseErrors) {
|
|
33
|
+
if (parseErrors.length) {
|
|
34
|
+
const message = parseErrors.map(parseError => {
|
|
35
|
+
return `Parse error in "${parseError.source.uri}" ${parseError.message}`;
|
|
36
|
+
}).join('\n');
|
|
37
|
+
(0, _utils.exitWithMessage)(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadSnippetBuilder = loadSnippetBuilder;
|
|
7
|
+
var _cucumber = require("@cucumber/cucumber");
|
|
8
|
+
/**
|
|
9
|
+
* Loads snippet builder
|
|
10
|
+
* See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/builder.ts
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
async function loadSnippetBuilder(supportCodeLibrary, snippetInterface, snippetSyntax) {
|
|
14
|
+
return _cucumber.FormatterBuilder.getStepDefinitionSnippetBuilder({
|
|
15
|
+
cwd: process.cwd(),
|
|
16
|
+
snippetInterface,
|
|
17
|
+
snippetSyntax,
|
|
18
|
+
supportCodeLibrary
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadSources = loadSources;
|
|
7
|
+
var _paths = require("@cucumber/cucumber/lib/api/paths");
|
|
8
|
+
var _messages = require("@cucumber/messages");
|
|
9
|
+
var _environment = require("@cucumber/cucumber/lib/api/environment");
|
|
10
|
+
var _gherkin = require("@cucumber/cucumber/lib/api/gherkin");
|
|
11
|
+
var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
|
|
12
|
+
/**
|
|
13
|
+
* Copied from original load_sources, but returns full Pickles.
|
|
14
|
+
* See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
|
|
15
|
+
*/
|
|
16
|
+
/// <reference path="./gherkin.d.ts" />
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Load and parse features, produce a filtered and ordered test plan and/or parse errors.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @param coordinates - Coordinates required to find features
|
|
23
|
+
* @param environment - Project environment.
|
|
24
|
+
*/
|
|
25
|
+
async function loadSources(coordinates, environment = {}) {
|
|
26
|
+
const {
|
|
27
|
+
cwd,
|
|
28
|
+
stderr,
|
|
29
|
+
debug
|
|
30
|
+
} = (0, _environment.mergeEnvironment)(environment);
|
|
31
|
+
const logger = new _console_logger.ConsoleLogger(stderr, debug);
|
|
32
|
+
const newId = _messages.IdGenerator.uuid();
|
|
33
|
+
const {
|
|
34
|
+
unexpandedFeaturePaths,
|
|
35
|
+
featurePaths
|
|
36
|
+
} = await (0, _paths.resolvePaths)(logger, cwd, coordinates);
|
|
37
|
+
if (featurePaths.length === 0) {
|
|
38
|
+
return {
|
|
39
|
+
filteredPickles: [],
|
|
40
|
+
parseErrors: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const {
|
|
44
|
+
filteredPickles,
|
|
45
|
+
parseErrors
|
|
46
|
+
} = await (0, _gherkin.getFilteredPicklesAndErrors)({
|
|
47
|
+
newId,
|
|
48
|
+
cwd,
|
|
49
|
+
logger,
|
|
50
|
+
unexpandedFeaturePaths,
|
|
51
|
+
featurePaths,
|
|
52
|
+
coordinates
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
filteredPickles,
|
|
56
|
+
parseErrors
|
|
57
|
+
};
|
|
58
|
+
}
|