@zohodesk/testinglibrary 0.0.5 → 0.0.7
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 +19 -0
- package/.eslintrc.js +27 -0
- package/.prettierrc +6 -0
- package/{changelog.md → Changelog.md} +42 -25
- package/README.md +17 -17
- package/bin/cli.js +2 -2
- package/bin/postinstall.js +1 -16
- package/build/bdd-framework/cli/commands/env.js +43 -0
- package/build/bdd-framework/cli/commands/export.js +48 -0
- package/build/bdd-framework/cli/commands/test.js +59 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +20 -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 +91 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
- package/build/bdd-framework/cucumber/gherkin.d.js +5 -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 +57 -0
- package/build/bdd-framework/cucumber/loadSteps.js +35 -0
- package/build/bdd-framework/decorators.js +22 -0
- package/build/bdd-framework/gen/formatter.js +88 -0
- package/build/bdd-framework/gen/i18n.js +35 -0
- package/build/bdd-framework/gen/index.js +160 -0
- package/build/bdd-framework/gen/poms.js +46 -0
- package/build/bdd-framework/gen/testFile.js +356 -0
- package/build/bdd-framework/gen/testNode.js +48 -0
- package/build/bdd-framework/gen/testPoms.js +123 -0
- package/build/bdd-framework/index.js +45 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +77 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +46 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +41 -0
- package/build/bdd-framework/playwright/transform.js +80 -0
- package/build/bdd-framework/playwright/types.js +5 -0
- package/build/bdd-framework/playwright/utils.js +34 -0
- package/build/bdd-framework/run/bddFixtures.js +108 -0
- package/build/bdd-framework/run/bddWorld.js +87 -0
- package/build/bdd-framework/snippets/index.js +131 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +41 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +49 -0
- package/build/bdd-framework/stepDefinitions/createDecorators.js +109 -0
- package/build/bdd-framework/stepDefinitions/decorators/poms.js +50 -0
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +94 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +61 -0
- package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
- package/build/bdd-framework/utils/index.js +50 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +29 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
- package/{src → build}/core/jest/runner/jest-runner.js +46 -44
- package/build/core/jest/setup/index.js +9 -0
- package/build/core/playwright/codegen.js +55 -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 +112 -82
- package/build/core/playwright/readConfigFile.js +69 -0
- package/build/core/playwright/report-generator.js +41 -0
- package/build/core/playwright/setup/config-creator.js +117 -0
- package/build/core/playwright/test-runner.js +132 -0
- package/build/decorators.d.ts +1 -0
- package/build/decorators.js +16 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +59 -0
- package/build/lib/cli.js +54 -0
- package/build/lib/post-install.js +17 -0
- package/build/lint/index.js +4 -0
- package/build/parser/parser.js +206 -0
- package/build/parser/sample.feature +34 -0
- package/build/parser/sample.spec.js +37 -0
- package/build/parser/verifier.js +130 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -0
- package/build/setup-folder-structure/samples/authUsers-sample.json +9 -0
- package/build/setup-folder-structure/samples/env-config-sample.json +21 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +33 -0
- package/build/setup-folder-structure/samples/uat-config-sample.js +35 -0
- package/build/setup-folder-structure/setupProject.js +100 -0
- package/{src → build}/utils/cliArgsToObject.js +65 -63
- package/build/utils/fileUtils.js +53 -0
- package/build/utils/getFilePath.js +11 -0
- package/build/utils/logger.js +58 -0
- package/build/utils/rootPath.js +46 -0
- package/build/utils/stepDefinitionsFormatter.js +12 -0
- package/jest.config.js +63 -63
- package/npm-shrinkwrap.json +8790 -5772
- package/package.json +53 -30
- package/playwright.config.js +112 -112
- 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 -63
- package/src/core/playwright/report-generator.js +0 -45
- package/src/core/playwright/setup/config-creator.js +0 -77
- package/src/core/playwright/test-runner.js +0 -67
- package/src/index.js +0 -9
- package/src/lib/cli.js +0 -42
- package/src/setup-folder-structure/env-config-sample.json +0 -17
- package/src/setup-folder-structure/setupProject.js +0 -99
- package/src/setup-folder-structure/uat-config-sample.js +0 -22
- package/src/setup-folder-structure/user-example.json +0 -3
- package/src/utils/getFilePath.js +0 -9
- package/src/utils/logger.js +0 -28
- package/src/utils/rootPath.js +0 -51
package/.babelrc
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
[
|
|
4
|
+
"@babel/preset-env",
|
|
5
|
+
{
|
|
6
|
+
"targets": {
|
|
7
|
+
"node": "14"
|
|
8
|
+
},
|
|
9
|
+
"exclude": ["@babel/plugin-transform-destructuring"]
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
],
|
|
13
|
+
"plugins": [
|
|
14
|
+
["@babel/plugin-transform-runtime"]
|
|
15
|
+
],
|
|
16
|
+
"ignore": [
|
|
17
|
+
"./src/setup-folder-structure/samples"
|
|
18
|
+
]
|
|
19
|
+
}
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": "eslint:recommended",
|
|
7
|
+
"overrides": [
|
|
8
|
+
{
|
|
9
|
+
"env": {
|
|
10
|
+
"node": true
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
".eslintrc.{js,cjs}"
|
|
14
|
+
],
|
|
15
|
+
"parserOptions": {
|
|
16
|
+
"sourceType": "script"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"parserOptions": {
|
|
21
|
+
"ecmaVersion": "latest",
|
|
22
|
+
"sourceType": "module"
|
|
23
|
+
},
|
|
24
|
+
"rules": {
|
|
25
|
+
"indent": ["error", 2]
|
|
26
|
+
}
|
|
27
|
+
}
|
package/.prettierrc
ADDED
|
@@ -1,25 +1,42 @@
|
|
|
1
|
-
# Testing Framework
|
|
2
|
-
|
|
3
|
-
## Framework that abstracts the configuration for playwright and Jest
|
|
4
|
-
|
|
5
|
-
# 0.0.
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
1
|
+
# Testing Framework
|
|
2
|
+
|
|
3
|
+
## Framework that abstracts the configuration for playwright and Jest
|
|
4
|
+
|
|
5
|
+
# 0.0.7
|
|
6
|
+
|
|
7
|
+
- Removed react and react-dom as dependencies. Added this as peer dependency
|
|
8
|
+
|
|
9
|
+
# 0.0.6
|
|
10
|
+
|
|
11
|
+
## Provided Initial Support for cucumber feature files
|
|
12
|
+
|
|
13
|
+
- Playwright-bdd and cucumber added as dependencies
|
|
14
|
+
- Added config bddMode which toggles the feature files processing
|
|
15
|
+
- Added expect timeout and test timeout as an option
|
|
16
|
+
- Decorators support for given, when and then. Typescript support needed to use this feature
|
|
17
|
+
|
|
18
|
+
## Internal Library change
|
|
19
|
+
|
|
20
|
+
- Provided support for import/export statements
|
|
21
|
+
|
|
22
|
+
# 0.0.5
|
|
23
|
+
|
|
24
|
+
- Added Init command to initialize the folder structure and configuration for testing
|
|
25
|
+
- Renamed config.json to env-config.json
|
|
26
|
+
- Configured report file path directory and Handled Edge case in Cookies Handling
|
|
27
|
+
|
|
28
|
+
# 0.0.4
|
|
29
|
+
|
|
30
|
+
- Issue Fixes while loading the storage state
|
|
31
|
+
|
|
32
|
+
# 0.0.3
|
|
33
|
+
|
|
34
|
+
- Added Support for custom config generator based on user preferences
|
|
35
|
+
|
|
36
|
+
# 0.0.2
|
|
37
|
+
|
|
38
|
+
- Fix for Finding directories inside node_modules folder
|
|
39
|
+
|
|
40
|
+
# 0.0.1
|
|
41
|
+
|
|
42
|
+
- test and report command support
|
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# Testing Framework
|
|
2
|
-
|
|
3
|
-
## Framework that abstracts the configuration for playwright and Jest
|
|
4
|
-
|
|
5
|
-
- Playwright
|
|
6
|
-
- Jest
|
|
7
|
-
|
|
8
|
-
## Cli
|
|
9
|
-
|
|
10
|
-
## Feature Supported
|
|
11
|
-
|
|
12
|
-
### Run TestCase
|
|
13
|
-
|
|
14
|
-
- npm run test
|
|
15
|
-
### Generate Report
|
|
16
|
-
|
|
17
|
-
- npm run report
|
|
1
|
+
# Testing Framework
|
|
2
|
+
|
|
3
|
+
## Framework that abstracts the configuration for playwright and Jest
|
|
4
|
+
|
|
5
|
+
- Playwright
|
|
6
|
+
- Jest
|
|
7
|
+
|
|
8
|
+
## Cli
|
|
9
|
+
|
|
10
|
+
## Feature Supported
|
|
11
|
+
|
|
12
|
+
### Run TestCase
|
|
13
|
+
|
|
14
|
+
- npm run test
|
|
15
|
+
### Generate Report
|
|
16
|
+
|
|
17
|
+
- npm run report
|
|
18
18
|
|
package/bin/cli.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
require('../
|
|
2
|
+
|
|
3
|
+
require('../build/lib/cli');
|
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,43 @@
|
|
|
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 _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({
|
|
16
|
+
verbose: true
|
|
17
|
+
});
|
|
18
|
+
const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
19
|
+
logger.log(`Playwright-bdd environment info:\n`);
|
|
20
|
+
logger.log(`platform: ${process.platform}`);
|
|
21
|
+
logger.log(`node: ${process.version}`);
|
|
22
|
+
showPackageVersion('playwright-bdd');
|
|
23
|
+
showPackageVersion('@playwright/test');
|
|
24
|
+
showPackageVersion('@cucumber/cucumber');
|
|
25
|
+
showPlaywrightConfigPath(opts.config);
|
|
26
|
+
});
|
|
27
|
+
exports.envCommand = envCommand;
|
|
28
|
+
function showPackageVersion(packageName) {
|
|
29
|
+
const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
30
|
+
logger.log(`${packageName}: v${version}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Getting own version by relative path instead of using getPackageVersion(),
|
|
34
|
+
* to aneble using directly from /dist in tests.
|
|
35
|
+
*/
|
|
36
|
+
function getOwnVersion() {
|
|
37
|
+
return '5.3.0';
|
|
38
|
+
}
|
|
39
|
+
function showPlaywrightConfigPath(cliConfigPath) {
|
|
40
|
+
const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
41
|
+
const relPath = _path.default.relative(process.cwd(), resolvedConfigFile);
|
|
42
|
+
logger.log(`Playwright config file: ${relPath}`);
|
|
43
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const logger = new _logger.Logger({
|
|
17
|
+
verbose: true
|
|
18
|
+
});
|
|
19
|
+
const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
20
|
+
const {
|
|
21
|
+
resolvedConfigFile
|
|
22
|
+
} = await (0, _loadConfig.loadConfig)(opts.config);
|
|
23
|
+
logger.log(`List of all steps found by config: ${_path.default.relative(process.cwd(), resolvedConfigFile)}\n`);
|
|
24
|
+
const configs = Object.values((0, _env.getEnvConfigs)());
|
|
25
|
+
(0, _test.assertConfigsCount)(configs);
|
|
26
|
+
await showStepsForConfigs(configs);
|
|
27
|
+
});
|
|
28
|
+
exports.exportCommand = exportCommand;
|
|
29
|
+
async function showStepsForConfigs(configs) {
|
|
30
|
+
// here we don't need workers (as in test command) because if some step files
|
|
31
|
+
// are already in node cache, we collected them.
|
|
32
|
+
const steps = new Set();
|
|
33
|
+
const tasks = configs.map(async config => {
|
|
34
|
+
const stepDefinitions = await new _gen.TestFilesGenerator(config).extractSteps();
|
|
35
|
+
stepDefinitions.forEach(s => steps.add(`* ${getStepText(s)}`));
|
|
36
|
+
});
|
|
37
|
+
await Promise.all(tasks);
|
|
38
|
+
steps.forEach(stepText => logger.log(stepText));
|
|
39
|
+
}
|
|
40
|
+
function getStepText({
|
|
41
|
+
pattern,
|
|
42
|
+
keyword
|
|
43
|
+
}) {
|
|
44
|
+
// for Unknown return When as it looks the most suitable
|
|
45
|
+
const keywordText = keyword === 'Unknown' ? 'When' : keyword;
|
|
46
|
+
const patternText = typeof pattern === 'string' ? pattern : pattern.source;
|
|
47
|
+
return `${keywordText} ${patternText}`;
|
|
48
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.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 generateFilesForConfigs(configs, cliConfig) {
|
|
40
|
+
// run first config in main thread and other in workers (to have fresh require cache)
|
|
41
|
+
// See: https://github.com/vitalets/playwright-bdd/issues/32
|
|
42
|
+
const tasks = configs.map((config, index) => {
|
|
43
|
+
const finalConfig = {
|
|
44
|
+
...config,
|
|
45
|
+
...cliConfig
|
|
46
|
+
};
|
|
47
|
+
return index === 0 ? new _gen.TestFilesGenerator(finalConfig).generate() : runInWorker(finalConfig);
|
|
48
|
+
});
|
|
49
|
+
return Promise.all(tasks);
|
|
50
|
+
}
|
|
51
|
+
async function runInWorker(config) {
|
|
52
|
+
const worker = new _worker_threads.Worker(GEN_WORKER_PATH, {
|
|
53
|
+
workerData: {
|
|
54
|
+
config
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// todo: check if worker exited with error?
|
|
58
|
+
await (0, _events.once)(worker, 'exit');
|
|
59
|
+
}
|
|
@@ -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,20 @@
|
|
|
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
|
+
* Helper used in test run to detect config location.
|
|
16
|
+
*/
|
|
17
|
+
exports.configOption = configOption;
|
|
18
|
+
function getCliConfigPath() {
|
|
19
|
+
return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
20
|
+
}
|
|
@@ -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,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 _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
|
+
// In main process store config in env to be accessible by workers
|
|
29
|
+
if (!process.env.TEST_WORKER_INDEX) {
|
|
30
|
+
(0, _env.saveConfigToEnv)(config);
|
|
31
|
+
}
|
|
32
|
+
return config.outputDir;
|
|
33
|
+
}
|
|
34
|
+
function getConfig(inputConfig) {
|
|
35
|
+
const config = Object.assign({}, defaults, inputConfig);
|
|
36
|
+
const configDir = (0, _dir.getPlaywrightConfigDir)();
|
|
37
|
+
const featuresRoot = config.featuresRoot ? _path.default.resolve(configDir, config.featuresRoot) : configDir;
|
|
38
|
+
return {
|
|
39
|
+
...config,
|
|
40
|
+
// important to resolve outputDir as it is used as unique key for input configs
|
|
41
|
+
outputDir: _path.default.resolve(configDir, config.outputDir),
|
|
42
|
+
importTestFrom: resolveImportTestFrom(configDir, config.importTestFrom),
|
|
43
|
+
featuresRoot
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function extractCucumberConfig(config) {
|
|
47
|
+
// todo: find more strict way to omit own config fields
|
|
48
|
+
// see: https://bobbyhadz.com/blog/typescript-object-remove-property
|
|
49
|
+
const omitProps = {
|
|
50
|
+
outputDir: true,
|
|
51
|
+
importTestFrom: true,
|
|
52
|
+
verbose: true,
|
|
53
|
+
skip: true,
|
|
54
|
+
examplesTitleFormat: true,
|
|
55
|
+
quotes: true,
|
|
56
|
+
tags: true,
|
|
57
|
+
featuresRoot: true
|
|
58
|
+
};
|
|
59
|
+
const keys = Object.keys(omitProps);
|
|
60
|
+
const cucumberConfig = {
|
|
61
|
+
...config
|
|
62
|
+
};
|
|
63
|
+
keys.forEach(key => delete cucumberConfig[key]);
|
|
64
|
+
stripPublishQuiet(cucumberConfig);
|
|
65
|
+
return cucumberConfig;
|
|
66
|
+
}
|
|
67
|
+
function resolveImportTestFrom(configDir, importTestFrom) {
|
|
68
|
+
if (importTestFrom) {
|
|
69
|
+
const {
|
|
70
|
+
file,
|
|
71
|
+
varName
|
|
72
|
+
} = typeof importTestFrom === 'string' ? {
|
|
73
|
+
file: importTestFrom
|
|
74
|
+
} : importTestFrom;
|
|
75
|
+
return {
|
|
76
|
+
file: _path.default.resolve(configDir, file),
|
|
77
|
+
varName
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function stripPublishQuiet(cucumberConfig) {
|
|
82
|
+
const 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,43 @@
|
|
|
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
|
+
// skip wrapping code as it is not needed for decorator steps
|
|
28
|
+
// const wrappedCode = this.wrapCode({
|
|
29
|
+
// code,
|
|
30
|
+
// wrapperOptions: options.wrapperOptions,
|
|
31
|
+
// })
|
|
32
|
+
return new _step_definition.default({
|
|
33
|
+
code,
|
|
34
|
+
expression,
|
|
35
|
+
id: newId(),
|
|
36
|
+
line,
|
|
37
|
+
options,
|
|
38
|
+
keyword,
|
|
39
|
+
pattern,
|
|
40
|
+
unwrappedCode: code,
|
|
41
|
+
uri
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -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
|
+
}
|