@zohodesk/testinglibrary 0.1.7 → 0.1.8-exp-bdd
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 +18 -18
- package/.eslintrc.js +27 -31
- package/.prettierrc +5 -5
- package/README.md +17 -17
- package/bin/cli.js +2 -2
- package/build/bdd-framework/cli/commands/env.js +4 -4
- package/build/bdd-framework/cli/commands/test.js +2 -6
- package/build/bdd-framework/cli/options.js +4 -4
- package/build/bdd-framework/cli/worker.js +3 -3
- package/build/bdd-framework/config/dir.js +6 -6
- package/build/bdd-framework/config/env.js +4 -5
- package/build/bdd-framework/config/index.js +2 -2
- package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
- package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +3 -3
- package/build/bdd-framework/cucumber/loadSources.js +9 -9
- package/build/bdd-framework/cucumber/loadSteps.js +3 -8
- package/build/bdd-framework/decorators.js +2 -2
- package/build/bdd-framework/gen/formatter.js +17 -64
- package/build/bdd-framework/gen/i18n.js +5 -9
- package/build/bdd-framework/gen/index.js +8 -9
- package/build/bdd-framework/gen/poms.js +46 -0
- package/build/bdd-framework/gen/testFile.js +55 -121
- package/build/bdd-framework/gen/testNode.js +6 -19
- package/build/bdd-framework/gen/testPoms.js +39 -49
- package/build/bdd-framework/playwright/fixtureParameterNames.js +11 -27
- package/build/bdd-framework/playwright/getLocationInFile.js +11 -17
- package/build/bdd-framework/playwright/loadConfig.js +3 -3
- package/build/bdd-framework/playwright/testTypeImpl.js +15 -19
- package/build/bdd-framework/playwright/transform.js +6 -10
- package/build/bdd-framework/playwright/utils.js +6 -3
- package/build/bdd-framework/run/bddFixtures.js +55 -118
- package/build/bdd-framework/run/bddWorld.js +36 -24
- package/build/bdd-framework/snippets/index.js +3 -5
- package/build/bdd-framework/snippets/snippetSyntax.js +1 -3
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
- package/build/bdd-framework/stepDefinitions/createBdd.js +13 -30
- package/build/bdd-framework/stepDefinitions/createDecorators.js +108 -0
- package/build/bdd-framework/stepDefinitions/decorators/{class.js → poms.js} +9 -13
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +8 -14
- package/build/bdd-framework/stepDefinitions/defineStep.js +4 -5
- package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
- package/build/bdd-framework/utils/exit.js +18 -26
- package/build/bdd-framework/utils/index.js +4 -30
- package/build/bdd-framework/utils/jsStringWrap.js +9 -9
- package/build/bdd-framework/utils/logger.js +3 -5
- package/build/bdd-poc/core-runner/exportMethods.js +14 -0
- package/build/bdd-poc/core-runner/stepDefinitions.js +55 -0
- package/build/bdd-poc/main.js +10 -0
- package/build/bdd-poc/test/cucumber/featureFileParer.js +81 -0
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +36 -0
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +43 -0
- package/build/bdd-poc/test/testDataMap.js +98 -0
- package/build/bdd-poc/test/testStructure.js +83 -0
- package/build/bdd-poc/utils/stringManipulation.js +19 -0
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/index.js +0 -15
- package/build/core/playwright/readConfigFile.js +30 -37
- package/build/core/playwright/report-generator.js +1 -2
- package/build/core/playwright/setup/config-creator.js +15 -21
- package/build/core/playwright/setup/config-utils.js +0 -30
- package/build/core/playwright/test-runner.js +5 -7
- package/build/index.d.ts +5 -60
- package/build/index.js +3 -5
- package/build/lib/cli.js +1 -10
- package/build/parser/sample.feature +34 -34
- package/build/parser/sample.spec.js +18 -18
- package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
- package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
- package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
- package/build/setup-folder-structure/samples/git-ignore.sample.js +32 -36
- package/build/setup-folder-structure/samples/uat-config-sample.js +43 -44
- package/build/setup-folder-structure/setupProject.js +5 -10
- package/build/utils/cliArgsToObject.js +25 -25
- package/build/utils/fileUtils.js +0 -12
- package/changelog.md +74 -124
- package/jest.config.js +63 -63
- package/npm-shrinkwrap.json +7781 -6469
- package/package.json +54 -55
- package/playwright.config.js +112 -112
- package/build/bdd-framework/config/lang.js +0 -14
- package/build/bdd-framework/gen/fixtures.js +0 -48
- package/build/bdd-framework/hooks/scenario.js +0 -107
- package/build/bdd-framework/hooks/worker.js +0 -83
- package/build/bdd-framework/run/StepInvoker.js +0 -73
- package/build/core/playwright/clear-caches.js +0 -29
- package/build/core/playwright/setup/custom-reporter.js +0 -100
- package/build/core/playwright/tag-processor.js +0 -68
- package/build/setup-folder-structure/helper.js +0 -34
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +0 -25
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +0 -25
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Fixture = Fixture;
|
|
7
|
+
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
8
|
+
exports.createStepDecorator = createStepDecorator;
|
|
9
|
+
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
10
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
+
var _defineStep = require("./defineStep");
|
|
12
|
+
var _buildStepDefinition = require("../cucumber/buildStepDefinition");
|
|
13
|
+
/* eslint-disable no-unused-vars */
|
|
14
|
+
/**
|
|
15
|
+
* Define steps via decorators.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const pomGraph = new Map();
|
|
19
|
+
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
20
|
+
const decoratedSteps = new Set();
|
|
21
|
+
function Fixture(fixtureName) {
|
|
22
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
23
|
+
return (Ctor, _context) => {
|
|
24
|
+
createPomNode(Ctor, fixtureName);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createStepDecorator(keyword) {
|
|
28
|
+
return pattern => {
|
|
29
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
30
|
+
return (method, _context) => {
|
|
31
|
+
method[decoratedStepSymbol] = {
|
|
32
|
+
keyword,
|
|
33
|
+
pattern,
|
|
34
|
+
fn: method,
|
|
35
|
+
hasCustomTest: true,
|
|
36
|
+
isDecorator: true
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function appendDecoratorSteps(supportCodeLibrary) {
|
|
42
|
+
decoratedSteps.forEach(stepConfig => {
|
|
43
|
+
const {
|
|
44
|
+
keyword,
|
|
45
|
+
pattern,
|
|
46
|
+
fn
|
|
47
|
+
} = stepConfig;
|
|
48
|
+
stepConfig.fn = (fixturesArg, ...args) => {
|
|
49
|
+
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
50
|
+
return fn.call(fixture, ...args);
|
|
51
|
+
};
|
|
52
|
+
const code = (0, _defineStep.buildCucumberStepFn)(stepConfig);
|
|
53
|
+
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
54
|
+
keyword,
|
|
55
|
+
pattern,
|
|
56
|
+
code,
|
|
57
|
+
line: 0,
|
|
58
|
+
// not used in playwright-bdd
|
|
59
|
+
options: {},
|
|
60
|
+
// not used in playwright-bdd
|
|
61
|
+
uri: '' // not used in playwright-bdd
|
|
62
|
+
}, supportCodeLibrary);
|
|
63
|
+
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
64
|
+
});
|
|
65
|
+
decoratedSteps.clear();
|
|
66
|
+
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
67
|
+
}
|
|
68
|
+
function getPomNodeByFixtureName(fixtureName) {
|
|
69
|
+
for (const pomNode of pomGraph.values()) {
|
|
70
|
+
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function createPomNode(Ctor, fixtureName) {
|
|
74
|
+
const pomNode = {
|
|
75
|
+
fixtureName,
|
|
76
|
+
children: new Set()
|
|
77
|
+
};
|
|
78
|
+
pomGraph.set(Ctor, pomNode);
|
|
79
|
+
getDecoratedSteps(Ctor).forEach(stepConfig => {
|
|
80
|
+
stepConfig.pomNode = pomNode;
|
|
81
|
+
decoratedSteps.add(stepConfig);
|
|
82
|
+
});
|
|
83
|
+
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
84
|
+
if (!parentCtor) return;
|
|
85
|
+
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
86
|
+
parentPomNode === null || parentPomNode === void 0 || parentPomNode.children.add(pomNode);
|
|
87
|
+
return pomNode;
|
|
88
|
+
}
|
|
89
|
+
function getDecoratedSteps(Ctor) {
|
|
90
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return [];
|
|
91
|
+
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
92
|
+
return Object.keys(propertyDescriptors)
|
|
93
|
+
// filter out getters / setters
|
|
94
|
+
.filter(methodName => typeof propertyDescriptors[methodName].value === 'function').map(methodName => {
|
|
95
|
+
return propertyDescriptors[methodName].value[decoratedStepSymbol];
|
|
96
|
+
}).filter(Boolean);
|
|
97
|
+
}
|
|
98
|
+
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
99
|
+
// there should be exatcly one suitable fixture in fixturesArg
|
|
100
|
+
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
101
|
+
if (fixtureNames.length === 0) {
|
|
102
|
+
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
103
|
+
}
|
|
104
|
+
if (fixtureNames.length > 1) {
|
|
105
|
+
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
106
|
+
}
|
|
107
|
+
return fixturesArg[fixtureNames[0]];
|
|
108
|
+
}
|
|
@@ -7,17 +7,17 @@ exports.Fixture = Fixture;
|
|
|
7
7
|
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
8
8
|
var _steps = require("./steps");
|
|
9
9
|
var _exit = require("../../utils/exit");
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
10
|
+
/**
|
|
11
|
+
* POM classes marked with @Fixture
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Graph of POM class inheritance.
|
|
16
|
-
* Allows to guess correct fixture by step text.
|
|
14
|
+
/**
|
|
15
|
+
* Graph of POM class inheritance.
|
|
16
|
+
* Allows to guess correct fixture by step text.
|
|
17
17
|
*/
|
|
18
18
|
const pomGraph = new Map();
|
|
19
|
-
/**
|
|
20
|
-
* @Fixture decorator.
|
|
19
|
+
/**
|
|
20
|
+
* @Fixture decorator.
|
|
21
21
|
*/
|
|
22
22
|
function Fixture(fixtureName) {
|
|
23
23
|
// context parameter is required for decorator by TS even though it's not used
|
|
@@ -51,9 +51,7 @@ function ensureUniqueFixtureName({
|
|
|
51
51
|
}
|
|
52
52
|
function linkParentWithPomNode(Ctor, pomNode) {
|
|
53
53
|
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
54
|
-
if (!parentCtor)
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
54
|
+
if (!parentCtor) return;
|
|
57
55
|
// if parentCtor is not in pomGraph, add it.
|
|
58
56
|
// Case: parent class is not marked with @Fixture, but has decorator steps (base class)
|
|
59
57
|
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
@@ -61,8 +59,6 @@ function linkParentWithPomNode(Ctor, pomNode) {
|
|
|
61
59
|
}
|
|
62
60
|
function getPomNodeByFixtureName(fixtureName) {
|
|
63
61
|
for (const pomNode of pomGraph.values()) {
|
|
64
|
-
if (pomNode.fixtureName === fixtureName)
|
|
65
|
-
return pomNode;
|
|
66
|
-
}
|
|
62
|
+
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
67
63
|
}
|
|
68
64
|
}
|
|
@@ -9,8 +9,8 @@ exports.linkStepsWithPomNode = linkStepsWithPomNode;
|
|
|
9
9
|
var _bddFixtures = require("../../run/bddFixtures");
|
|
10
10
|
var _buildStepDefinition = require("../../cucumber/buildStepDefinition");
|
|
11
11
|
var _defineStep = require("../defineStep");
|
|
12
|
-
/**
|
|
13
|
-
* Define steps via decorators.
|
|
12
|
+
/**
|
|
13
|
+
* Define steps via decorators.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
// initially we sotre step data inside method,
|
|
@@ -18,8 +18,8 @@ var _defineStep = require("../defineStep");
|
|
|
18
18
|
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
19
19
|
// global list of all decorator steps
|
|
20
20
|
const decoratedSteps = new Set();
|
|
21
|
-
/**
|
|
22
|
-
* Creates @Given, @When, @Then decorators.
|
|
21
|
+
/**
|
|
22
|
+
* Creates @Given, @When, @Then decorators.
|
|
23
23
|
*/
|
|
24
24
|
function createStepDecorator(keyword) {
|
|
25
25
|
return pattern => {
|
|
@@ -36,21 +36,17 @@ function createStepDecorator(keyword) {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
function linkStepsWithPomNode(Ctor, pomNode) {
|
|
39
|
-
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype))
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
39
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return;
|
|
42
40
|
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
43
41
|
return Object.values(propertyDescriptors).forEach(descriptor => {
|
|
44
42
|
const stepConfig = getStepConfigFromMethod(descriptor);
|
|
45
|
-
if (!stepConfig)
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
43
|
+
if (!stepConfig) return;
|
|
48
44
|
stepConfig.pomNode = pomNode;
|
|
49
45
|
decoratedSteps.add(stepConfig);
|
|
50
46
|
});
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
48
|
+
/**
|
|
49
|
+
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
54
50
|
*/
|
|
55
51
|
function appendDecoratorSteps(supportCodeLibrary) {
|
|
56
52
|
decoratedSteps.forEach(stepConfig => {
|
|
@@ -69,9 +65,7 @@ function appendDecoratorSteps(supportCodeLibrary) {
|
|
|
69
65
|
pattern,
|
|
70
66
|
code,
|
|
71
67
|
line: 0,
|
|
72
|
-
// not used in playwright-bdd
|
|
73
68
|
options: {},
|
|
74
|
-
// not used in playwright-bdd
|
|
75
69
|
uri: '' // not used in playwright-bdd
|
|
76
70
|
}, supportCodeLibrary);
|
|
77
71
|
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
@@ -8,9 +8,9 @@ exports.defineStep = defineStep;
|
|
|
8
8
|
exports.getStepCode = getStepCode;
|
|
9
9
|
var _cucumber = require("@cucumber/cucumber");
|
|
10
10
|
var _exit = require("../utils/exit");
|
|
11
|
-
/**
|
|
12
|
-
* Defines step by config.
|
|
13
|
-
* Calls cucumber's Given(), When(), Then() under the hood.
|
|
11
|
+
/**
|
|
12
|
+
* Defines step by config.
|
|
13
|
+
* Calls cucumber's Given(), When(), Then() under the hood.
|
|
14
14
|
*/
|
|
15
15
|
function defineStep(stepConfig) {
|
|
16
16
|
const {
|
|
@@ -34,8 +34,7 @@ function defineStep(stepConfig) {
|
|
|
34
34
|
}
|
|
35
35
|
function buildCucumberStepCode(stepConfig) {
|
|
36
36
|
const code = function (...args) {
|
|
37
|
-
|
|
38
|
-
const fixturesArg = Object.assign({}, this.stepFixtures, {
|
|
37
|
+
const fixturesArg = Object.assign({}, this.customFixtures, {
|
|
39
38
|
$testInfo: this.testInfo,
|
|
40
39
|
$test: this.test,
|
|
41
40
|
$tags: this.tags
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getStepConfig = getStepConfig;
|
|
7
7
|
exports.isDecorator = isDecorator;
|
|
8
8
|
exports.isPlaywrightStyle = isPlaywrightStyle;
|
|
9
|
-
/**
|
|
10
|
-
* Playwright-bdd's step config.
|
|
9
|
+
/**
|
|
10
|
+
* Playwright-bdd's step config.
|
|
11
11
|
*/
|
|
12
12
|
function getStepConfig(step) {
|
|
13
13
|
return step.code.stepConfig;
|
|
@@ -15,9 +15,9 @@ function getStepConfig(step) {
|
|
|
15
15
|
function isDecorator(stepConfig) {
|
|
16
16
|
return Boolean(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.pomNode);
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Cucumber-style steps don't have stepConfig
|
|
20
|
-
* b/c they created directly via cucumber's Given, When, Then.
|
|
18
|
+
/**
|
|
19
|
+
* Cucumber-style steps don't have stepConfig
|
|
20
|
+
* b/c they created directly via cucumber's Given, When, Then.
|
|
21
21
|
*/
|
|
22
22
|
function isPlaywrightStyle(stepConfig) {
|
|
23
23
|
return Boolean(stepConfig);
|
|
@@ -5,24 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.exit = exit;
|
|
7
7
|
exports.withExitHandler = withExitHandler;
|
|
8
|
+
var _logger = require("./logger");
|
|
8
9
|
var _worker_threads = require("worker_threads");
|
|
9
|
-
/**
|
|
10
|
-
* Exit utils.
|
|
11
|
-
*
|
|
12
|
-
* When calling process.exit() in worker thread used for
|
|
13
|
-
* logs are not flushed (https://github.com/vitalets/playwright-bdd/issues/59).
|
|
14
|
-
* That's why instead of process.exit we throw ExitError
|
|
15
|
-
* that just sets process.exitCode = 1 and allow program to exit normally.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* - https://github.com/nodejs/node/issues/
|
|
24
|
-
* - https://github.com/
|
|
25
|
-
* - https://github.com/cucumber/cucumber-js/pull/123
|
|
10
|
+
/**
|
|
11
|
+
* Exit utils.
|
|
12
|
+
*
|
|
13
|
+
* When calling process.exit() in worker thread used for file generation,
|
|
14
|
+
* logs are not flushed (https://github.com/vitalets/playwright-bdd/issues/59).
|
|
15
|
+
* That's why instead of process.exit we throw ExitError
|
|
16
|
+
* that just sets process.exitCode = 1 and allow program to exit normally.
|
|
17
|
+
*
|
|
18
|
+
* On the other hand, when running in main thread, especially inside Playwright,
|
|
19
|
+
* thrown error is captured by Playwright and show with additional messages (e.g. no tests found).
|
|
20
|
+
* That's why in main thread we to call process.exit() to show only needed error.
|
|
21
|
+
*
|
|
22
|
+
* Relevant discussions:
|
|
23
|
+
* - https://github.com/nodejs/node/issues/6379
|
|
24
|
+
* - https://github.com/nodejs/node-v0.x-archive/issues/3737
|
|
25
|
+
* - https://github.com/cucumber/cucumber-js/pull/123
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
class ExitError extends Error {
|
|
@@ -35,10 +35,6 @@ async function withExitHandler(fn) {
|
|
|
35
35
|
return await fn();
|
|
36
36
|
} catch (e) {
|
|
37
37
|
if (e instanceof ExitError) {
|
|
38
|
-
if (e.message) {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.error(e.message);
|
|
41
|
-
}
|
|
42
38
|
process.exitCode = 1;
|
|
43
39
|
} else {
|
|
44
40
|
throw e;
|
|
@@ -48,12 +44,8 @@ async function withExitHandler(fn) {
|
|
|
48
44
|
function exit(...messages) {
|
|
49
45
|
messages = messages.filter(Boolean);
|
|
50
46
|
if (_worker_threads.isMainThread) {
|
|
51
|
-
// use console.error() here instead of logger.error() to have less stack
|
|
52
|
-
// for flushing messages to stderr.
|
|
53
|
-
|
|
54
47
|
if (messages.length) {
|
|
55
|
-
|
|
56
|
-
console.error('Error:', ...messages);
|
|
48
|
+
_logger.logger.error('Error:', ...messages);
|
|
57
49
|
}
|
|
58
50
|
process.exit(1);
|
|
59
51
|
} else {
|
|
@@ -4,8 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.callWithTimeout = callWithTimeout;
|
|
8
|
-
exports.extractTemplateParams = extractTemplateParams;
|
|
9
7
|
exports.getPackageVersion = getPackageVersion;
|
|
10
8
|
exports.getSymbolByName = getSymbolByName;
|
|
11
9
|
exports.removeDuplicates = removeDuplicates;
|
|
@@ -13,12 +11,7 @@ exports.resolvePackageRoot = resolvePackageRoot;
|
|
|
13
11
|
exports.template = template;
|
|
14
12
|
var _fs = _interopRequireDefault(require("fs"));
|
|
15
13
|
var _path = _interopRequireDefault(require("path"));
|
|
16
|
-
|
|
17
|
-
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
18
|
-
/**
|
|
19
|
-
* Returns Symbol by name.
|
|
20
|
-
* See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
21
|
-
*/
|
|
14
|
+
// See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
22
15
|
function getSymbolByName(target, name) {
|
|
23
16
|
const ownKeys = Reflect.ownKeys(target);
|
|
24
17
|
const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
|
|
@@ -27,22 +20,15 @@ function getSymbolByName(target, name) {
|
|
|
27
20
|
}
|
|
28
21
|
return symbol;
|
|
29
22
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Inserts params into template.
|
|
32
|
-
* Params defined as <param>.
|
|
23
|
+
/**
|
|
24
|
+
* Inserts params into template.
|
|
25
|
+
* Params defined as <param>.
|
|
33
26
|
*/
|
|
34
27
|
function template(t, params = {}) {
|
|
35
28
|
return t.replace(/<(.+?)>/g, (match, key) => {
|
|
36
29
|
return params[key] !== undefined ? String(params[key]) : match;
|
|
37
30
|
});
|
|
38
31
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Extracts all template params from string.
|
|
41
|
-
* Params defined as <param>.
|
|
42
|
-
*/
|
|
43
|
-
function extractTemplateParams(t) {
|
|
44
|
-
return [...t.matchAll(/<(.+?)>/g)].map(m => m[1]);
|
|
45
|
-
}
|
|
46
32
|
function removeDuplicates(arr) {
|
|
47
33
|
return [...new Set(arr)];
|
|
48
34
|
}
|
|
@@ -55,16 +41,4 @@ function getPackageVersion(packageName) {
|
|
|
55
41
|
const packageJsonPath = _path.default.join(packageRoot, 'package.json');
|
|
56
42
|
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
57
43
|
return packageJson.version || '';
|
|
58
|
-
}
|
|
59
|
-
async function callWithTimeout(fn, timeout, timeoutMsg) {
|
|
60
|
-
if (!timeout) {
|
|
61
|
-
return fn();
|
|
62
|
-
}
|
|
63
|
-
const ac = new AbortController();
|
|
64
|
-
return Promise.race([fn(), setTimeoutPromise(timeout, null, {
|
|
65
|
-
ref: false,
|
|
66
|
-
signal: ac.signal
|
|
67
|
-
}).then(() => {
|
|
68
|
-
throw new Error(timeoutMsg || `Function timeout (${timeout} ms)`);
|
|
69
|
-
})]).finally(() => ac.abort());
|
|
70
44
|
}
|
|
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.jsStringWrap = jsStringWrap;
|
|
7
|
-
/**
|
|
8
|
-
* Adopted version of https://github.com/joliss/js-string-escape
|
|
9
|
-
* - added support of backticks
|
|
10
|
-
* - added 'quotes' option to indicate which quotes to escape
|
|
11
|
-
* - wrap result string with provided quotes
|
|
12
|
-
*
|
|
13
|
-
* Considered alternative is https://github.com/mathiasbynens/jsesc,
|
|
14
|
-
* but it provides additional functionality and much slower
|
|
15
|
-
* See: https://github.com/mathiasbynens/jsesc/issues/16
|
|
7
|
+
/**
|
|
8
|
+
* Adopted version of https://github.com/joliss/js-string-escape
|
|
9
|
+
* - added support of backticks
|
|
10
|
+
* - added 'quotes' option to indicate which quotes to escape
|
|
11
|
+
* - wrap result string with provided quotes
|
|
12
|
+
*
|
|
13
|
+
* Considered alternative is https://github.com/mathiasbynens/jsesc,
|
|
14
|
+
* but it provides additional functionality and much slower
|
|
15
|
+
* See: https://github.com/mathiasbynens/jsesc/issues/16
|
|
16
16
|
*/
|
|
17
17
|
function jsStringWrap(str, {
|
|
18
18
|
quotes = 'single'
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.logger = exports.Logger = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Simple logger
|
|
7
|
+
/**
|
|
8
|
+
* Simple logger
|
|
9
9
|
*/
|
|
10
10
|
class Logger {
|
|
11
11
|
options;
|
|
@@ -13,9 +13,7 @@ class Logger {
|
|
|
13
13
|
this.options = options;
|
|
14
14
|
}
|
|
15
15
|
log(...args) {
|
|
16
|
-
if (this.options.verbose)
|
|
17
|
-
console.log(...args);
|
|
18
|
-
}
|
|
16
|
+
if (this.options.verbose) console.log(...args);
|
|
19
17
|
}
|
|
20
18
|
warn(...args) {
|
|
21
19
|
// using log() to output warnings to stdout, not stderr
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.And = void 0;
|
|
7
|
+
exports.Given = Given;
|
|
8
|
+
exports.When = exports.Then = void 0;
|
|
9
|
+
function Given(description, callback) {
|
|
10
|
+
globalStepMap.set(description, callback);
|
|
11
|
+
}
|
|
12
|
+
const Then = exports.Then = Given;
|
|
13
|
+
const When = exports.When = Given;
|
|
14
|
+
const And = exports.And = Given;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createNativeBDD = createNativeBDD;
|
|
7
|
+
var _testDataMap = require("../test/testDataMap");
|
|
8
|
+
(0, _testDataMap.testDataCreation)().then(data => globalThis.globalTestdata = data);
|
|
9
|
+
function $Given(description) {
|
|
10
|
+
const stepFunction = globalStepMap[description];
|
|
11
|
+
if (stepFunction === undefined) {
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
return function (pages, ...argument) {
|
|
15
|
+
const finalInput = getInputArray(description, argument);
|
|
16
|
+
return stepFunction(pages, ...finalInput);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getInputArray(description, argument) {
|
|
20
|
+
const specInput = globalTestdata.get(description);
|
|
21
|
+
if (specInput.input && specInput.steptable) {
|
|
22
|
+
const stepInput = Object.values(specInput.currentArgument).pop() || 'null';
|
|
23
|
+
return [stepInput, specInput.dataTableStep];
|
|
24
|
+
}
|
|
25
|
+
if (specInput.input) {
|
|
26
|
+
return Object.values(specInput.currentArgument) || [];
|
|
27
|
+
}
|
|
28
|
+
if (specInput.steptable) {
|
|
29
|
+
return [specInput.dataTableStep];
|
|
30
|
+
}
|
|
31
|
+
if (specInput.scenarioTable) {
|
|
32
|
+
console.log(specInput.inputParameter);
|
|
33
|
+
var exceedParam = specInput.inputParameter[0];
|
|
34
|
+
const extracted = argument.map(element => {
|
|
35
|
+
return exceedParam[element];
|
|
36
|
+
});
|
|
37
|
+
const duplicate = Object.assign({}, specInput);
|
|
38
|
+
const extractInput = duplicate.inputParameter.shift();
|
|
39
|
+
duplicate.inputParameter.push(extractInput);
|
|
40
|
+
globalTestdata.set(description, Object.assign({}, duplicate));
|
|
41
|
+
return extracted;
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const $When = $Given;
|
|
46
|
+
const $And = $Given;
|
|
47
|
+
const $Then = $Given;
|
|
48
|
+
function createNativeBDD() {
|
|
49
|
+
return {
|
|
50
|
+
$Given,
|
|
51
|
+
$When,
|
|
52
|
+
$And,
|
|
53
|
+
$Then
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cucumberBDDtoTestFile = cucumberBDDtoTestFile;
|
|
7
|
+
var _stepFileGenerate = require("./test/stepGenerate/stepFileGenerate");
|
|
8
|
+
async function cucumberBDDtoTestFile() {
|
|
9
|
+
await (0, _stepFileGenerate.generateSpecFiles)();
|
|
10
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.parseFeature = parseFeature;
|
|
8
|
+
var _gherkin = _interopRequireDefault(require("@cucumber/gherkin"));
|
|
9
|
+
var _messages = require("@cucumber/messages");
|
|
10
|
+
var uuidFn = _messages.IdGenerator.uuid();
|
|
11
|
+
var builder = new _gherkin.default.AstBuilder(uuidFn);
|
|
12
|
+
var matcher = new _gherkin.default.GherkinClassicTokenMatcher();
|
|
13
|
+
var parser = new _gherkin.default.Parser(builder, matcher);
|
|
14
|
+
function parseFeature(featureFileContent) {
|
|
15
|
+
var _gherkinDocument$feat;
|
|
16
|
+
var gherkinDocument = parser.parse(featureFileContent);
|
|
17
|
+
var currentFeature = {
|
|
18
|
+
feature: "",
|
|
19
|
+
tags: "",
|
|
20
|
+
scenarios: []
|
|
21
|
+
};
|
|
22
|
+
currentFeature.feature = gherkinDocument.feature.name;
|
|
23
|
+
currentFeature.tags = (_gherkinDocument$feat = gherkinDocument.feature) === null || _gherkinDocument$feat === void 0 ? void 0 : _gherkinDocument$feat.tags.map(tag => tag.name);
|
|
24
|
+
gherkinDocument.feature.children.forEach($scenario => {
|
|
25
|
+
var _$scenario$scenario, _$scenario$scenario2, _$scenario$scenario3, _$scenario$scenario4;
|
|
26
|
+
var scenarioSteps = {
|
|
27
|
+
scenariodescription: "",
|
|
28
|
+
steps: "",
|
|
29
|
+
tablebody: false,
|
|
30
|
+
tableheader: false,
|
|
31
|
+
examples: [],
|
|
32
|
+
scenarioTags: []
|
|
33
|
+
};
|
|
34
|
+
scenarioSteps.scenariodescription = (_$scenario$scenario = $scenario.scenario) === null || _$scenario$scenario === void 0 ? void 0 : _$scenario$scenario.name;
|
|
35
|
+
if ($scenario !== null && $scenario !== void 0 && $scenario.background) {
|
|
36
|
+
scenarioSteps.scenariodescription = "BackGround";
|
|
37
|
+
scenarioSteps.steps = $scenario.background.steps.pop().text;
|
|
38
|
+
currentFeature.scenarios.push(scenarioSteps);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
(_$scenario$scenario2 = $scenario.scenario) === null || _$scenario$scenario2 === void 0 || _$scenario$scenario2.examples.map(example => {
|
|
42
|
+
var _example$tableHeader;
|
|
43
|
+
scenarioSteps.tablebody = example === null || example === void 0 ? void 0 : example.tableBody.map(cell => {
|
|
44
|
+
return cell === null || cell === void 0 ? void 0 : cell.cells.map(example => example.value);
|
|
45
|
+
});
|
|
46
|
+
scenarioSteps.tableheader = example === null || example === void 0 || (_example$tableHeader = example.tableHeader) === null || _example$tableHeader === void 0 ? void 0 : _example$tableHeader.cells.map(exampleHead => {
|
|
47
|
+
return exampleHead.value;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
if (scenarioSteps.tablebody && scenarioSteps.tableheader) {
|
|
51
|
+
scenarioSteps.examples = testDataExtraction(scenarioSteps.tableheader, scenarioSteps.tablebody);
|
|
52
|
+
} else {
|
|
53
|
+
scenarioSteps.examples = false;
|
|
54
|
+
}
|
|
55
|
+
scenarioSteps.scenarioTags = (_$scenario$scenario3 = $scenario.scenario) === null || _$scenario$scenario3 === void 0 ? void 0 : _$scenario$scenario3.tags.map(tag => tag.name);
|
|
56
|
+
const _scenarioDescription = $scenario === null || $scenario === void 0 || (_$scenario$scenario4 = $scenario.scenario) === null || _$scenario$scenario4 === void 0 ? void 0 : _$scenario$scenario4.steps.map(step => {
|
|
57
|
+
return {
|
|
58
|
+
stepDescription: step.text,
|
|
59
|
+
keyword: step.keyword
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
scenarioSteps.steps = _scenarioDescription;
|
|
63
|
+
currentFeature.scenarios.push(scenarioSteps);
|
|
64
|
+
});
|
|
65
|
+
return currentFeature;
|
|
66
|
+
}
|
|
67
|
+
function testDataExtraction(tableHeader, tableBody) {
|
|
68
|
+
const result = [];
|
|
69
|
+
if (tableBody && tableHeader) {
|
|
70
|
+
tableBody.forEach(array => {
|
|
71
|
+
const obj = {};
|
|
72
|
+
array.forEach((item, index) => {
|
|
73
|
+
obj[`<${tableHeader[index]}>`] = item;
|
|
74
|
+
});
|
|
75
|
+
result.push(obj);
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.generateSpecFiles = generateSpecFiles;
|
|
8
|
+
var _fs = require("fs");
|
|
9
|
+
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _featureFileParer = require("../cucumber/featureFileParer");
|
|
12
|
+
var _testStructure = require("../testStructure");
|
|
13
|
+
async function stepFileCreation(featureContent, stepFilename, constructedFilePath) {
|
|
14
|
+
const generatedFolderPath = _path.default.resolve(process.cwd(), './feature-gen');
|
|
15
|
+
if (!(0, _fs.existsSync)(generatedFolderPath)) {
|
|
16
|
+
(0, _fs.mkdirSync)('./feature-gen', {
|
|
17
|
+
recursive: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const stepsFilePath = _path.default.resolve(process.cwd(), 'feature-gen', stepFilename);
|
|
21
|
+
const stepsSnippets = (0, _testStructure.testSnippet)(featureContent, constructedFilePath);
|
|
22
|
+
await (0, _fs.writeFileSync)(stepsFilePath, stepsSnippets);
|
|
23
|
+
}
|
|
24
|
+
function generateSpecFiles() {
|
|
25
|
+
const featureFilePath = _path.default.resolve(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.feature').split(`\\`).join('/');
|
|
26
|
+
_fastGlob.default.globSync(featureFilePath, {
|
|
27
|
+
dot: true,
|
|
28
|
+
cwd: process.cwd()
|
|
29
|
+
}).forEach(filePath => {
|
|
30
|
+
console.log(filePath);
|
|
31
|
+
const featurefilePath = _path.default.resolve(process.cwd(), filePath);
|
|
32
|
+
const featureContent = (0, _featureFileParer.parseFeature)((0, _fs.readFileSync)(featurefilePath, 'utf-8'));
|
|
33
|
+
const fileName = _path.default.basename(filePath).replace('.feature', '.spec.js');
|
|
34
|
+
stepFileCreation(featureContent, fileName, featureFilePath);
|
|
35
|
+
});
|
|
36
|
+
}
|