@zohodesk/testinglibrary 0.1.8-exp-bdd-v1 → 0.1.8-exp.1
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 +31 -27
- 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 +6 -2
- 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 +5 -4
- package/build/bdd-framework/config/index.js +2 -2
- package/build/bdd-framework/config/lang.js +14 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
- 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 +8 -3
- package/build/bdd-framework/decorators.js +2 -2
- package/build/bdd-framework/gen/fixtures.js +48 -0
- package/build/bdd-framework/gen/formatter.js +64 -17
- package/build/bdd-framework/gen/i18n.js +9 -5
- package/build/bdd-framework/gen/index.js +9 -8
- package/build/bdd-framework/gen/testFile.js +121 -55
- package/build/bdd-framework/gen/testNode.js +19 -6
- package/build/bdd-framework/gen/testPoms.js +49 -39
- 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 +27 -11
- package/build/bdd-framework/playwright/getLocationInFile.js +17 -11
- package/build/bdd-framework/playwright/loadConfig.js +3 -3
- package/build/bdd-framework/playwright/testTypeImpl.js +19 -15
- package/build/bdd-framework/playwright/transform.js +10 -6
- package/build/bdd-framework/playwright/utils.js +3 -6
- package/build/bdd-framework/run/StepInvoker.js +73 -0
- package/build/bdd-framework/run/bddFixtures.js +118 -55
- package/build/bdd-framework/run/bddWorld.js +24 -36
- package/build/bdd-framework/snippets/index.js +5 -3
- package/build/bdd-framework/snippets/snippetSyntax.js +3 -1
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
- package/build/bdd-framework/stepDefinitions/createBdd.js +30 -13
- package/build/bdd-framework/stepDefinitions/decorators/{poms.js → class.js} +13 -9
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +14 -8
- package/build/bdd-framework/stepDefinitions/defineStep.js +5 -4
- package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
- package/build/bdd-framework/utils/exit.js +26 -18
- package/build/bdd-framework/utils/index.js +30 -4
- package/build/bdd-framework/utils/jsStringWrap.js +9 -9
- package/build/bdd-framework/utils/logger.js +5 -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 -1
- package/build/core/playwright/index.js +6 -74
- package/build/core/playwright/readConfigFile.js +37 -30
- package/build/core/playwright/report-generator.js +2 -1
- package/build/core/playwright/setup/config-creator.js +43 -20
- package/build/core/playwright/setup/config-utils.js +30 -0
- 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 +8 -12
- package/build/index.d.ts +60 -5
- package/build/index.js +18 -12
- package/build/lib/cli.js +10 -1
- package/build/parser/sample.feature +34 -34
- package/build/parser/sample.spec.js +18 -18
- package/build/setup-folder-structure/helper.js +35 -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/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 +36 -32
- package/build/setup-folder-structure/samples/uat-config-sample.js +44 -43
- package/build/setup-folder-structure/setupProject.js +10 -5
- package/build/utils/cliArgsToObject.js +29 -25
- package/build/utils/fileUtils.js +15 -4
- package/changelog.md +137 -74
- package/jest.config.js +63 -63
- package/npm-shrinkwrap.json +6469 -7781
- package/package.json +55 -54
- package/playwright.config.js +112 -112
- 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 -108
- package/build/bdd-poc/core-runner/exportMethods.js +0 -20
- package/build/bdd-poc/core-runner/stepDefinitions.js +0 -53
- package/build/bdd-poc/main.js +0 -10
- package/build/bdd-poc/runner.js +0 -19
- package/build/bdd-poc/test/cucumber/featureFileParer.js +0 -81
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +0 -36
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +0 -43
- package/build/bdd-poc/test/testDataMap.js +0 -98
- package/build/bdd-poc/test/testStructure.js +0 -83
- package/build/bdd-poc/utils/stringManipulation.js +0 -19
|
@@ -6,58 +6,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.BddWorld = void 0;
|
|
7
7
|
exports.getWorldConstructor = getWorldConstructor;
|
|
8
8
|
var _cucumber = require("@cucumber/cucumber");
|
|
9
|
-
var _loadSteps = require("../cucumber/loadSteps");
|
|
10
|
-
var _getLocationInFile = require("../playwright/getLocationInFile");
|
|
11
|
-
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
12
|
-
var _defineStep = require("../stepDefinitions/defineStep");
|
|
13
9
|
class BddWorld extends _cucumber.World {
|
|
14
10
|
options;
|
|
15
|
-
|
|
16
|
-
customFixtures;
|
|
11
|
+
stepFixtures = {};
|
|
17
12
|
constructor(options) {
|
|
18
13
|
super(options);
|
|
19
14
|
this.options = options;
|
|
20
|
-
this.invokeStep = this.invokeStep.bind(this);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
world: this
|
|
42
|
-
});
|
|
43
|
-
const res = await (0, _testTypeImpl.runStepWithCustomLocation)(this.test, text, location, () => code.apply(this, parameters));
|
|
44
|
-
delete this.customFixtures;
|
|
45
|
-
return res;
|
|
16
|
+
/**
|
|
17
|
+
* Use particular fixture in cucumber-style steps.
|
|
18
|
+
*
|
|
19
|
+
* Note: TS does not support partial generic inference,
|
|
20
|
+
* that's why we can't use this.useFixture<typeof test>('xxx');
|
|
21
|
+
* The solution is to pass TestType as a generic to BddWorld
|
|
22
|
+
* and call useFixture without explicit generic params.
|
|
23
|
+
* Finally, it looks even better as there is no need to pass `typeof test`
|
|
24
|
+
* in every `this.useFixture` call.
|
|
25
|
+
*
|
|
26
|
+
* The downside - it's impossible to pass fixtures type directly to `this.useFixture`
|
|
27
|
+
* like it's done in @Fixture decorator.
|
|
28
|
+
*
|
|
29
|
+
* See: https://stackoverflow.com/questions/45509621/specify-only-first-type-argument
|
|
30
|
+
* See: https://github.com/Microsoft/TypeScript/pull/26349
|
|
31
|
+
*/
|
|
32
|
+
useFixture(fixtureName) {
|
|
33
|
+
return this.stepFixtures[fixtureName];
|
|
46
34
|
}
|
|
47
35
|
get page() {
|
|
48
|
-
return this.
|
|
36
|
+
return this.options.$bddWorldFixtures.page;
|
|
49
37
|
}
|
|
50
38
|
get context() {
|
|
51
|
-
return this.
|
|
39
|
+
return this.options.$bddWorldFixtures.context;
|
|
52
40
|
}
|
|
53
41
|
get browser() {
|
|
54
|
-
return this.
|
|
42
|
+
return this.options.$bddWorldFixtures.browser;
|
|
55
43
|
}
|
|
56
44
|
get browserName() {
|
|
57
|
-
return this.
|
|
45
|
+
return this.options.$bddWorldFixtures.browserName;
|
|
58
46
|
}
|
|
59
47
|
get request() {
|
|
60
|
-
return this.
|
|
48
|
+
return this.options.$bddWorldFixtures.request;
|
|
61
49
|
}
|
|
62
50
|
get testInfo() {
|
|
63
51
|
return this.options.testInfo;
|
|
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Snippets = void 0;
|
|
7
|
+
var _url = require("url");
|
|
7
8
|
var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
|
|
8
9
|
var _logger = require("../utils/logger");
|
|
9
10
|
var _stepConfig = require("../stepDefinitions/stepConfig");
|
|
10
|
-
/**
|
|
11
|
-
* Generate and show snippets for undefined steps
|
|
11
|
+
/**
|
|
12
|
+
* Generate and show snippets for undefined steps
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
class Snippets {
|
|
@@ -43,7 +44,8 @@ class Snippets {
|
|
|
43
44
|
} = this.runConfiguration.formats.options;
|
|
44
45
|
if (!snippetSyntax && this.isPlaywrightStyle()) {
|
|
45
46
|
this.bddBuiltInSyntax = true;
|
|
46
|
-
|
|
47
|
+
const filePath = this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
|
|
48
|
+
return (0, _url.pathToFileURL)(filePath).toString();
|
|
47
49
|
} else {
|
|
48
50
|
return snippetSyntax;
|
|
49
51
|
}
|
|
@@ -27,7 +27,9 @@ class _default {
|
|
|
27
27
|
});
|
|
28
28
|
const allParameterNames = ['{}', ...expressionParameters, ...stepParameters];
|
|
29
29
|
const functionSignature = `${functionName}('${this.escapeSpecialCharacters(generatedExpression)}', async (${allParameterNames.join(', ')}) => {`;
|
|
30
|
-
return [functionSignature,
|
|
30
|
+
return [functionSignature,
|
|
31
|
+
// prettier-ignore
|
|
32
|
+
` // ...`, '});'].join('\n');
|
|
31
33
|
}
|
|
32
34
|
escapeSpecialCharacters(generatedExpression) {
|
|
33
35
|
let source = generatedExpression.source;
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _snippetSyntax = _interopRequireDefault(require("./snippetSyntax"));
|
|
9
|
-
/**
|
|
10
|
-
* Playwright-style snippet syntax for typescript.
|
|
11
|
-
* Important to use separate file as it's simplest way to distinguish between js/ts
|
|
12
|
-
* without hooking into cucumber machinery.
|
|
9
|
+
/**
|
|
10
|
+
* Playwright-style snippet syntax for typescript.
|
|
11
|
+
* Important to use separate file as it's simplest way to distinguish between js/ts
|
|
12
|
+
* without hooking into cucumber machinery.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
class _default extends _snippetSyntax.default {
|
|
@@ -4,27 +4,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createBdd = createBdd;
|
|
7
|
-
exports.
|
|
8
|
-
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
7
|
+
exports.hasCustomTest = void 0;
|
|
9
8
|
var _bddFixtures = require("../run/bddFixtures");
|
|
10
9
|
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
11
10
|
var _defineStep = require("./defineStep");
|
|
12
11
|
var _exit = require("../utils/exit");
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var _scenario = require("../hooks/scenario");
|
|
13
|
+
var _worker = require("../hooks/worker");
|
|
14
|
+
/**
|
|
15
|
+
* Stuff related to writing steps in Playwright-style.
|
|
15
16
|
*/
|
|
16
17
|
|
|
18
|
+
// Global flag showing that custom test was passed.
|
|
19
|
+
// Used when checking 'importTestFrom' config option.
|
|
20
|
+
// todo: https://github.com/vitalets/playwright-bdd/issues/46
|
|
21
|
+
let hasCustomTest = exports.hasCustomTest = false;
|
|
17
22
|
function createBdd(customTest) {
|
|
18
|
-
|
|
23
|
+
if (!hasCustomTest) {
|
|
24
|
+
exports.hasCustomTest = hasCustomTest = isCustomTest(customTest);
|
|
25
|
+
}
|
|
19
26
|
const Given = defineStepCtor('Given', hasCustomTest);
|
|
20
27
|
const When = defineStepCtor('When', hasCustomTest);
|
|
21
28
|
const Then = defineStepCtor('Then', hasCustomTest);
|
|
22
29
|
const Step = defineStepCtor('Unknown', hasCustomTest);
|
|
30
|
+
const Before = (0, _scenario.scenarioHookFactory)('before');
|
|
31
|
+
const After = (0, _scenario.scenarioHookFactory)('after');
|
|
32
|
+
const BeforeAll = (0, _worker.workerHookFactory)('beforeAll');
|
|
33
|
+
const AfterAll = (0, _worker.workerHookFactory)('afterAll');
|
|
23
34
|
return {
|
|
24
35
|
Given,
|
|
25
36
|
When,
|
|
26
37
|
Then,
|
|
27
|
-
Step
|
|
38
|
+
Step,
|
|
39
|
+
Before,
|
|
40
|
+
After,
|
|
41
|
+
BeforeAll,
|
|
42
|
+
AfterAll
|
|
28
43
|
};
|
|
29
44
|
}
|
|
30
45
|
function defineStepCtor(keyword, hasCustomTest) {
|
|
@@ -37,13 +52,15 @@ function defineStepCtor(keyword, hasCustomTest) {
|
|
|
37
52
|
});
|
|
38
53
|
};
|
|
39
54
|
}
|
|
40
|
-
function extractFixtureNames(fn) {
|
|
41
|
-
return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
|
|
42
|
-
}
|
|
43
55
|
function isCustomTest(customTest) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
if (!customTest || customTest === _bddFixtures.test) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
assertTestHasBddFixtures(customTest);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function assertTestHasBddFixtures(customTest) {
|
|
63
|
+
if (!(0, _testTypeImpl.isTestContainsSubtest)(customTest, _bddFixtures.test)) {
|
|
64
|
+
(0, _exit.exit)(`createBdd() should use 'test' extended from "playwright-bdd"`);
|
|
47
65
|
}
|
|
48
|
-
return isCustomTest;
|
|
49
66
|
}
|
|
@@ -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
|
+
* Class level @Fixture decorator.
|
|
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,7 +51,9 @@ function ensureUniqueFixtureName({
|
|
|
51
51
|
}
|
|
52
52
|
function linkParentWithPomNode(Ctor, pomNode) {
|
|
53
53
|
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
54
|
-
if (!parentCtor)
|
|
54
|
+
if (!parentCtor) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
55
57
|
// if parentCtor is not in pomGraph, add it.
|
|
56
58
|
// Case: parent class is not marked with @Fixture, but has decorator steps (base class)
|
|
57
59
|
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
@@ -59,6 +61,8 @@ function linkParentWithPomNode(Ctor, pomNode) {
|
|
|
59
61
|
}
|
|
60
62
|
function getPomNodeByFixtureName(fixtureName) {
|
|
61
63
|
for (const pomNode of pomGraph.values()) {
|
|
62
|
-
if (pomNode.fixtureName === fixtureName)
|
|
64
|
+
if (pomNode.fixtureName === fixtureName) {
|
|
65
|
+
return pomNode;
|
|
66
|
+
}
|
|
63
67
|
}
|
|
64
68
|
}
|
|
@@ -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,17 +36,21 @@ function createStepDecorator(keyword) {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
function linkStepsWithPomNode(Ctor, pomNode) {
|
|
39
|
-
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype))
|
|
39
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
40
42
|
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
41
43
|
return Object.values(propertyDescriptors).forEach(descriptor => {
|
|
42
44
|
const stepConfig = getStepConfigFromMethod(descriptor);
|
|
43
|
-
if (!stepConfig)
|
|
45
|
+
if (!stepConfig) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
44
48
|
stepConfig.pomNode = pomNode;
|
|
45
49
|
decoratedSteps.add(stepConfig);
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
52
|
+
/**
|
|
53
|
+
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
50
54
|
*/
|
|
51
55
|
function appendDecoratorSteps(supportCodeLibrary) {
|
|
52
56
|
decoratedSteps.forEach(stepConfig => {
|
|
@@ -65,7 +69,9 @@ function appendDecoratorSteps(supportCodeLibrary) {
|
|
|
65
69
|
pattern,
|
|
66
70
|
code,
|
|
67
71
|
line: 0,
|
|
72
|
+
// not used in playwright-bdd
|
|
68
73
|
options: {},
|
|
74
|
+
// not used in playwright-bdd
|
|
69
75
|
uri: '' // not used in playwright-bdd
|
|
70
76
|
}, supportCodeLibrary);
|
|
71
77
|
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,7 +34,8 @@ function defineStep(stepConfig) {
|
|
|
34
34
|
}
|
|
35
35
|
function buildCucumberStepCode(stepConfig) {
|
|
36
36
|
const code = function (...args) {
|
|
37
|
-
|
|
37
|
+
// build the first argument (fixtures) for step fn
|
|
38
|
+
const fixturesArg = Object.assign({}, this.stepFixtures, {
|
|
38
39
|
$testInfo: this.testInfo,
|
|
39
40
|
$test: this.test,
|
|
40
41
|
$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");
|
|
9
8
|
var _worker_threads = require("worker_threads");
|
|
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
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* - https://github.com/nodejs/node
|
|
25
|
-
* - https://github.com/
|
|
9
|
+
/**
|
|
10
|
+
* Exit utils.
|
|
11
|
+
*
|
|
12
|
+
* When calling process.exit() in worker thread used for test-file generation,
|
|
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
|
+
* This esnured by wrapping code with withExitHandler().
|
|
17
|
+
*
|
|
18
|
+
* On the other hand, when running in the 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,6 +35,10 @@ 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
|
+
}
|
|
38
42
|
process.exitCode = 1;
|
|
39
43
|
} else {
|
|
40
44
|
throw e;
|
|
@@ -44,8 +48,12 @@ async function withExitHandler(fn) {
|
|
|
44
48
|
function exit(...messages) {
|
|
45
49
|
messages = messages.filter(Boolean);
|
|
46
50
|
if (_worker_threads.isMainThread) {
|
|
51
|
+
// use console.error() here instead of logger.error() to have less stack
|
|
52
|
+
// for flushing messages to stderr.
|
|
53
|
+
|
|
47
54
|
if (messages.length) {
|
|
48
|
-
|
|
55
|
+
// eslint-disable-next-line no-console, max-depth
|
|
56
|
+
console.error('Error:', ...messages);
|
|
49
57
|
}
|
|
50
58
|
process.exit(1);
|
|
51
59
|
} else {
|
|
@@ -4,6 +4,8 @@ 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;
|
|
7
9
|
exports.getPackageVersion = getPackageVersion;
|
|
8
10
|
exports.getSymbolByName = getSymbolByName;
|
|
9
11
|
exports.removeDuplicates = removeDuplicates;
|
|
@@ -11,7 +13,12 @@ exports.resolvePackageRoot = resolvePackageRoot;
|
|
|
11
13
|
exports.template = template;
|
|
12
14
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
15
|
var _path = _interopRequireDefault(require("path"));
|
|
14
|
-
|
|
16
|
+
var _util = require("util");
|
|
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
|
+
*/
|
|
15
22
|
function getSymbolByName(target, name) {
|
|
16
23
|
const ownKeys = Reflect.ownKeys(target);
|
|
17
24
|
const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
|
|
@@ -20,15 +27,22 @@ function getSymbolByName(target, name) {
|
|
|
20
27
|
}
|
|
21
28
|
return symbol;
|
|
22
29
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Inserts params into template.
|
|
25
|
-
* Params defined as <param>.
|
|
30
|
+
/**
|
|
31
|
+
* Inserts params into template.
|
|
32
|
+
* Params defined as <param>.
|
|
26
33
|
*/
|
|
27
34
|
function template(t, params = {}) {
|
|
28
35
|
return t.replace(/<(.+?)>/g, (match, key) => {
|
|
29
36
|
return params[key] !== undefined ? String(params[key]) : match;
|
|
30
37
|
});
|
|
31
38
|
}
|
|
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
|
+
}
|
|
32
46
|
function removeDuplicates(arr) {
|
|
33
47
|
return [...new Set(arr)];
|
|
34
48
|
}
|
|
@@ -41,4 +55,16 @@ function getPackageVersion(packageName) {
|
|
|
41
55
|
const packageJsonPath = _path.default.join(packageRoot, 'package.json');
|
|
42
56
|
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
43
57
|
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());
|
|
44
70
|
}
|
|
@@ -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,7 +13,9 @@ class Logger {
|
|
|
13
13
|
this.options = options;
|
|
14
14
|
}
|
|
15
15
|
log(...args) {
|
|
16
|
-
if (this.options.verbose)
|
|
16
|
+
if (this.options.verbose) {
|
|
17
|
+
console.log(...args);
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
20
|
warn(...args) {
|
|
19
21
|
// using log() to output warnings to stdout, not stderr
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
addTags: [async ({
|
|
9
|
+
$tags
|
|
10
|
+
}, use, testInfo) => {
|
|
11
|
+
testInfo.annotations.push({
|
|
12
|
+
type: 'tags',
|
|
13
|
+
description: $tags.join(', ')
|
|
14
|
+
});
|
|
15
|
+
await use();
|
|
16
|
+
}, {
|
|
17
|
+
auto: true
|
|
18
|
+
}]
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const cacheMap = new Map();
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
// eslint-disable-next-line no-empty-pattern
|
|
10
|
+
cacheLayer: async ({}, use) => {
|
|
11
|
+
await use(cacheMap);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
context: async ({
|
|
9
|
+
context
|
|
10
|
+
}, use) => {
|
|
11
|
+
// eslint-disable-next-line no-undef
|
|
12
|
+
await context.addInitScript(() => window.localStorage.setItem('isDnBannerHide', true));
|
|
13
|
+
await use(context);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _page = _interopRequireDefault(require("./page"));
|
|
9
|
+
var _context = _interopRequireDefault(require("./context"));
|
|
10
|
+
var _cacheLayer = _interopRequireDefault(require("./cacheLayer"));
|
|
11
|
+
var _addTags = _interopRequireDefault(require("./addTags"));
|
|
12
|
+
function getBuiltInFixtures(bddMode) {
|
|
13
|
+
let builtInFixtures = {
|
|
14
|
+
..._page.default,
|
|
15
|
+
..._context.default,
|
|
16
|
+
..._cacheLayer.default
|
|
17
|
+
};
|
|
18
|
+
if (bddMode) {
|
|
19
|
+
builtInFixtures = {
|
|
20
|
+
...builtInFixtures,
|
|
21
|
+
..._addTags.default
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return builtInFixtures;
|
|
25
|
+
}
|
|
26
|
+
var _default = exports.default = getBuiltInFixtures;
|