@zohodesk/testinglibrary 0.1.8-exp-bdd-v2 → 0.1.8-exp-bdd-v4
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/.eslintrc.js +5 -1
- package/build/bdd-framework/cli/commands/env.js +2 -3
- package/build/bdd-framework/cli/commands/export.js +1 -2
- package/build/bdd-framework/cli/commands/test.js +7 -4
- package/build/bdd-framework/cli/options.js +1 -2
- package/build/bdd-framework/config/env.js +2 -1
- package/build/bdd-framework/config/index.js +1 -2
- package/build/bdd-framework/config/lang.js +14 -0
- package/build/bdd-framework/cucumber/loadSteps.js +8 -3
- package/build/bdd-framework/decorators.js +6 -10
- package/build/bdd-framework/gen/fixtures.js +48 -0
- package/build/bdd-framework/gen/formatter.js +57 -10
- package/build/bdd-framework/gen/i18n.js +6 -2
- package/build/bdd-framework/gen/index.js +7 -6
- package/build/bdd-framework/gen/testFile.js +105 -39
- package/build/bdd-framework/gen/testNode.js +16 -3
- package/build/bdd-framework/gen/testPoms.js +18 -8
- package/build/bdd-framework/hooks/scenario.js +107 -0
- package/build/bdd-framework/hooks/worker.js +83 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +24 -8
- package/build/bdd-framework/playwright/getLocationInFile.js +13 -7
- package/build/bdd-framework/playwright/testTypeImpl.js +11 -7
- package/build/bdd-framework/playwright/transform.js +6 -2
- package/build/bdd-framework/playwright/utils.js +1 -4
- package/build/bdd-framework/run/StepInvoker.js +73 -0
- package/build/bdd-framework/run/bddFixtures.js +119 -57
- package/build/bdd-framework/run/bddWorld.js +24 -36
- package/build/bdd-framework/snippets/index.js +3 -2
- package/build/bdd-framework/snippets/snippetSyntax.js +3 -1
- package/build/bdd-framework/stepDefinitions/createBdd.js +28 -11
- package/build/bdd-framework/stepDefinitions/decorators/{poms.js → class.js} +7 -3
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +8 -3
- package/build/bdd-framework/stepDefinitions/defineStep.js +2 -1
- package/build/bdd-framework/utils/exit.js +8 -4
- package/build/bdd-framework/utils/index.js +27 -1
- package/build/bdd-framework/utils/logger.js +4 -3
- package/build/bdd-poc/core-runner/main.js +10 -0
- package/build/bdd-poc/core-runner/stepDefinitions.js +0 -1
- package/build/bdd-poc/index.js +26 -0
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +6 -6
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +1 -2
- package/build/bdd-poc/test/testDataMap.js +5 -5
- package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
- package/build/core/playwright/builtInFixtures/addTags.js +19 -0
- package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
- package/build/core/playwright/builtInFixtures/context.js +15 -0
- package/build/core/playwright/builtInFixtures/index.js +26 -0
- package/build/core/playwright/builtInFixtures/page.js +51 -0
- package/build/core/playwright/clear-caches.js +29 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/index.js +12 -93
- package/build/core/playwright/readConfigFile.js +12 -6
- package/build/core/playwright/report-generator.js +2 -1
- package/build/core/playwright/setup/config-creator.js +23 -17
- package/build/core/playwright/setup/config-utils.js +43 -11
- package/build/core/playwright/setup/custom-reporter.js +109 -0
- package/build/core/playwright/tag-processor.js +68 -0
- package/build/core/playwright/test-runner.js +40 -36
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +2 -16
- package/build/index.d.ts +59 -4
- package/build/index.js +10 -9
- package/build/lib/cli.js +10 -1
- package/build/parser/parser.js +0 -1
- package/build/setup-folder-structure/helper.js +34 -0
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
- package/build/setup-folder-structure/samples/uat-config-sample.js +3 -2
- package/build/setup-folder-structure/setupProject.js +10 -5
- package/build/utils/fileUtils.js +15 -4
- package/build/utils/logger.js +1 -2
- package/build/utils/stepDefinitionsFormatter.js +1 -2
- package/changelog.md +57 -0
- package/npm-shrinkwrap.json +1426 -2172
- package/package.json +5 -4
- package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
- package/build/bdd-framework/gen/poms.js +0 -46
- package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -109
- package/build/bdd-poc/main.js +0 -10
- /package/build/bdd-poc/{runner.js → core-runner/runner.js} +0 -0
package/.eslintrc.js
CHANGED
|
@@ -22,6 +22,10 @@ module.exports = {
|
|
|
22
22
|
"sourceType": "module"
|
|
23
23
|
},
|
|
24
24
|
"rules": {
|
|
25
|
-
"indent": ["error", 2]
|
|
25
|
+
"indent": ["error", 2, { "SwitchCase": 1 }],
|
|
26
|
+
"no-empty-pattern": "off",
|
|
27
|
+
"comma-dangle": ["error", "never"],
|
|
28
|
+
"curly": ["error"],
|
|
29
|
+
"brace-style": "error"
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -15,7 +15,7 @@ var _loadConfig = require("../../playwright/loadConfig");
|
|
|
15
15
|
const logger = new _logger.Logger({
|
|
16
16
|
verbose: true
|
|
17
17
|
});
|
|
18
|
-
const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
18
|
+
const envCommand = exports.envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
19
19
|
logger.log(`Playwright-bdd environment info:\n`);
|
|
20
20
|
logger.log(`platform: ${process.platform}`);
|
|
21
21
|
logger.log(`node: ${process.version}`);
|
|
@@ -24,7 +24,6 @@ const envCommand = new _commander.Command('env').description('Prints environment
|
|
|
24
24
|
showPackageVersion('@cucumber/cucumber');
|
|
25
25
|
showPlaywrightConfigPath(opts.config);
|
|
26
26
|
});
|
|
27
|
-
exports.envCommand = envCommand;
|
|
28
27
|
function showPackageVersion(packageName) {
|
|
29
28
|
const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
30
29
|
logger.log(`${packageName}: v${version}`);
|
|
@@ -34,7 +33,7 @@ function showPackageVersion(packageName) {
|
|
|
34
33
|
* to aneble using directly from /dist in tests.
|
|
35
34
|
*/
|
|
36
35
|
function getOwnVersion() {
|
|
37
|
-
return '5.
|
|
36
|
+
return '5.6.0';
|
|
38
37
|
}
|
|
39
38
|
function showPlaywrightConfigPath(cliConfigPath) {
|
|
40
39
|
const resolvedConfigFile = (0, _loadConfig.resolveConfigFile)(cliConfigPath);
|
|
@@ -16,7 +16,7 @@ var _gen = require("../../gen");
|
|
|
16
16
|
const logger = new _logger.Logger({
|
|
17
17
|
verbose: true
|
|
18
18
|
});
|
|
19
|
-
const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
19
|
+
const exportCommand = exports.exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
20
20
|
const {
|
|
21
21
|
resolvedConfigFile
|
|
22
22
|
} = await (0, _loadConfig.loadConfig)(opts.config);
|
|
@@ -25,7 +25,6 @@ const exportCommand = new _commander.Command('export').description('Prints all s
|
|
|
25
25
|
(0, _test.assertConfigsCount)(configs);
|
|
26
26
|
await showStepsForConfigs(configs);
|
|
27
27
|
});
|
|
28
|
-
exports.exportCommand = exportCommand;
|
|
29
28
|
async function showStepsForConfigs(configs) {
|
|
30
29
|
// here we don't need workers (as in test command) because if some step files
|
|
31
30
|
// are already in node cache, we collected them.
|
|
@@ -17,13 +17,12 @@ var _config = require("../../config");
|
|
|
17
17
|
var _options = require("../options");
|
|
18
18
|
var _exit = require("../../utils/exit");
|
|
19
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 => {
|
|
20
|
+
const testCommand = exports.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
21
|
await (0, _loadConfig.loadConfig)(opts.config);
|
|
22
22
|
const configs = readConfigsFromEnv();
|
|
23
23
|
mergeCliOptions(configs, opts);
|
|
24
24
|
await generateFilesForConfigs(configs);
|
|
25
25
|
});
|
|
26
|
-
exports.testCommand = testCommand;
|
|
27
26
|
function readConfigsFromEnv() {
|
|
28
27
|
const configs = Object.values((0, _env.getEnvConfigs)());
|
|
29
28
|
assertConfigsCount(configs);
|
|
@@ -31,8 +30,12 @@ function readConfigsFromEnv() {
|
|
|
31
30
|
}
|
|
32
31
|
function mergeCliOptions(configs, opts) {
|
|
33
32
|
configs.forEach(config => {
|
|
34
|
-
if ('tags' in opts)
|
|
35
|
-
|
|
33
|
+
if ('tags' in opts) {
|
|
34
|
+
config.tags = opts.tags;
|
|
35
|
+
}
|
|
36
|
+
if ('verbose' in opts) {
|
|
37
|
+
config.verbose = Boolean(opts.verbose);
|
|
38
|
+
}
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
function assertConfigsCount(configs) {
|
|
@@ -10,11 +10,10 @@ var _commander = require("commander");
|
|
|
10
10
|
* Config option moved to separate file as it used in test run.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
13
|
+
const configOption = exports.configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
14
14
|
/**
|
|
15
15
|
* Helper used in test run to detect config location.
|
|
16
16
|
*/
|
|
17
|
-
exports.configOption = configOption;
|
|
18
17
|
function getCliConfigPath() {
|
|
19
18
|
return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
20
19
|
}
|
|
@@ -34,7 +34,8 @@ function getConfigFromEnv(outputDir) {
|
|
|
34
34
|
outputDir = _path.default.resolve(outputDir);
|
|
35
35
|
const config = envConfigs[outputDir];
|
|
36
36
|
if (!config) {
|
|
37
|
-
|
|
37
|
+
// exit(`Config not found for outputDir: "${outputDir}".`, `Available dirs: ${Object.keys(envConfigs).join('\n')}`);
|
|
38
|
+
return {};
|
|
38
39
|
}
|
|
39
40
|
return config;
|
|
40
41
|
}
|
|
@@ -15,14 +15,13 @@ var _utils = require("../utils");
|
|
|
15
15
|
* BDD Config.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const defaults = {
|
|
18
|
+
const defaults = exports.defaults = {
|
|
19
19
|
outputDir: '.features-gen',
|
|
20
20
|
verbose: false,
|
|
21
21
|
examplesTitleFormat: 'Example #<_index_>',
|
|
22
22
|
publishQuiet: true,
|
|
23
23
|
quotes: 'double'
|
|
24
24
|
};
|
|
25
|
-
exports.defaults = defaults;
|
|
26
25
|
function defineBddConfig(inputConfig) {
|
|
27
26
|
const config = getConfig(inputConfig);
|
|
28
27
|
// In main process store config in env to be accessible by workers
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LANG_EN = void 0;
|
|
7
|
+
exports.isEnglish = isEnglish;
|
|
8
|
+
/**
|
|
9
|
+
* Helpers for Cucumber language option.
|
|
10
|
+
*/
|
|
11
|
+
const LANG_EN = exports.LANG_EN = 'en';
|
|
12
|
+
function isEnglish(lang) {
|
|
13
|
+
return !lang || lang === LANG_EN;
|
|
14
|
+
}
|
|
@@ -25,9 +25,14 @@ function findStepDefinition(supportCodeLibrary, stepText, file) {
|
|
|
25
25
|
const matchedSteps = supportCodeLibrary.stepDefinitions.filter(step => {
|
|
26
26
|
return step.matchesStepName(stepText);
|
|
27
27
|
});
|
|
28
|
-
if (matchedSteps.length === 0)
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (matchedSteps.length === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (matchedSteps.length > 1) {
|
|
32
|
+
(0, _exit.exit)([`Multiple step definitions matched for text: "${stepText}" (${file})`,
|
|
33
|
+
// todo: print location of every step definition (as in cucumber)
|
|
34
|
+
...matchedSteps.map(s => ` ${s.pattern}`)].join('\n'));
|
|
35
|
+
}
|
|
31
36
|
return matchedSteps[0];
|
|
32
37
|
}
|
|
33
38
|
function hasTsNodeRegister(runConfiguration) {
|
|
@@ -6,17 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "Fixture", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _class.Fixture;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
exports.When = exports.Then = exports.Step = exports.Given = void 0;
|
|
13
|
-
var
|
|
13
|
+
var _class = require("./stepDefinitions/decorators/class");
|
|
14
14
|
var _steps = require("./stepDefinitions/decorators/steps");
|
|
15
|
-
const Given = (0, _steps.createStepDecorator)('Given');
|
|
16
|
-
exports.
|
|
17
|
-
const
|
|
18
|
-
exports.
|
|
19
|
-
const Then = (0, _steps.createStepDecorator)('Then');
|
|
20
|
-
exports.Then = Then;
|
|
21
|
-
const Step = (0, _steps.createStepDecorator)('Unknown');
|
|
22
|
-
exports.Step = Step;
|
|
15
|
+
const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
|
|
16
|
+
const When = exports.When = (0, _steps.createStepDecorator)('When');
|
|
17
|
+
const Then = exports.Then = (0, _steps.createStepDecorator)('Then');
|
|
18
|
+
const Step = exports.Step = (0, _steps.createStepDecorator)('Unknown');
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractFixtureNames = extractFixtureNames;
|
|
7
|
+
exports.extractFixtureNamesFromFnBodyMemo = extractFixtureNamesFromFnBodyMemo;
|
|
8
|
+
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
9
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
10
|
+
var _exit = require("../utils/exit");
|
|
11
|
+
const bodyFixturesSymbol = Symbol('bodyFixtures');
|
|
12
|
+
/**
|
|
13
|
+
* This function is used for playwright-style steps and decorators.
|
|
14
|
+
* It extracts fixtures names from first parameter of function
|
|
15
|
+
* using Playwright's helper.
|
|
16
|
+
*/
|
|
17
|
+
function extractFixtureNames(fn) {
|
|
18
|
+
return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* This function is used for cucumber-style steps.
|
|
22
|
+
* It looks for `this.useFixture('xxx')` entries in function body
|
|
23
|
+
* and extracts fixtures names from it.
|
|
24
|
+
*/
|
|
25
|
+
function extractFixtureNamesFromFnBodyMemo(fn) {
|
|
26
|
+
if (typeof fn !== 'function') {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const fnWithFixtures = fn;
|
|
30
|
+
if (!fnWithFixtures[bodyFixturesSymbol]) {
|
|
31
|
+
fnWithFixtures[bodyFixturesSymbol] = extractFixtureNamesFromFnBody(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
|
|
32
|
+
}
|
|
33
|
+
return fnWithFixtures[bodyFixturesSymbol];
|
|
34
|
+
}
|
|
35
|
+
function extractFixtureNamesFromFnBody(fn) {
|
|
36
|
+
const matches = fn.toString().matchAll(/this\.useFixture\((.+)\)/gi) || [];
|
|
37
|
+
return [...matches].map(match => getFixtureName(match[1]));
|
|
38
|
+
}
|
|
39
|
+
function getFixtureName(arg) {
|
|
40
|
+
if (!/^['"`]/.test(arg)) {
|
|
41
|
+
// todo: log file location with incorrect useFixture
|
|
42
|
+
(0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
|
|
43
|
+
}
|
|
44
|
+
if (arg.startsWith('`') && arg.includes('${')) {
|
|
45
|
+
(0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
|
|
46
|
+
}
|
|
47
|
+
return arg.replace(/['"`]/g, '');
|
|
48
|
+
}
|
|
@@ -18,14 +18,20 @@ class Formatter {
|
|
|
18
18
|
fileHeader(uri, importTestFrom) {
|
|
19
19
|
const file = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary';
|
|
20
20
|
let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
|
|
21
|
-
if (varName !== 'test')
|
|
21
|
+
if (varName !== 'test') {
|
|
22
|
+
varName = `${varName} as test`;
|
|
23
|
+
}
|
|
22
24
|
return [`/** Generated from: ${uri} */`,
|
|
25
|
+
// prettier-ignore
|
|
23
26
|
// this.quoted() is not possible for 'import from' as backticks not parsed
|
|
24
27
|
`import { ${varName} } from ${JSON.stringify(file)};`, ''];
|
|
25
28
|
}
|
|
26
29
|
suite(node, children) {
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
const firstLine = `test.describe${this.getSubFn(node)}(${this.quoted(node.title)}, () => {`;
|
|
31
|
+
if (!children.length) {
|
|
32
|
+
return [`${firstLine}});`, ''];
|
|
33
|
+
}
|
|
34
|
+
return [firstLine, '', ...children.map(indent), `});`, ''];
|
|
29
35
|
}
|
|
30
36
|
beforeEach(fixtures, children) {
|
|
31
37
|
const fixturesStr = [...fixtures].join(', ');
|
|
@@ -34,8 +40,12 @@ class Formatter {
|
|
|
34
40
|
}
|
|
35
41
|
test(node, fixtures, children) {
|
|
36
42
|
const fixturesStr = [...fixtures].join(', ');
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
const title = this.quoted([node.title, ...node.tags].join(' '));
|
|
44
|
+
const firstLine = `test${this.getSubFn(node)}(${title}, async ({ ${fixturesStr} }) => {`;
|
|
45
|
+
if (!children.length) {
|
|
46
|
+
return [`${firstLine}});`, ''];
|
|
47
|
+
}
|
|
48
|
+
return [firstLine, ...children.map(indent), `});`, ''];
|
|
39
49
|
}
|
|
40
50
|
// eslint-disable-next-line max-params
|
|
41
51
|
step(keyword, text, argument, fixtureNames = []) {
|
|
@@ -49,25 +59,62 @@ class Formatter {
|
|
|
49
59
|
return `// missing step: ${keyword}(${this.quoted(text)});`;
|
|
50
60
|
}
|
|
51
61
|
useFixtures(fixtures) {
|
|
52
|
-
return fixtures.length > 0 ? ['// == technical section ==',
|
|
62
|
+
return fixtures.length > 0 ? ['// == technical section ==',
|
|
63
|
+
// prettier-ignore
|
|
64
|
+
'', 'test.use({', ...fixtures.map(indent), '});'] : [];
|
|
53
65
|
}
|
|
54
66
|
testFixture() {
|
|
55
67
|
return ['$test: ({}, use) => use(test),'];
|
|
56
68
|
}
|
|
69
|
+
bddWorldFixtures() {
|
|
70
|
+
const fixturesObj = {
|
|
71
|
+
page: null,
|
|
72
|
+
context: null,
|
|
73
|
+
browser: null,
|
|
74
|
+
browserName: null,
|
|
75
|
+
request: null
|
|
76
|
+
};
|
|
77
|
+
const fixtures = Object.keys(fixturesObj).join(', ');
|
|
78
|
+
return [`$bddWorldFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
|
|
79
|
+
}
|
|
57
80
|
tagsFixture(testNodes) {
|
|
58
81
|
const lines = testNodes.filter(node => node.tags.length).map(node => {
|
|
59
82
|
// remove first parent as it is the same for all tests: root suite
|
|
60
|
-
const key = node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR)
|
|
83
|
+
const key = `${node.titlePath.slice(1).join(TAGS_FIXTURE_TEST_KEY_SEPARATOR)} ${node.tags.join(" ")}`;
|
|
61
84
|
return `${JSON.stringify(key)}: ${JSON.stringify(node.tags)},`;
|
|
62
85
|
});
|
|
63
86
|
return lines.length > 0 ? ['$tags: ({}, use, testInfo) => use({', ...lines.map(indent),
|
|
64
87
|
// .slice(2) -> b/c we remove filename and root suite title
|
|
65
88
|
`}[testInfo.titlePath.slice(2).join(${JSON.stringify(TAGS_FIXTURE_TEST_KEY_SEPARATOR)})] || []),`] : [];
|
|
66
89
|
}
|
|
90
|
+
scenarioHookFixtures(fixtureNames) {
|
|
91
|
+
if (!fixtureNames.length) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const fixtures = fixtureNames.join(', ');
|
|
95
|
+
return [`$scenarioHookFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
|
|
96
|
+
}
|
|
97
|
+
workerHookFixtures(fixtureNames) {
|
|
98
|
+
if (!fixtureNames.length) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const fixtures = fixtureNames.join(', ');
|
|
102
|
+
const scope = this.quoted('worker');
|
|
103
|
+
return [`$workerHookFixtures: [({ ${fixtures} }, use) => use({ ${fixtures} }), { scope: ${scope} }],`];
|
|
104
|
+
}
|
|
105
|
+
langFixture(lang) {
|
|
106
|
+
return [`$lang: ({}, use) => use(${this.quoted(lang)}),`];
|
|
107
|
+
}
|
|
67
108
|
getSubFn(node) {
|
|
68
|
-
if (node.flags.only)
|
|
69
|
-
|
|
70
|
-
|
|
109
|
+
if (node.flags.only) {
|
|
110
|
+
return '.only';
|
|
111
|
+
}
|
|
112
|
+
if (node.flags.skip) {
|
|
113
|
+
return '.skip';
|
|
114
|
+
}
|
|
115
|
+
if (node.flags.fixme) {
|
|
116
|
+
return '.fixme';
|
|
117
|
+
}
|
|
71
118
|
return '';
|
|
72
119
|
}
|
|
73
120
|
/**
|
|
@@ -23,10 +23,14 @@ function getKeywordsMap(language) {
|
|
|
23
23
|
function handleKeyword(enKeyword, origMap, targetMap) {
|
|
24
24
|
const nativeKeywords = origMap[enKeyword];
|
|
25
25
|
// Array.isArray converts to any[]
|
|
26
|
-
if (typeof nativeKeywords === 'string')
|
|
26
|
+
if (typeof nativeKeywords === 'string') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
27
29
|
nativeKeywords.forEach(nativeKeyword => {
|
|
28
30
|
nativeKeyword = nativeKeyword.trim();
|
|
29
|
-
if (!nativeKeyword || nativeKeyword === '*')
|
|
31
|
+
if (!nativeKeyword || nativeKeyword === '*') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
30
34
|
targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
|
|
31
35
|
});
|
|
32
36
|
}
|
|
@@ -20,6 +20,7 @@ var _dir = require("../config/dir");
|
|
|
20
20
|
var _logger = require("../utils/logger");
|
|
21
21
|
var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
|
|
22
22
|
var _exit = require("../utils/exit");
|
|
23
|
+
var _createBdd = require("../stepDefinitions/createBdd");
|
|
23
24
|
/**
|
|
24
25
|
* Generate playwright test files from Gherkin documents.
|
|
25
26
|
*/
|
|
@@ -38,7 +39,9 @@ class TestFilesGenerator {
|
|
|
38
39
|
this.logger = new _logger.Logger({
|
|
39
40
|
verbose: config.verbose
|
|
40
41
|
});
|
|
41
|
-
if (config.tags)
|
|
42
|
+
if (config.tags) {
|
|
43
|
+
this.tagsExpression = (0, _tagExpressions.default)(config.tags);
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
async generate() {
|
|
44
47
|
await (0, _exit.withExitHandler)(async () => {
|
|
@@ -46,7 +49,7 @@ class TestFilesGenerator {
|
|
|
46
49
|
await Promise.all([this.loadFeatures(), this.loadSteps()]);
|
|
47
50
|
this.buildFiles();
|
|
48
51
|
await this.checkUndefinedSteps();
|
|
49
|
-
this.
|
|
52
|
+
this.checkImportTestFrom();
|
|
50
53
|
await this.clearOutputDir();
|
|
51
54
|
await this.saveFiles();
|
|
52
55
|
});
|
|
@@ -133,10 +136,8 @@ class TestFilesGenerator {
|
|
|
133
136
|
(0, _exit.exit)();
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
if (this.config.importTestFrom)
|
|
138
|
-
const hasCustomTest = this.files.some(file => file.hasCustomTest);
|
|
139
|
-
if (hasCustomTest) {
|
|
139
|
+
checkImportTestFrom() {
|
|
140
|
+
if (_createBdd.hasCustomTest && !this.config.importTestFrom) {
|
|
140
141
|
(0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
|
|
141
142
|
}
|
|
142
143
|
}
|