@zohodesk/testinglibrary 2.9.1 → 3.0.2
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/.gitlab-ci.yml +16 -23
- package/README.md +32 -1
- package/build/core/playwright/constants/fileMutexConfig.js +11 -0
- package/build/core/playwright/fixtures.js +24 -0
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +2 -8
- package/build/core/playwright/helpers/auth/loginSteps.js +25 -18
- package/build/core/playwright/helpers/checkAuthDirectory.js +17 -0
- package/build/core/playwright/helpers/fileMutex.js +58 -0
- package/build/core/playwright/index.js +10 -23
- package/build/core/playwright/setup/config-creator.js +3 -3
- package/build/core/playwright/setup/config-utils.js +8 -25
- package/build/core/playwright/test-runner.js +1 -1
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +1 -1
- package/build/setup-folder-structure/samples/actors-index.js +2 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
- package/build/setup-folder-structure/samples/editions-index.js +3 -0
- package/build/setup-folder-structure/samples/free-sample.json +25 -0
- package/build/setup-folder-structure/samples/settings.json +7 -0
- package/build/setup-folder-structure/setupProject.js +18 -5
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +94 -0
- package/nobdd/uat/conf/default/actors/index.js +1 -4
- package/nobdd/uat/conf/default/settings.json +1 -1
- package/nobdd/uat/conf/nobdd/uat.config.js +11 -4
- package/nobdd/uat/env-config.json +3 -3
- package/nobdd/uat/fixtures/setup.teardown.js +2 -1
- package/nobdd/uat/modules/nobdd/steps/VerifyNoBDD.feature.spec.js +3 -3
- package/nobdd/uat.config.js +8 -3
- package/package.json +8 -7
- package/build/bdd-framework/cli/commands/env.js +0 -42
- package/build/bdd-framework/cli/commands/export.js +0 -62
- package/build/bdd-framework/cli/commands/test.js +0 -64
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -19
- package/build/bdd-framework/cli/worker.js +0 -13
- package/build/bdd-framework/config/configDir.js +0 -35
- package/build/bdd-framework/config/enrichReporterData.js +0 -23
- package/build/bdd-framework/config/env.js +0 -50
- package/build/bdd-framework/config/index.js +0 -94
- package/build/bdd-framework/config/lang.js +0 -14
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
- package/build/bdd-framework/cucumber/createTestStep.js +0 -43
- package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
- package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
- package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
- package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
- package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
- package/build/bdd-framework/cucumber/formatter/index.js +0 -16
- package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
- package/build/bdd-framework/cucumber/loadConfig.js +0 -17
- package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
- package/build/bdd-framework/cucumber/loadSteps.js +0 -47
- package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
- package/build/bdd-framework/cucumber/stepArguments.js +0 -21
- package/build/bdd-framework/cucumber/types.js +0 -5
- package/build/bdd-framework/cucumber/valueChecker.js +0 -23
- package/build/bdd-framework/decorators.js +0 -18
- package/build/bdd-framework/gen/fixtures.js +0 -48
- package/build/bdd-framework/gen/formatter.js +0 -167
- package/build/bdd-framework/gen/i18n.js +0 -39
- package/build/bdd-framework/gen/index.js +0 -197
- package/build/bdd-framework/gen/specialTags.js +0 -70
- package/build/bdd-framework/gen/testFile.js +0 -470
- package/build/bdd-framework/gen/testMeta.js +0 -60
- package/build/bdd-framework/gen/testNode.js +0 -35
- package/build/bdd-framework/gen/testPoms.js +0 -133
- package/build/bdd-framework/hooks/scenario.js +0 -130
- package/build/bdd-framework/hooks/worker.js +0 -89
- package/build/bdd-framework/index.js +0 -52
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/loadUtils.js +0 -33
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
- package/build/bdd-framework/playwright/transform.js +0 -88
- package/build/bdd-framework/playwright/types.js +0 -12
- package/build/bdd-framework/playwright/utils.js +0 -56
- package/build/bdd-framework/reporter/cucumber/base.js +0 -52
- package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
- package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
- package/build/bdd-framework/reporter/cucumber/html.js +0 -40
- package/build/bdd-framework/reporter/cucumber/index.js +0 -74
- package/build/bdd-framework/reporter/cucumber/json.js +0 -312
- package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
- package/build/bdd-framework/reporter/cucumber/message.js +0 -20
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
- package/build/bdd-framework/run/StepInvoker.js +0 -69
- package/build/bdd-framework/run/bddData/index.js +0 -59
- package/build/bdd-framework/run/bddData/types.js +0 -5
- package/build/bdd-framework/run/bddFixtures.js +0 -192
- package/build/bdd-framework/run/bddWorld.js +0 -79
- package/build/bdd-framework/run/bddWorldInternal.js +0 -11
- package/build/bdd-framework/snippets/index.js +0 -132
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
- package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
- package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
- package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
- package/build/bdd-framework/steps/createBdd.js +0 -78
- package/build/bdd-framework/steps/decorators/class.js +0 -68
- package/build/bdd-framework/steps/decorators/steps.js +0 -98
- package/build/bdd-framework/steps/defineStep.js +0 -62
- package/build/bdd-framework/steps/stepConfig.js +0 -24
- package/build/bdd-framework/utils/AutofillMap.js +0 -20
- package/build/bdd-framework/utils/exit.js +0 -62
- package/build/bdd-framework/utils/index.js +0 -93
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -30
- package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
- package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
- package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
- package/nobdd/uat/conf/default/actors/beta/custom-module.json +0 -24
- package/nobdd/uat/conf/default/actors/beta/index.js +0 -6
- package/nobdd/uat/conf/default/actors/beta/parent-child.json +0 -24
- package/npm-shrinkwrap.json +0 -6475
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findStepDefinition = findStepDefinition;
|
|
7
|
-
exports.hasTsNodeRegister = hasTsNodeRegister;
|
|
8
|
-
exports.loadSteps = loadSteps;
|
|
9
|
-
var _api = require("@cucumber/cucumber/api");
|
|
10
|
-
var _transform = require("../playwright/transform");
|
|
11
|
-
var _exit = require("../utils/exit");
|
|
12
|
-
const cache = new Map();
|
|
13
|
-
async function loadSteps(runConfiguration, environment = {}) {
|
|
14
|
-
const cacheKey = JSON.stringify(runConfiguration);
|
|
15
|
-
let lib = cache.get(cacheKey);
|
|
16
|
-
if (!lib) {
|
|
17
|
-
// use Playwright's built-in hook to compile TypeScript steps
|
|
18
|
-
const uninstall = !hasTsNodeRegister(runConfiguration) ? (0, _transform.installTransform)() : () => {};
|
|
19
|
-
lib = (0, _api.loadSupport)(runConfiguration, environment).finally(() => uninstall());
|
|
20
|
-
cache.set(cacheKey, lib);
|
|
21
|
-
}
|
|
22
|
-
return lib;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Finds step definition by step text.
|
|
26
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/runtime/assemble_test_cases.ts#L103
|
|
27
|
-
*
|
|
28
|
-
* Handling case when several step definitions found:
|
|
29
|
-
* https://github.com/cucumber/cucumber-js/blob/main/src/runtime/test_case_runner.ts#L313
|
|
30
|
-
*/
|
|
31
|
-
function findStepDefinition(supportCodeLibrary, stepText, file) {
|
|
32
|
-
const matchedSteps = supportCodeLibrary.stepDefinitions.filter(step => {
|
|
33
|
-
return step.matchesStepName(stepText);
|
|
34
|
-
});
|
|
35
|
-
if (matchedSteps.length === 0) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (matchedSteps.length > 1) {
|
|
39
|
-
(0, _exit.exit)([`Multiple step definitions matched for text: "${stepText}" (${file})`,
|
|
40
|
-
// todo: print location of every step definition (as in cucumber)
|
|
41
|
-
...matchedSteps.map(s => ` ${s.pattern}`)].join('\n'));
|
|
42
|
-
}
|
|
43
|
-
return matchedSteps[0];
|
|
44
|
-
}
|
|
45
|
-
function hasTsNodeRegister(runConfiguration) {
|
|
46
|
-
return runConfiguration.support.requireModules.includes('ts-node/register');
|
|
47
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.resovleFeaturePaths = resovleFeaturePaths;
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _environment = require("@cucumber/cucumber/lib/api/environment");
|
|
11
|
-
var _console_logger = require("@cucumber/cucumber/lib/api/console_logger");
|
|
12
|
-
var _utils = require("../utils");
|
|
13
|
-
/**
|
|
14
|
-
* Representation of https://github.com/cucumber/cucumber-js/blob/main/src/paths/paths.ts
|
|
15
|
-
* Since Cucumber 10.1 resolvePaths was moved from lib/api/paths to lib/paths/paths.
|
|
16
|
-
* This module makes resolvePaths working with any version of Cucumber.
|
|
17
|
-
* See: https://github.com/cucumber/cucumber-js/pull/2361/files
|
|
18
|
-
*
|
|
19
|
-
* todo: replace with own paths resolution.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns list of absolute feature paths.
|
|
24
|
-
*/
|
|
25
|
-
// eslint-disable-next-line max-statements
|
|
26
|
-
async function resovleFeaturePaths(runConfiguration, environment = {}) {
|
|
27
|
-
const {
|
|
28
|
-
cwd,
|
|
29
|
-
stderr,
|
|
30
|
-
debug
|
|
31
|
-
} = (0, _environment.mergeEnvironment)(environment);
|
|
32
|
-
const logger = new _console_logger.ConsoleLogger(stderr, debug);
|
|
33
|
-
const cucumberRoot = (0, _utils.resolvePackageRoot)('@cucumber/cucumber');
|
|
34
|
-
const pathsModuleBefore10_1 = _path.default.join(cucumberRoot, 'lib/api/paths.js');
|
|
35
|
-
const pathsModuleAfter10_1 = _path.default.join(cucumberRoot, 'lib/paths/paths.js');
|
|
36
|
-
const isNewResolvePaths = _fs.default.existsSync(pathsModuleAfter10_1);
|
|
37
|
-
if (isNewResolvePaths) {
|
|
38
|
-
const {
|
|
39
|
-
resolvePaths
|
|
40
|
-
} = require(pathsModuleAfter10_1);
|
|
41
|
-
const {
|
|
42
|
-
sourcePaths,
|
|
43
|
-
unexpandedSourcePaths
|
|
44
|
-
} = await resolvePaths(logger, cwd, runConfiguration.sources);
|
|
45
|
-
return {
|
|
46
|
-
featurePaths: sourcePaths,
|
|
47
|
-
unexpandedFeaturePaths: unexpandedSourcePaths
|
|
48
|
-
};
|
|
49
|
-
} else {
|
|
50
|
-
const {
|
|
51
|
-
resolvePaths
|
|
52
|
-
} = require(pathsModuleBefore10_1);
|
|
53
|
-
const {
|
|
54
|
-
featurePaths,
|
|
55
|
-
unexpandedFeaturePaths
|
|
56
|
-
} = await resolvePaths(logger, cwd, runConfiguration.sources);
|
|
57
|
-
return {
|
|
58
|
-
featurePaths,
|
|
59
|
-
unexpandedFeaturePaths
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.parseStepArgument = parseStepArgument;
|
|
8
|
-
var _util = _interopRequireDefault(require("util"));
|
|
9
|
-
var _valueChecker = require("./valueChecker");
|
|
10
|
-
/**
|
|
11
|
-
* Based on: https://github.com/cucumber/cucumber-js/blob/main/src/step_arguments.ts
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
function parseStepArgument(arg, mapping) {
|
|
15
|
-
if ((0, _valueChecker.doesHaveValue)(arg.dataTable)) {
|
|
16
|
-
return mapping.dataTable(arg.dataTable);
|
|
17
|
-
} else if ((0, _valueChecker.doesHaveValue)(arg.docString)) {
|
|
18
|
-
return mapping.docString(arg.docString);
|
|
19
|
-
}
|
|
20
|
-
throw new Error(`Unknown step argument: ${_util.default.inspect(arg)}`);
|
|
21
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.doesHaveValue = doesHaveValue;
|
|
7
|
-
exports.doesNotHaveValue = doesNotHaveValue;
|
|
8
|
-
exports.valueOrDefault = valueOrDefault;
|
|
9
|
-
/**
|
|
10
|
-
* Based on: https://github.com/cucumber/cucumber-js/blob/main/src/value_checker.ts
|
|
11
|
-
*/
|
|
12
|
-
function doesHaveValue(value) {
|
|
13
|
-
return !doesNotHaveValue(value);
|
|
14
|
-
}
|
|
15
|
-
function doesNotHaveValue(value) {
|
|
16
|
-
return value === null || value === undefined;
|
|
17
|
-
}
|
|
18
|
-
function valueOrDefault(value, defaultValue) {
|
|
19
|
-
if (doesHaveValue(value)) {
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
return defaultValue;
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Fixture", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _class.Fixture;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
exports.When = exports.Then = exports.Step = exports.Given = void 0;
|
|
13
|
-
var _class = require("./steps/decorators/class");
|
|
14
|
-
var _steps = require("./steps/decorators/steps");
|
|
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');
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Formatter = void 0;
|
|
7
|
-
var _jsStringWrap = require("../utils/jsStringWrap");
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
var _utils2 = require("../playwright/utils");
|
|
10
|
-
/**
|
|
11
|
-
* Helper to format Playwright test file.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const supportsTags = _utils2.playwrightVersion >= '1.42.0';
|
|
15
|
-
class Formatter {
|
|
16
|
-
config;
|
|
17
|
-
constructor(config) {
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
fileHeader(featureUri, importTestFrom) {
|
|
21
|
-
// always use "/" for imports, see #91
|
|
22
|
-
const importTestFromFile = (0, _utils.toPosixPath)((importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary');
|
|
23
|
-
let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
|
|
24
|
-
if (varName !== 'test') {
|
|
25
|
-
varName = `${varName} as test`;
|
|
26
|
-
}
|
|
27
|
-
return [`/** Generated from: ${featureUri} */`,
|
|
28
|
-
// prettier-ignore
|
|
29
|
-
// this.quoted() is not possible for 'import from' as backticks not parsed
|
|
30
|
-
`import { ${varName} } from ${JSON.stringify(importTestFromFile)};`, ''];
|
|
31
|
-
}
|
|
32
|
-
describe(node, children) {
|
|
33
|
-
const firstLine = `test.${this.getFunction('describe', node)}(${this.quoted(node.title)}, () => {`;
|
|
34
|
-
if (!children.length) {
|
|
35
|
-
return [`${firstLine}});`, ''];
|
|
36
|
-
}
|
|
37
|
-
return [firstLine,
|
|
38
|
-
// prettier-ignore
|
|
39
|
-
...this.describeConfigure(node).map(indent), '', ...children.map(indent), `});`, ''];
|
|
40
|
-
}
|
|
41
|
-
beforeEach(fixtures, children) {
|
|
42
|
-
const fixturesStr = [...fixtures].join(', ');
|
|
43
|
-
// prettier-ignore
|
|
44
|
-
return [`test.beforeEach(async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
|
|
45
|
-
}
|
|
46
|
-
test(node, fixtures, children) {
|
|
47
|
-
const fixturesStr = [...fixtures].join(', ');
|
|
48
|
-
const title = this.quoted(node.title);
|
|
49
|
-
const tags = this.testTags(node);
|
|
50
|
-
const firstLine = `${this.getFunction('test', node)}(${title}, ${tags}async ({ ${fixturesStr} }) => {`;
|
|
51
|
-
if (!children.length) {
|
|
52
|
-
return [`${firstLine}});`, ''];
|
|
53
|
-
}
|
|
54
|
-
const lines = [firstLine,
|
|
55
|
-
// prettier-ignore
|
|
56
|
-
...children.map(indent), `});`, ''];
|
|
57
|
-
// wrap test into anonymous describe in case of retries / timeout tags
|
|
58
|
-
const specialTagsConfigure = this.describeConfigure(node);
|
|
59
|
-
return specialTagsConfigure.length ? ['test.describe(() => {',
|
|
60
|
-
// prettier-ignore
|
|
61
|
-
...specialTagsConfigure.map(indent), '', ...lines.map(indent), `});`, ''] : lines;
|
|
62
|
-
}
|
|
63
|
-
// eslint-disable-next-line max-params
|
|
64
|
-
step(keyword, text, argument, fixtureNames = []) {
|
|
65
|
-
const fixtures = fixtureNames.length ? `{ ${fixtureNames.join(', ')} }` : '';
|
|
66
|
-
const argumentArg = argument ? JSON.stringify(argument) : fixtures ? 'null' : '';
|
|
67
|
-
const textArg = this.quoted(text);
|
|
68
|
-
const args = [textArg, argumentArg, fixtures].filter(arg => arg !== '').join(', ');
|
|
69
|
-
return `await ${keyword}(${args});`;
|
|
70
|
-
}
|
|
71
|
-
missingStep(keyword, text) {
|
|
72
|
-
return `// missing step: ${keyword}(${this.quoted(text)});`;
|
|
73
|
-
}
|
|
74
|
-
technicalSection(testMetaBuilder, featureUri, fixtures) {
|
|
75
|
-
return ['// == technical section ==',
|
|
76
|
-
// prettier-ignore
|
|
77
|
-
'', 'test.use({', ...['$test: ({}, use) => use(test),', '$testMetaMap: ({}, use) => use(testMetaMap),', `$uri: ({}, use) => use(${this.quoted(featureUri)}),`, ...fixtures].map(indent), '});', '', 'const testMetaMap = {', ...testMetaBuilder.getObjectLines().map(indent), '};'];
|
|
78
|
-
}
|
|
79
|
-
bddWorldFixtures() {
|
|
80
|
-
const fixturesObj = {
|
|
81
|
-
page: null,
|
|
82
|
-
context: null,
|
|
83
|
-
browser: null,
|
|
84
|
-
browserName: null,
|
|
85
|
-
request: null
|
|
86
|
-
};
|
|
87
|
-
const fixtures = Object.keys(fixturesObj).join(', ');
|
|
88
|
-
return [`$bddWorldFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
|
|
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
|
-
}
|
|
108
|
-
// eslint-disable-next-line complexity
|
|
109
|
-
getFunction(baseFn, node) {
|
|
110
|
-
if (node.specialTags.only) {
|
|
111
|
-
return `${baseFn}.only`;
|
|
112
|
-
}
|
|
113
|
-
// describe.fail is not supported
|
|
114
|
-
if (baseFn === 'test' && node.specialTags.fail) {
|
|
115
|
-
return `${baseFn}.fail`;
|
|
116
|
-
}
|
|
117
|
-
if (node.specialTags.skip) {
|
|
118
|
-
return `${baseFn}.skip`;
|
|
119
|
-
}
|
|
120
|
-
if (node.specialTags.fixme) {
|
|
121
|
-
return `${baseFn}.fixme`;
|
|
122
|
-
}
|
|
123
|
-
return baseFn;
|
|
124
|
-
}
|
|
125
|
-
describeConfigure(node) {
|
|
126
|
-
const options = {};
|
|
127
|
-
const {
|
|
128
|
-
retries,
|
|
129
|
-
timeout,
|
|
130
|
-
mode
|
|
131
|
-
} = node.specialTags;
|
|
132
|
-
if (retries !== undefined) {
|
|
133
|
-
options.retries = retries;
|
|
134
|
-
}
|
|
135
|
-
if (timeout !== undefined) {
|
|
136
|
-
options.timeout = timeout;
|
|
137
|
-
}
|
|
138
|
-
if (mode !== undefined) {
|
|
139
|
-
options.mode = mode;
|
|
140
|
-
}
|
|
141
|
-
return Object.keys(options).length ? [`test.describe.configure(${JSON.stringify(options)});`] : [];
|
|
142
|
-
}
|
|
143
|
-
testTags(node) {
|
|
144
|
-
return supportsTags && node.tags.length ? `{ tag: [${node.tags.map(tag => this.quoted(tag)).join(', ')}] }, ` : '';
|
|
145
|
-
}
|
|
146
|
-
testTimeout(node) {
|
|
147
|
-
const {
|
|
148
|
-
timeout
|
|
149
|
-
} = node.specialTags;
|
|
150
|
-
return timeout !== undefined ? [`test.setTimeout(${timeout});`] : [];
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Apply this function only to string literals (mostly titles here).
|
|
154
|
-
* Objects and arrays are handled with JSON.strinigfy,
|
|
155
|
-
* b/c object keys can't be in backticks.
|
|
156
|
-
* See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
|
|
157
|
-
*/
|
|
158
|
-
quoted(str) {
|
|
159
|
-
return (0, _jsStringWrap.jsStringWrap)(str, {
|
|
160
|
-
quotes: this.config.quotes
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.Formatter = Formatter;
|
|
165
|
-
function indent(value) {
|
|
166
|
-
return value ? `${' '}${value}` : value;
|
|
167
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getKeywordsMap = getKeywordsMap;
|
|
7
|
-
var _gherkin = require("@cucumber/gherkin");
|
|
8
|
-
/**
|
|
9
|
-
* Get i18n keywords.
|
|
10
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
function getKeywordsMap(language) {
|
|
14
|
-
const origMap = _gherkin.dialects[language];
|
|
15
|
-
if (!origMap) {
|
|
16
|
-
throw new Error(`Language not found: ${language}`);
|
|
17
|
-
}
|
|
18
|
-
const targetMap = new Map();
|
|
19
|
-
const enKeywords = Object.keys(origMap);
|
|
20
|
-
enKeywords.forEach(enKeyword => handleKeyword(enKeyword, origMap, targetMap));
|
|
21
|
-
return targetMap;
|
|
22
|
-
}
|
|
23
|
-
function handleKeyword(enKeyword, origMap, targetMap) {
|
|
24
|
-
const nativeKeywords = origMap[enKeyword];
|
|
25
|
-
// Array.isArray converts to any[]
|
|
26
|
-
if (typeof nativeKeywords === 'string') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
nativeKeywords.forEach(nativeKeyword => {
|
|
30
|
-
nativeKeyword = nativeKeyword.trim();
|
|
31
|
-
if (!nativeKeyword || nativeKeyword === '*') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function capitalizeFirstLetter(s) {
|
|
38
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
39
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TestFilesGenerator = void 0;
|
|
8
|
-
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
11
|
-
var _testFile = require("./testFile");
|
|
12
|
-
var _loadConfig = require("../cucumber/loadConfig");
|
|
13
|
-
var _loadFeatures = require("../cucumber/loadFeatures");
|
|
14
|
-
var _loadSteps = require("../cucumber/loadSteps");
|
|
15
|
-
var _config = require("../config");
|
|
16
|
-
var _snippets = require("../snippets");
|
|
17
|
-
var _steps = require("../steps/decorators/steps");
|
|
18
|
-
var _transform = require("../playwright/transform");
|
|
19
|
-
var _configDir = require("../config/configDir");
|
|
20
|
-
var _logger = require("../utils/logger");
|
|
21
|
-
var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
|
|
22
|
-
var _exit = require("../utils/exit");
|
|
23
|
-
var _createBdd = require("../steps/createBdd");
|
|
24
|
-
var _resolveFeaturePaths = require("../cucumber/resolveFeaturePaths");
|
|
25
|
-
/**
|
|
26
|
-
* Generate playwright test files from Gherkin documents.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
class TestFilesGenerator {
|
|
30
|
-
config;
|
|
31
|
-
// all these props are exist
|
|
32
|
-
runConfiguration;
|
|
33
|
-
featuresLoader = new _loadFeatures.FeaturesLoader();
|
|
34
|
-
supportCodeLibrary;
|
|
35
|
-
files = [];
|
|
36
|
-
tagsExpression;
|
|
37
|
-
logger;
|
|
38
|
-
constructor(config) {
|
|
39
|
-
this.config = config;
|
|
40
|
-
this.logger = new _logger.Logger({
|
|
41
|
-
verbose: config.verbose
|
|
42
|
-
});
|
|
43
|
-
if (config.tags) {
|
|
44
|
-
this.tagsExpression = (0, _tagExpressions.default)(config.tags);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async generate() {
|
|
48
|
-
await (0, _exit.withExitHandler)(async () => {
|
|
49
|
-
await this.loadCucumberConfig();
|
|
50
|
-
await Promise.all([this.loadFeatures(), this.loadSteps()]);
|
|
51
|
-
this.buildFiles();
|
|
52
|
-
await this.checkUndefinedSteps();
|
|
53
|
-
this.checkImportTestFrom();
|
|
54
|
-
await this.clearOutputDir();
|
|
55
|
-
await this.saveFiles();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async extractSteps() {
|
|
59
|
-
await this.loadCucumberConfig();
|
|
60
|
-
await this.loadSteps();
|
|
61
|
-
return this.supportCodeLibrary.stepDefinitions;
|
|
62
|
-
}
|
|
63
|
-
// todo: combine with extractSteps
|
|
64
|
-
async extractUnusedSteps() {
|
|
65
|
-
await this.loadCucumberConfig();
|
|
66
|
-
await Promise.all([this.loadFeatures(), this.loadSteps()]);
|
|
67
|
-
this.buildFiles();
|
|
68
|
-
return this.supportCodeLibrary.stepDefinitions.filter(stepDefinition => {
|
|
69
|
-
const isUsed = this.files.some(file => file.usedStepDefinitions.has(stepDefinition));
|
|
70
|
-
return !isUsed;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async loadCucumberConfig() {
|
|
74
|
-
const environment = {
|
|
75
|
-
cwd: (0, _configDir.getPlaywrightConfigDir)()
|
|
76
|
-
};
|
|
77
|
-
const {
|
|
78
|
-
runConfiguration
|
|
79
|
-
} = await (0, _loadConfig.loadConfig)({
|
|
80
|
-
provided: (0, _config.extractCucumberConfig)(this.config)
|
|
81
|
-
}, environment);
|
|
82
|
-
this.runConfiguration = runConfiguration;
|
|
83
|
-
this.warnForTsNodeRegister();
|
|
84
|
-
}
|
|
85
|
-
async loadFeatures() {
|
|
86
|
-
const cwd = (0, _configDir.getPlaywrightConfigDir)();
|
|
87
|
-
const {
|
|
88
|
-
defaultDialect
|
|
89
|
-
} = this.runConfiguration.sources;
|
|
90
|
-
const {
|
|
91
|
-
featurePaths
|
|
92
|
-
} = await (0, _resolveFeaturePaths.resovleFeaturePaths)(this.runConfiguration, {
|
|
93
|
-
cwd
|
|
94
|
-
});
|
|
95
|
-
this.logger.log(`Loading features from paths (${featurePaths.length}):`);
|
|
96
|
-
featurePaths.forEach(featurePath => this.logger.log(featurePath));
|
|
97
|
-
if (featurePaths.length) {
|
|
98
|
-
await this.featuresLoader.load(featurePaths, {
|
|
99
|
-
relativeTo: cwd,
|
|
100
|
-
defaultDialect
|
|
101
|
-
});
|
|
102
|
-
this.handleParseErrors();
|
|
103
|
-
}
|
|
104
|
-
this.logger.log(`Loaded features: ${this.featuresLoader.getDocumentsCount()}`);
|
|
105
|
-
}
|
|
106
|
-
async loadSteps() {
|
|
107
|
-
const {
|
|
108
|
-
requirePaths,
|
|
109
|
-
importPaths
|
|
110
|
-
} = this.runConfiguration.support;
|
|
111
|
-
this.logger.log(`Loading steps from: ${requirePaths.concat(importPaths).join(', ')}`);
|
|
112
|
-
const environment = {
|
|
113
|
-
cwd: (0, _configDir.getPlaywrightConfigDir)()
|
|
114
|
-
};
|
|
115
|
-
this.supportCodeLibrary = await (0, _loadSteps.loadSteps)(this.runConfiguration, environment);
|
|
116
|
-
await this.loadDecoratorSteps();
|
|
117
|
-
this.logger.log(`Loaded steps: ${this.supportCodeLibrary.stepDefinitions.length}`);
|
|
118
|
-
}
|
|
119
|
-
async loadDecoratorSteps() {
|
|
120
|
-
const {
|
|
121
|
-
importTestFrom
|
|
122
|
-
} = this.config;
|
|
123
|
-
if (importTestFrom) {
|
|
124
|
-
// require importTestFrom for case when it is not required by step definitions
|
|
125
|
-
// possible re-require but it's not a problem as it is cached by Node.js
|
|
126
|
-
await (0, _transform.requireTransform)().requireOrImport(importTestFrom.file);
|
|
127
|
-
(0, _steps.appendDecoratorSteps)(this.supportCodeLibrary);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
buildFiles() {
|
|
131
|
-
this.files = this.featuresLoader.getDocumentsWithPickles().map(gherkinDocument => {
|
|
132
|
-
return new _testFile.TestFile({
|
|
133
|
-
gherkinDocument,
|
|
134
|
-
supportCodeLibrary: this.supportCodeLibrary,
|
|
135
|
-
// doc.uri is always relative to cwd (coming after cucumber handling)
|
|
136
|
-
// see: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts#L51
|
|
137
|
-
outputPath: this.getSpecPathByFeaturePath(gherkinDocument.uri),
|
|
138
|
-
config: this.config,
|
|
139
|
-
tagsExpression: this.tagsExpression
|
|
140
|
-
}).build();
|
|
141
|
-
}).filter(file => file.testCount > 0);
|
|
142
|
-
}
|
|
143
|
-
getSpecPathByFeaturePath(relFeaturePath) {
|
|
144
|
-
const configDir = (0, _configDir.getPlaywrightConfigDir)();
|
|
145
|
-
const absFeaturePath = _path.default.resolve(configDir, relFeaturePath);
|
|
146
|
-
const relOutputPath = _path.default.relative(this.config.featuresRoot, absFeaturePath);
|
|
147
|
-
if (relOutputPath.startsWith('..')) {
|
|
148
|
-
(0, _exit.exit)(`All feature files should be located underneath featuresRoot.`, `Please change featuresRoot or paths in configuration.\n`, `featureFile: ${absFeaturePath}\n`, `featuresRoot: ${this.config.featuresRoot}\n`);
|
|
149
|
-
}
|
|
150
|
-
const absOutputPath = _path.default.resolve(this.config.outputDir, relOutputPath);
|
|
151
|
-
return `${absOutputPath}.spec.js`;
|
|
152
|
-
}
|
|
153
|
-
async checkUndefinedSteps() {
|
|
154
|
-
const undefinedSteps = this.files.reduce((sum, file) => sum + file.undefinedSteps.length, 0);
|
|
155
|
-
if (undefinedSteps > 0) {
|
|
156
|
-
const snippets = new _snippets.Snippets(this.files, this.runConfiguration, this.supportCodeLibrary);
|
|
157
|
-
await snippets.print();
|
|
158
|
-
(0, _exit.exit)();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
checkImportTestFrom() {
|
|
162
|
-
if (_createBdd.hasCustomTest && !this.config.importTestFrom) {
|
|
163
|
-
(0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async saveFiles() {
|
|
167
|
-
this.files.forEach(file => {
|
|
168
|
-
file.save();
|
|
169
|
-
this.logger.log(`Generated: ${_path.default.relative(process.cwd(), file.outputPath)}`);
|
|
170
|
-
});
|
|
171
|
-
this.logger.log(`Generated files: ${this.files.length}`);
|
|
172
|
-
}
|
|
173
|
-
async clearOutputDir() {
|
|
174
|
-
const pattern = `${_fastGlob.default.convertPathToPattern(this.config.outputDir)}/**/*.spec.js`;
|
|
175
|
-
const testFiles = await (0, _fastGlob.default)(pattern);
|
|
176
|
-
this.logger.log(`Clearing output dir: ${testFiles.length} file(s)`);
|
|
177
|
-
const tasks = testFiles.map(testFile => _promises.default.rm(testFile));
|
|
178
|
-
await Promise.all(tasks);
|
|
179
|
-
}
|
|
180
|
-
warnForTsNodeRegister() {
|
|
181
|
-
if ((0, _loadSteps.hasTsNodeRegister)(this.runConfiguration)) {
|
|
182
|
-
this.logger.warn(`WARNING: usage of requireModule: ['ts-node/register'] is not recommended for playwright-bdd.`, `Remove this option from defineBddConfig() and`, `Playwright's built-in loader will be used to compile TypeScript step definitions.`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
handleParseErrors() {
|
|
186
|
-
const {
|
|
187
|
-
parseErrors
|
|
188
|
-
} = this.featuresLoader;
|
|
189
|
-
if (parseErrors.length) {
|
|
190
|
-
const message = parseErrors.map(parseError => {
|
|
191
|
-
return `Parse error in "${parseError.source.uri}" ${parseError.message}`;
|
|
192
|
-
}).join('\n');
|
|
193
|
-
(0, _exit.exit)(message);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.TestFilesGenerator = TestFilesGenerator;
|