@zohodesk/testinglibrary 0.0.5-exp.23 → 0.0.5-exp.25
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 +4 -0
- package/build/bdd-framework/cli/commands/env.js +12 -21
- package/build/bdd-framework/cli/commands/export.js +15 -23
- package/build/bdd-framework/cli/commands/test.js +19 -28
- package/build/bdd-framework/cli/index.js +7 -9
- package/build/bdd-framework/cli/options.js +4 -13
- package/build/bdd-framework/cli/worker.js +3 -6
- package/build/bdd-framework/config/dir.js +7 -15
- package/build/bdd-framework/config/env.js +8 -18
- package/build/bdd-framework/config/index.js +13 -24
- package/build/bdd-framework/cucumber/buildStepDefinition.js +7 -15
- package/build/bdd-framework/cucumber/gherkin.d.js +1 -5
- package/build/bdd-framework/cucumber/loadConfig.js +3 -9
- package/build/bdd-framework/cucumber/loadFeatures.js +5 -11
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +3 -10
- package/build/bdd-framework/cucumber/loadSources.js +11 -18
- package/build/bdd-framework/cucumber/loadSteps.js +9 -17
- package/build/bdd-framework/decorators.js +7 -22
- package/build/bdd-framework/gen/formatter.js +3 -11
- package/build/bdd-framework/gen/i18n.js +3 -10
- package/build/bdd-framework/gen/index.js +41 -50
- package/build/bdd-framework/gen/poms.js +4 -12
- package/build/bdd-framework/gen/testFile.js +35 -44
- package/build/bdd-framework/gen/testNode.js +4 -12
- package/build/bdd-framework/gen/testPoms.js +7 -16
- package/build/bdd-framework/index.js +4 -45
- package/build/bdd-framework/playwright/fixtureParameterNames.js +1 -7
- package/build/bdd-framework/playwright/getLocationInFile.js +5 -12
- package/build/bdd-framework/playwright/loadConfig.js +12 -21
- package/build/bdd-framework/playwright/testTypeImpl.js +5 -13
- package/build/bdd-framework/playwright/transform.js +15 -23
- package/build/bdd-framework/playwright/types.js +4 -5
- package/build/bdd-framework/playwright/utils.js +10 -18
- package/build/bdd-framework/run/bddFixtures.js +18 -26
- package/build/bdd-framework/run/bddWorld.js +12 -20
- package/build/bdd-framework/snippets/index.js +12 -20
- package/build/bdd-framework/snippets/snippetSyntax.js +2 -9
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +2 -9
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +3 -12
- package/build/bdd-framework/stepDefinitions/createBdd.js +12 -20
- package/build/bdd-framework/stepDefinitions/createDecorators.js +10 -19
- package/build/bdd-framework/stepDefinitions/decorators/poms.js +4 -12
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +9 -18
- package/build/bdd-framework/stepDefinitions/defineStep.js +10 -18
- package/build/bdd-framework/stepDefinitions/stepConfig.js +3 -11
- package/build/bdd-framework/utils/index.js +13 -25
- package/build/bdd-framework/utils/jsStringWrap.js +1 -7
- package/build/bdd-framework/utils/logger.js +2 -10
- package/build/core/jest/preprocessor/jsPreprocessor.js +3 -11
- package/build/core/jest/runner/jest-runner.js +6 -13
- package/build/core/jest/setup/index.js +167 -9
- package/build/core/playwright/codegen.js +11 -18
- package/build/core/playwright/custom-commands.js +1 -8
- package/build/core/playwright/env-initializer.js +5 -11
- package/build/core/playwright/index.js +7 -28
- package/build/core/playwright/readConfigFile.js +12 -22
- package/build/core/playwright/report-generator.js +14 -21
- package/build/core/playwright/setup/config-creator.js +22 -30
- package/build/core/playwright/test-runner.js +32 -39
- package/build/index.js +13 -36
- package/build/lib/cli.js +17 -21
- package/build/lib/post-install.js +8 -11
- package/build/lint/index.js +1 -2
- package/build/parser/parser.js +18 -26
- package/build/parser/sample.spec.js +5 -7
- package/build/parser/verifier.js +24 -26
- package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -0
- package/build/setup-folder-structure/{authUsers-sample.json → samples/authUsers-sample.json} +2 -2
- package/build/setup-folder-structure/samples/git-ignore.sample.js +33 -0
- package/build/setup-folder-structure/{uat-config-sample.js → samples/uat-config-sample.js} +8 -10
- package/build/setup-folder-structure/setupProject.js +35 -42
- package/build/utils/cliArgsToObject.js +2 -8
- package/build/utils/fileUtils.js +9 -18
- package/build/utils/getFilePath.js +3 -9
- package/build/utils/logger.js +1 -8
- package/build/utils/rootPath.js +12 -21
- package/changelog.md +8 -0
- package/package.json +1 -1
- package/build/setup-folder-structure/auth-setup-sample.js +0 -67
- package/build/setup-folder-structure/git-ignore.sample.js +0 -38
- /package/build/setup-folder-structure/{env-config-sample.json → samples/env-config-sample.json} +0 -0
package/.babelrc
CHANGED
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
"targets": {
|
|
7
7
|
"node": "14"
|
|
8
8
|
},
|
|
9
|
+
"modules": false,
|
|
9
10
|
"exclude": ["@babel/plugin-transform-destructuring"]
|
|
10
11
|
}
|
|
11
12
|
]
|
|
12
13
|
],
|
|
13
14
|
"plugins": [
|
|
14
15
|
["@babel/plugin-transform-runtime"]
|
|
16
|
+
],
|
|
17
|
+
"ignore": [
|
|
18
|
+
"./src/setup-folder-structure/samples"
|
|
15
19
|
]
|
|
16
20
|
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
exports.getOwnVersion = getOwnVersion;
|
|
9
|
-
var _commander = require("commander");
|
|
10
|
-
var _options = require("../options");
|
|
11
|
-
var _path = _interopRequireDefault(require("path"));
|
|
12
|
-
var _logger = require("../../utils/logger");
|
|
13
|
-
var _utils = require("../../utils");
|
|
14
|
-
var _loadConfig = require("../../playwright/loadConfig");
|
|
15
|
-
const logger = new _logger.Logger({
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { configOption } from '../options';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { Logger } from '../../utils/logger';
|
|
5
|
+
import { getPackageVersion } from '../../utils';
|
|
6
|
+
import { resolveConfigFile } from '../../playwright/loadConfig';
|
|
7
|
+
const logger = new Logger({
|
|
16
8
|
verbose: true
|
|
17
9
|
});
|
|
18
|
-
const envCommand = new
|
|
10
|
+
export const envCommand = new Command('env').description('Prints environment info').addOption(configOption).action(opts => {
|
|
19
11
|
logger.log(`Playwright-bdd environment info:\n`);
|
|
20
12
|
logger.log(`platform: ${process.platform}`);
|
|
21
13
|
logger.log(`node: ${process.version}`);
|
|
@@ -24,20 +16,19 @@ const envCommand = new _commander.Command('env').description('Prints environment
|
|
|
24
16
|
showPackageVersion('@cucumber/cucumber');
|
|
25
17
|
showPlaywrightConfigPath(opts.config);
|
|
26
18
|
});
|
|
27
|
-
exports.envCommand = envCommand;
|
|
28
19
|
function showPackageVersion(packageName) {
|
|
29
|
-
const version = packageName === 'playwright-bdd' ? getOwnVersion() :
|
|
20
|
+
const version = packageName === 'playwright-bdd' ? getOwnVersion() : getPackageVersion(packageName);
|
|
30
21
|
logger.log(`${packageName}: v${version}`);
|
|
31
22
|
}
|
|
32
23
|
/**
|
|
33
24
|
* Getting own version by relative path instead of using getPackageVersion(),
|
|
34
25
|
* to aneble using directly from /dist in tests.
|
|
35
26
|
*/
|
|
36
|
-
function getOwnVersion() {
|
|
27
|
+
export function getOwnVersion() {
|
|
37
28
|
return '5.3.0';
|
|
38
29
|
}
|
|
39
30
|
function showPlaywrightConfigPath(cliConfigPath) {
|
|
40
|
-
const resolvedConfigFile =
|
|
41
|
-
const relPath =
|
|
31
|
+
const resolvedConfigFile = resolveConfigFile(cliConfigPath);
|
|
32
|
+
const relPath = path.relative(process.cwd(), resolvedConfigFile);
|
|
42
33
|
logger.log(`Playwright config file: ${relPath}`);
|
|
43
34
|
}
|
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
const logger = new _logger.Logger({
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { configOption } from '../options';
|
|
4
|
+
import { loadConfig as loadPlaywrightConfig } from '../../playwright/loadConfig';
|
|
5
|
+
import { Logger } from '../../utils/logger';
|
|
6
|
+
import { getEnvConfigs } from '../../config/env';
|
|
7
|
+
import { assertConfigsCount } from './test';
|
|
8
|
+
import { TestFilesGenerator } from '../../gen';
|
|
9
|
+
const logger = new Logger({
|
|
17
10
|
verbose: true
|
|
18
11
|
});
|
|
19
|
-
const exportCommand = new
|
|
12
|
+
export const exportCommand = new Command('export').description('Prints all step definitions').addOption(configOption).action(async opts => {
|
|
20
13
|
const {
|
|
21
14
|
resolvedConfigFile
|
|
22
|
-
} = await (
|
|
23
|
-
logger.log(`List of all steps found by config: ${
|
|
24
|
-
const configs = Object.values(
|
|
25
|
-
|
|
15
|
+
} = await loadPlaywrightConfig(opts.config);
|
|
16
|
+
logger.log(`List of all steps found by config: ${path.relative(process.cwd(), resolvedConfigFile)}\n`);
|
|
17
|
+
const configs = Object.values(getEnvConfigs());
|
|
18
|
+
assertConfigsCount(configs);
|
|
26
19
|
await showStepsForConfigs(configs);
|
|
27
20
|
});
|
|
28
|
-
exports.exportCommand = exportCommand;
|
|
29
21
|
async function showStepsForConfigs(configs) {
|
|
30
22
|
// here we don't need workers (as in test command) because if some step files
|
|
31
23
|
// are already in node cache, we collected them.
|
|
32
24
|
const steps = new Set();
|
|
33
25
|
const tasks = configs.map(async config => {
|
|
34
|
-
const stepDefinitions = await new
|
|
26
|
+
const stepDefinitions = await new TestFilesGenerator(config).extractSteps();
|
|
35
27
|
stepDefinitions.forEach(s => steps.add(`* ${getStepText(s)}`));
|
|
36
28
|
});
|
|
37
29
|
await Promise.all(tasks);
|
|
@@ -1,39 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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)());
|
|
1
|
+
import { Worker } from 'worker_threads';
|
|
2
|
+
import { once } from 'events';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import { TestFilesGenerator } from '../../gen';
|
|
6
|
+
import { exitWithMessage } from '../../utils';
|
|
7
|
+
import { loadConfig as loadPlaywrightConfig } from '../../playwright/loadConfig';
|
|
8
|
+
import { getEnvConfigs } from '../../config/env';
|
|
9
|
+
import { defaults } from '../../config';
|
|
10
|
+
import { configOption } from '../options';
|
|
11
|
+
const GEN_WORKER_PATH = path.resolve(__dirname, '..', 'worker.js');
|
|
12
|
+
export const testCommand = new Command('test').description('Generate Playwright test files from Gherkin documents').addOption(configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(defaults.verbose)})`).action(async opts => {
|
|
13
|
+
await loadPlaywrightConfig(opts.config);
|
|
14
|
+
const configs = Object.values(getEnvConfigs());
|
|
23
15
|
assertConfigsCount(configs);
|
|
24
16
|
const cliOptions = buildCliOptions(opts);
|
|
25
17
|
await generateFilesForConfigs(configs, cliOptions);
|
|
26
18
|
});
|
|
27
|
-
exports.testCommand = testCommand;
|
|
28
19
|
function buildCliOptions(opts) {
|
|
29
20
|
const config = {};
|
|
30
21
|
if ('tags' in opts) config.tags = opts.tags;
|
|
31
22
|
if ('verbose' in opts) config.verbose = Boolean(opts.verbose);
|
|
32
23
|
return config;
|
|
33
24
|
}
|
|
34
|
-
function assertConfigsCount(configs) {
|
|
25
|
+
export function assertConfigsCount(configs) {
|
|
35
26
|
if (configs.length === 0) {
|
|
36
|
-
|
|
27
|
+
exitWithMessage(`No BDD configs found. Did you use defineBddConfig() in playwright.config.ts?`);
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
async function generateFilesForConfigs(configs, cliConfig) {
|
|
@@ -44,16 +35,16 @@ async function generateFilesForConfigs(configs, cliConfig) {
|
|
|
44
35
|
...config,
|
|
45
36
|
...cliConfig
|
|
46
37
|
};
|
|
47
|
-
return index === 0 ? new
|
|
38
|
+
return index === 0 ? new TestFilesGenerator(finalConfig).generate() : runInWorker(finalConfig);
|
|
48
39
|
});
|
|
49
40
|
return Promise.all(tasks);
|
|
50
41
|
}
|
|
51
42
|
async function runInWorker(config) {
|
|
52
|
-
const worker = new
|
|
43
|
+
const worker = new Worker(GEN_WORKER_PATH, {
|
|
53
44
|
workerData: {
|
|
54
45
|
config
|
|
55
46
|
}
|
|
56
47
|
});
|
|
57
48
|
// todo: check if worker exited with error?
|
|
58
|
-
await
|
|
49
|
+
await once(worker, 'exit');
|
|
59
50
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const program = new _commander.Command();
|
|
9
|
-
program.name('bddgen').description(`Playwright-bdd CLI v${(0, _env.getOwnVersion)()}`).addCommand(_test.testCommand, {
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { testCommand } from './commands/test';
|
|
4
|
+
import { envCommand, getOwnVersion } from './commands/env';
|
|
5
|
+
import { exportCommand } from './commands/export';
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program.name('bddgen').description(`Playwright-bdd CLI v${getOwnVersion()}`).addCommand(testCommand, {
|
|
10
8
|
isDefault: true
|
|
11
|
-
}).addCommand(
|
|
9
|
+
}).addCommand(exportCommand).addCommand(envCommand).addHelpCommand(false).parse();
|
|
@@ -1,20 +1,11 @@
|
|
|
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
1
|
/**
|
|
10
2
|
* Config option moved to separate file as it used in test run.
|
|
11
3
|
*/
|
|
12
|
-
|
|
13
|
-
const configOption = new
|
|
4
|
+
import { Command, Option } from 'commander';
|
|
5
|
+
export const configOption = new Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
14
6
|
/**
|
|
15
7
|
* Helper used in test run to detect config location.
|
|
16
8
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
9
|
+
export function getCliConfigPath() {
|
|
10
|
+
return new Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
20
11
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _worker_threads = require("worker_threads");
|
|
4
|
-
var _gen = require("../gen");
|
|
5
1
|
/**
|
|
6
2
|
* Worker to generate test files with fresh require/import cache
|
|
7
3
|
* See: https://github.com/nodejs/modules/issues/307#issuecomment-858729422
|
|
8
4
|
*/
|
|
9
|
-
|
|
5
|
+
import { workerData } from 'worker_threads';
|
|
6
|
+
import { TestFilesGenerator } from '../gen';
|
|
10
7
|
async function main() {
|
|
11
|
-
await new
|
|
8
|
+
await new TestFilesGenerator(workerData.config).generate();
|
|
12
9
|
}
|
|
13
10
|
main();
|
|
@@ -1,27 +1,19 @@
|
|
|
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
1
|
/**
|
|
12
2
|
* Store playwright config dir in env to provide access to it in workers.
|
|
13
3
|
* Important that in workers there is different process.argv, that's why we save it to env.
|
|
14
4
|
* Config dir is needed to resolve all paths.
|
|
15
5
|
*/
|
|
16
|
-
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { resolveConfigFile } from '../playwright/loadConfig';
|
|
8
|
+
import { getCliConfigPath } from '../cli/options';
|
|
17
9
|
/**
|
|
18
10
|
* Resolve playwright config dir considering cli flags.
|
|
19
11
|
*/
|
|
20
|
-
function getPlaywrightConfigDir() {
|
|
12
|
+
export function getPlaywrightConfigDir() {
|
|
21
13
|
if (!process.env.PLAYWRIGHT_BDD_CONFIG_DIR) {
|
|
22
|
-
const cliConfigPath =
|
|
23
|
-
const playwrightConfigFile =
|
|
24
|
-
process.env.PLAYWRIGHT_BDD_CONFIG_DIR = playwrightConfigFile ?
|
|
14
|
+
const cliConfigPath = getCliConfigPath();
|
|
15
|
+
const playwrightConfigFile = resolveConfigFile(cliConfigPath);
|
|
16
|
+
process.env.PLAYWRIGHT_BDD_CONFIG_DIR = playwrightConfigFile ? path.dirname(playwrightConfigFile) : process.cwd();
|
|
25
17
|
}
|
|
26
18
|
return process.env.PLAYWRIGHT_BDD_CONFIG_DIR;
|
|
27
19
|
}
|
|
@@ -1,20 +1,10 @@
|
|
|
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
1
|
/**
|
|
13
2
|
* Storing configs in env var PLAYWRIGHT_BDD_CONFIGS as JSON-stringified values.
|
|
14
3
|
* For passing configs to playwright workers and bddgen.
|
|
15
4
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { exitWithMessage } from '../utils';
|
|
7
|
+
export function saveConfigToEnv(config) {
|
|
18
8
|
const envConfigs = getEnvConfigs();
|
|
19
9
|
const existingConfig = envConfigs[config.outputDir];
|
|
20
10
|
if (existingConfig) {
|
|
@@ -22,23 +12,23 @@ function saveConfigToEnv(config) {
|
|
|
22
12
|
// Throw error only if different calls of defineBddConfig() use the same outputDir.
|
|
23
13
|
// See: https://github.com/vitalets/playwright-bdd/issues/39#issuecomment-1653805368
|
|
24
14
|
if (!isSameConfigs(config, existingConfig)) {
|
|
25
|
-
|
|
15
|
+
exitWithMessage(`When using several calls of defineBddConfig()`, `please manually provide different "outputDir" option.`);
|
|
26
16
|
}
|
|
27
17
|
return;
|
|
28
18
|
}
|
|
29
19
|
envConfigs[config.outputDir] = config;
|
|
30
20
|
saveEnvConfigs(envConfigs);
|
|
31
21
|
}
|
|
32
|
-
function getConfigFromEnv(outputDir) {
|
|
22
|
+
export function getConfigFromEnv(outputDir) {
|
|
33
23
|
const envConfigs = getEnvConfigs();
|
|
34
|
-
outputDir =
|
|
24
|
+
outputDir = path.resolve(outputDir);
|
|
35
25
|
const config = envConfigs[outputDir];
|
|
36
26
|
if (!config) {
|
|
37
|
-
|
|
27
|
+
exitWithMessage(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
|
|
38
28
|
}
|
|
39
29
|
return config;
|
|
40
30
|
}
|
|
41
|
-
function getEnvConfigs() {
|
|
31
|
+
export function getEnvConfigs() {
|
|
42
32
|
return JSON.parse(process.env.PLAYWRIGHT_BDD_CONFIGS || '{}');
|
|
43
33
|
}
|
|
44
34
|
function saveEnvConfigs(envConfigs) {
|
|
@@ -1,49 +1,38 @@
|
|
|
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
1
|
/**
|
|
15
2
|
* BDD Config.
|
|
16
3
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { saveConfigToEnv } from './env';
|
|
6
|
+
import { getPlaywrightConfigDir } from './dir';
|
|
7
|
+
import { getPackageVersion } from '../utils';
|
|
8
|
+
export const defaults = {
|
|
19
9
|
outputDir: '.features-gen',
|
|
20
10
|
verbose: false,
|
|
21
11
|
examplesTitleFormat: 'Example #<_index_>',
|
|
22
12
|
publishQuiet: true,
|
|
23
13
|
quotes: 'double'
|
|
24
14
|
};
|
|
25
|
-
|
|
26
|
-
function defineBddConfig(inputConfig) {
|
|
15
|
+
export function defineBddConfig(inputConfig) {
|
|
27
16
|
const config = getConfig(inputConfig);
|
|
28
17
|
// In main process store config in env to be accessible by workers
|
|
29
18
|
if (!process.env.TEST_WORKER_INDEX) {
|
|
30
|
-
|
|
19
|
+
saveConfigToEnv(config);
|
|
31
20
|
}
|
|
32
21
|
return config.outputDir;
|
|
33
22
|
}
|
|
34
23
|
function getConfig(inputConfig) {
|
|
35
24
|
const config = Object.assign({}, defaults, inputConfig);
|
|
36
|
-
const configDir =
|
|
37
|
-
const featuresRoot = config.featuresRoot ?
|
|
25
|
+
const configDir = getPlaywrightConfigDir();
|
|
26
|
+
const featuresRoot = config.featuresRoot ? path.resolve(configDir, config.featuresRoot) : configDir;
|
|
38
27
|
return {
|
|
39
28
|
...config,
|
|
40
29
|
// important to resolve outputDir as it is used as unique key for input configs
|
|
41
|
-
outputDir:
|
|
30
|
+
outputDir: path.resolve(configDir, config.outputDir),
|
|
42
31
|
importTestFrom: resolveImportTestFrom(configDir, config.importTestFrom),
|
|
43
32
|
featuresRoot
|
|
44
33
|
};
|
|
45
34
|
}
|
|
46
|
-
function extractCucumberConfig(config) {
|
|
35
|
+
export function extractCucumberConfig(config) {
|
|
47
36
|
// todo: find more strict way to omit own config fields
|
|
48
37
|
// see: https://bobbyhadz.com/blog/typescript-object-remove-property
|
|
49
38
|
const omitProps = {
|
|
@@ -73,13 +62,13 @@ function resolveImportTestFrom(configDir, importTestFrom) {
|
|
|
73
62
|
file: importTestFrom
|
|
74
63
|
} : importTestFrom;
|
|
75
64
|
return {
|
|
76
|
-
file:
|
|
65
|
+
file: path.resolve(configDir, file),
|
|
77
66
|
varName
|
|
78
67
|
};
|
|
79
68
|
}
|
|
80
69
|
}
|
|
81
70
|
function stripPublishQuiet(cucumberConfig) {
|
|
82
|
-
const cucumberVersion =
|
|
71
|
+
const cucumberVersion = getPackageVersion('@cucumber/cucumber');
|
|
83
72
|
// Playwright-bdd supports Cucumber from v9+
|
|
84
73
|
// publishQuiet was deprecated in Cucumber 9.4.0.
|
|
85
74
|
// See: https://github.com/cucumber/cucumber-js/pull/2311
|
|
@@ -1,20 +1,12 @@
|
|
|
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
1
|
/**
|
|
12
2
|
* Extracted from cucumber SupportCodeLibraryBuilder.
|
|
13
3
|
* See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts
|
|
14
4
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
import { IdGenerator } from '@cucumber/messages';
|
|
6
|
+
import { CucumberExpression, RegularExpression } from '@cucumber/cucumber-expressions';
|
|
7
|
+
import StepDefinition from '@cucumber/cucumber/lib/models/step_definition';
|
|
8
|
+
const newId = IdGenerator.uuid();
|
|
9
|
+
export function buildStepDefinition({
|
|
18
10
|
keyword,
|
|
19
11
|
pattern,
|
|
20
12
|
code,
|
|
@@ -23,13 +15,13 @@ function buildStepDefinition({
|
|
|
23
15
|
uri
|
|
24
16
|
}, supportCodeLibrary) {
|
|
25
17
|
// todo: handle error.undefinedParameterTypeName as it's done in cucumber?
|
|
26
|
-
const expression = typeof pattern === 'string' ? new
|
|
18
|
+
const expression = typeof pattern === 'string' ? new CucumberExpression(pattern, supportCodeLibrary.parameterTypeRegistry) : new RegularExpression(pattern, supportCodeLibrary.parameterTypeRegistry);
|
|
27
19
|
// skip wrapping code as it is not needed for decorator steps
|
|
28
20
|
// const wrappedCode = this.wrapCode({
|
|
29
21
|
// code,
|
|
30
22
|
// wrapperOptions: options.wrapperOptions,
|
|
31
23
|
// })
|
|
32
|
-
return new
|
|
24
|
+
return new StepDefinition({
|
|
33
25
|
code,
|
|
34
26
|
expression,
|
|
35
27
|
id: newId(),
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadConfig = loadConfig;
|
|
7
|
-
var _api = require("@cucumber/cucumber/api");
|
|
1
|
+
import { loadConfiguration } from '@cucumber/cucumber/api';
|
|
8
2
|
const cache = new Map();
|
|
9
|
-
async function loadConfig(options, environment) {
|
|
3
|
+
export async function loadConfig(options, environment) {
|
|
10
4
|
const cacheKey = JSON.stringify(options);
|
|
11
5
|
let config = cache.get(cacheKey);
|
|
12
6
|
if (!config) {
|
|
13
|
-
config =
|
|
7
|
+
config = loadConfiguration(options, environment);
|
|
14
8
|
cache.set(cacheKey, config);
|
|
15
9
|
}
|
|
16
10
|
return config;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadFeatures = loadFeatures;
|
|
7
|
-
var _loadSources = require("./loadSources");
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
async function loadFeatures(runConfiguration, environment) {
|
|
1
|
+
import { loadSources } from './loadSources';
|
|
2
|
+
import { exitWithMessage } from '../utils';
|
|
3
|
+
export async function loadFeatures(runConfiguration, environment) {
|
|
10
4
|
const {
|
|
11
5
|
filteredPickles,
|
|
12
6
|
parseErrors
|
|
13
|
-
} = await
|
|
7
|
+
} = await loadSources(runConfiguration.sources, environment);
|
|
14
8
|
handleParseErrors(parseErrors);
|
|
15
9
|
return groupByDocument(filteredPickles);
|
|
16
10
|
}
|
|
@@ -34,6 +28,6 @@ function handleParseErrors(parseErrors) {
|
|
|
34
28
|
const message = parseErrors.map(parseError => {
|
|
35
29
|
return `Parse error in "${parseError.source.uri}" ${parseError.message}`;
|
|
36
30
|
}).join('\n');
|
|
37
|
-
|
|
31
|
+
exitWithMessage(message);
|
|
38
32
|
}
|
|
39
33
|
}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadSnippetBuilder = loadSnippetBuilder;
|
|
7
|
-
var _cucumber = require("@cucumber/cucumber");
|
|
8
1
|
/**
|
|
9
2
|
* Loads snippet builder
|
|
10
3
|
* See: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/builder.ts
|
|
11
4
|
*/
|
|
12
|
-
|
|
13
|
-
async function loadSnippetBuilder(supportCodeLibrary, snippetInterface, snippetSyntax) {
|
|
14
|
-
return
|
|
5
|
+
import { FormatterBuilder } from '@cucumber/cucumber';
|
|
6
|
+
export async function loadSnippetBuilder(supportCodeLibrary, snippetInterface, snippetSyntax) {
|
|
7
|
+
return FormatterBuilder.getStepDefinitionSnippetBuilder({
|
|
15
8
|
cwd: process.cwd(),
|
|
16
9
|
snippetInterface,
|
|
17
10
|
snippetSyntax,
|
|
@@ -1,19 +1,12 @@
|
|
|
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
1
|
/**
|
|
13
2
|
* Copied from original load_sources, but returns full Pickles.
|
|
14
3
|
* See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
|
|
15
4
|
*/
|
|
16
|
-
|
|
5
|
+
import { resolvePaths } from '@cucumber/cucumber/lib/api/paths';
|
|
6
|
+
import { IdGenerator } from '@cucumber/messages';
|
|
7
|
+
import { mergeEnvironment } from '@cucumber/cucumber/lib/api/environment';
|
|
8
|
+
import { getFilteredPicklesAndErrors } from '@cucumber/cucumber/lib/api/gherkin';
|
|
9
|
+
import { ConsoleLogger } from '@cucumber/cucumber/lib/api/console_logger';
|
|
17
10
|
/**
|
|
18
11
|
* Load and parse features, produce a filtered and ordered test plan and/or parse errors.
|
|
19
12
|
*
|
|
@@ -21,18 +14,18 @@ var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
|
|
|
21
14
|
* @param coordinates - Coordinates required to find features
|
|
22
15
|
* @param environment - Project environment.
|
|
23
16
|
*/
|
|
24
|
-
async function loadSources(coordinates, environment = {}) {
|
|
17
|
+
export async function loadSources(coordinates, environment = {}) {
|
|
25
18
|
const {
|
|
26
19
|
cwd,
|
|
27
20
|
stderr,
|
|
28
21
|
debug
|
|
29
|
-
} =
|
|
30
|
-
const logger = new
|
|
31
|
-
const newId =
|
|
22
|
+
} = mergeEnvironment(environment);
|
|
23
|
+
const logger = new ConsoleLogger(stderr, debug);
|
|
24
|
+
const newId = IdGenerator.uuid();
|
|
32
25
|
const {
|
|
33
26
|
unexpandedFeaturePaths,
|
|
34
27
|
featurePaths
|
|
35
|
-
} = await
|
|
28
|
+
} = await resolvePaths(logger, cwd, coordinates);
|
|
36
29
|
if (featurePaths.length === 0) {
|
|
37
30
|
return {
|
|
38
31
|
filteredPickles: [],
|
|
@@ -42,7 +35,7 @@ async function loadSources(coordinates, environment = {}) {
|
|
|
42
35
|
const {
|
|
43
36
|
filteredPickles,
|
|
44
37
|
parseErrors
|
|
45
|
-
} = await
|
|
38
|
+
} = await getFilteredPicklesAndErrors({
|
|
46
39
|
newId,
|
|
47
40
|
cwd,
|
|
48
41
|
logger,
|