@zohodesk/testinglibrary 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -1
- package/build/bdd-framework/cli/commands/env.js +1 -1
- package/build/bdd-framework/cli/commands/test.js +9 -3
- package/build/bdd-framework/config/env.js +2 -1
- package/build/bdd-framework/config/lang.js +14 -0
- 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 +57 -10
- package/build/bdd-framework/gen/i18n.js +6 -2
- package/build/bdd-framework/gen/index.js +7 -6
- package/build/bdd-framework/gen/testFile.js +105 -39
- package/build/bdd-framework/gen/testNode.js +16 -3
- package/build/bdd-framework/gen/testPoms.js +18 -8
- package/build/bdd-framework/hooks/scenario.js +107 -0
- package/build/bdd-framework/hooks/worker.js +83 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +24 -8
- package/build/bdd-framework/playwright/getLocationInFile.js +13 -7
- package/build/bdd-framework/playwright/testTypeImpl.js +11 -7
- package/build/bdd-framework/playwright/transform.js +6 -2
- package/build/bdd-framework/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 +3 -1
- package/build/bdd-framework/snippets/snippetSyntax.js +3 -1
- package/build/bdd-framework/stepDefinitions/createBdd.js +28 -11
- package/build/bdd-framework/stepDefinitions/decorators/{poms.js → class.js} +7 -3
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +8 -2
- package/build/bdd-framework/stepDefinitions/defineStep.js +2 -1
- package/build/bdd-framework/utils/exit.js +14 -4
- package/build/bdd-framework/utils/index.js +27 -1
- package/build/bdd-framework/utils/logger.js +3 -1
- package/build/core/playwright/index.js +12 -3
- package/build/core/playwright/report-generator.js +2 -1
- package/build/core/playwright/setup/config-creator.js +5 -0
- package/build/core/playwright/tag-processor.js +6 -2
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
- package/changelog.md +10 -0
- package/npm-shrinkwrap.json +1 -1
- package/package.json +1 -1
- 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
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.TestPoms = void 0;
|
|
7
7
|
exports.buildFixtureTag = buildFixtureTag;
|
|
8
|
-
var
|
|
8
|
+
var _class = require("../stepDefinitions/decorators/class");
|
|
9
9
|
var _exit = require("../utils/exit");
|
|
10
10
|
/**
|
|
11
11
|
* Track PomNodes used in the particular test.
|
|
@@ -44,7 +44,7 @@ class TestPoms {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
addByFixtureName(fixtureName) {
|
|
47
|
-
const pomNode = (0,
|
|
47
|
+
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
48
48
|
this.addUsedPom(pomNode, {
|
|
49
49
|
byTag: false
|
|
50
50
|
});
|
|
@@ -52,7 +52,7 @@ class TestPoms {
|
|
|
52
52
|
addByTag(tag) {
|
|
53
53
|
const fixtureName = extractFixtureName(tag);
|
|
54
54
|
if (fixtureName) {
|
|
55
|
-
const pomNode = (0,
|
|
55
|
+
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
56
56
|
this.addUsedPom(pomNode, {
|
|
57
57
|
byTag: true
|
|
58
58
|
});
|
|
@@ -73,10 +73,14 @@ class TestPoms {
|
|
|
73
73
|
*/
|
|
74
74
|
getResolvedFixtures(pomNode) {
|
|
75
75
|
const usedPom = this.usedPoms.get(pomNode);
|
|
76
|
-
if (usedPom !== null && usedPom !== void 0 && usedPom.fixtures)
|
|
76
|
+
if (usedPom !== null && usedPom !== void 0 && usedPom.fixtures) {
|
|
77
|
+
return usedPom.fixtures;
|
|
78
|
+
}
|
|
77
79
|
// Recursively resolve children fixtures, used in test.
|
|
78
80
|
let childFixtures = [...pomNode.children].map(child => this.getResolvedFixtures(child)).flat();
|
|
79
|
-
if (!usedPom)
|
|
81
|
+
if (!usedPom) {
|
|
82
|
+
return childFixtures;
|
|
83
|
+
}
|
|
80
84
|
if (childFixtures.length) {
|
|
81
85
|
this.verifyChildFixtures(pomNode, usedPom, childFixtures);
|
|
82
86
|
usedPom.fixtures = childFixtures;
|
|
@@ -91,10 +95,14 @@ class TestPoms {
|
|
|
91
95
|
addUsedPom(pomNode, {
|
|
92
96
|
byTag
|
|
93
97
|
}) {
|
|
94
|
-
if (!pomNode)
|
|
98
|
+
if (!pomNode) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
95
101
|
const usedPom = this.usedPoms.get(pomNode);
|
|
96
102
|
if (usedPom) {
|
|
97
|
-
if (byTag && !usedPom.byTag)
|
|
103
|
+
if (byTag && !usedPom.byTag) {
|
|
104
|
+
usedPom.byTag = true;
|
|
105
|
+
}
|
|
98
106
|
} else {
|
|
99
107
|
this.usedPoms.set(pomNode, {
|
|
100
108
|
byTag
|
|
@@ -107,7 +115,9 @@ class TestPoms {
|
|
|
107
115
|
* @fixture:xxx tag provides maximum fixture that can be used in the scenario.
|
|
108
116
|
*/
|
|
109
117
|
verifyChildFixtures(pomNode, usedPom, childFixtures) {
|
|
110
|
-
if (!usedPom.byTag)
|
|
118
|
+
if (!usedPom.byTag) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
111
121
|
const childFixturesBySteps = childFixtures.filter(f => !f.byTag);
|
|
112
122
|
if (childFixturesBySteps.length) {
|
|
113
123
|
(0, _exit.exit)(`Scenario "${this.title}" contains ${childFixturesBySteps.length} step(s)`, `not compatible with required fixture "${pomNode.fixtureName}"`);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getScenarioHooksFixtures = getScenarioHooksFixtures;
|
|
8
|
+
exports.hasScenarioHooks = hasScenarioHooks;
|
|
9
|
+
exports.runScenarioHooks = runScenarioHooks;
|
|
10
|
+
exports.scenarioHookFactory = scenarioHookFactory;
|
|
11
|
+
var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
|
|
12
|
+
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
13
|
+
var _utils = require("../utils");
|
|
14
|
+
/**
|
|
15
|
+
* Scenario level hooks: Before / After.
|
|
16
|
+
*
|
|
17
|
+
* before(async ({ page }) => {})
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const scenarioHooks = [];
|
|
21
|
+
let scenarioHooksFixtures;
|
|
22
|
+
/**
|
|
23
|
+
* Returns Before() / After() functions.
|
|
24
|
+
*/
|
|
25
|
+
function scenarioHookFactory(type) {
|
|
26
|
+
return (...args) => {
|
|
27
|
+
addHook({
|
|
28
|
+
type,
|
|
29
|
+
options: getOptionsFromArgs(args),
|
|
30
|
+
fn: getFnFromArgs(args)
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function hasScenarioHooks() {
|
|
35
|
+
return scenarioHooks.length > 0;
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line complexity
|
|
38
|
+
async function runScenarioHooks(type, fixtures) {
|
|
39
|
+
let error;
|
|
40
|
+
for (const hook of scenarioHooks) {
|
|
41
|
+
if (hook.type !== type) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (hook.tagsExpression && !hook.tagsExpression.evaluate(fixtures.$tags)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const {
|
|
48
|
+
timeout
|
|
49
|
+
} = hook.options;
|
|
50
|
+
try {
|
|
51
|
+
await (0, _utils.callWithTimeout)(() => hook.fn.call(fixtures.$bddWorld, fixtures), timeout, `${type} hook timeout (${timeout} ms)`);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (type === 'before') {
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
if (!error) {
|
|
57
|
+
error = e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function getScenarioHooksFixtures() {
|
|
66
|
+
if (!scenarioHooksFixtures) {
|
|
67
|
+
const fixturesFakeObj = {
|
|
68
|
+
$bddWorld: null,
|
|
69
|
+
$tags: null,
|
|
70
|
+
$testInfo: null
|
|
71
|
+
};
|
|
72
|
+
const set = new Set();
|
|
73
|
+
scenarioHooks.forEach(hook => {
|
|
74
|
+
(0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
|
|
75
|
+
});
|
|
76
|
+
scenarioHooksFixtures = [...set];
|
|
77
|
+
}
|
|
78
|
+
return scenarioHooksFixtures;
|
|
79
|
+
}
|
|
80
|
+
function getOptionsFromArgs(args) {
|
|
81
|
+
if (typeof args[0] === 'string') {
|
|
82
|
+
return {
|
|
83
|
+
tags: args[0]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (typeof args[0] === 'object') {
|
|
87
|
+
return args[0];
|
|
88
|
+
}
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
function getFnFromArgs(args) {
|
|
92
|
+
return args.length === 1 ? args[0] : args[1];
|
|
93
|
+
}
|
|
94
|
+
function setTagsExpression(hook) {
|
|
95
|
+
if (hook.options.tags) {
|
|
96
|
+
hook.tagsExpression = (0, _tagExpressions.default)(hook.options.tags);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function addHook(hook) {
|
|
100
|
+
setTagsExpression(hook);
|
|
101
|
+
if (hook.type === 'before') {
|
|
102
|
+
scenarioHooks.push(hook);
|
|
103
|
+
} else {
|
|
104
|
+
// 'after' hooks run in reverse order
|
|
105
|
+
scenarioHooks.unshift(hook);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getWorkerHooksFixtures = getWorkerHooksFixtures;
|
|
7
|
+
exports.runWorkerHooks = runWorkerHooks;
|
|
8
|
+
exports.workerHookFactory = workerHookFactory;
|
|
9
|
+
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
/**
|
|
12
|
+
* Worker-level hooks: BeforeAll / AfterAll.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const workerHooks = [];
|
|
16
|
+
let workerHooksFixtures;
|
|
17
|
+
/**
|
|
18
|
+
* Returns BeforeAll() / AfterAll() functions.
|
|
19
|
+
*/
|
|
20
|
+
function workerHookFactory(type) {
|
|
21
|
+
return (...args) => {
|
|
22
|
+
addHook({
|
|
23
|
+
type,
|
|
24
|
+
options: getOptionsFromArgs(args),
|
|
25
|
+
fn: getFnFromArgs(args)
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line complexity
|
|
30
|
+
async function runWorkerHooks(type, fixtures) {
|
|
31
|
+
let error;
|
|
32
|
+
for (const hook of workerHooks) {
|
|
33
|
+
if (hook.type !== type) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const {
|
|
37
|
+
timeout
|
|
38
|
+
} = hook.options;
|
|
39
|
+
try {
|
|
40
|
+
await (0, _utils.callWithTimeout)(() => hook.fn(fixtures), timeout, `${type} hook timeout (${timeout} ms)`);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (type === 'beforeAll') {
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
if (!error) {
|
|
46
|
+
error = e;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (error) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getWorkerHooksFixtures() {
|
|
55
|
+
if (!workerHooksFixtures) {
|
|
56
|
+
const fixturesFakeObj = {
|
|
57
|
+
$workerInfo: null
|
|
58
|
+
};
|
|
59
|
+
const set = new Set();
|
|
60
|
+
workerHooks.forEach(hook => {
|
|
61
|
+
(0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
|
|
62
|
+
});
|
|
63
|
+
workerHooksFixtures = [...set];
|
|
64
|
+
}
|
|
65
|
+
return workerHooksFixtures;
|
|
66
|
+
}
|
|
67
|
+
function getOptionsFromArgs(args) {
|
|
68
|
+
if (typeof args[0] === 'object') {
|
|
69
|
+
return args[0];
|
|
70
|
+
}
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
function getFnFromArgs(args) {
|
|
74
|
+
return args.length === 1 ? args[0] : args[1];
|
|
75
|
+
}
|
|
76
|
+
function addHook(hook) {
|
|
77
|
+
if (hook.type === 'beforeAll') {
|
|
78
|
+
workerHooks.push(hook);
|
|
79
|
+
} else {
|
|
80
|
+
// 'afterAll' hooks run in reverse order
|
|
81
|
+
workerHooks.unshift(hook);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -11,16 +11,24 @@ exports.fixtureParameterNames = fixtureParameterNames;
|
|
|
11
11
|
/* eslint-disable max-statements, complexity, max-len, max-depth */
|
|
12
12
|
const signatureSymbol = Symbol('signature');
|
|
13
13
|
function fixtureParameterNames(fn) {
|
|
14
|
-
if (typeof fn !== 'function')
|
|
15
|
-
|
|
14
|
+
if (typeof fn !== 'function') {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (!fn[signatureSymbol]) {
|
|
18
|
+
fn[signatureSymbol] = innerFixtureParameterNames(fn);
|
|
19
|
+
}
|
|
16
20
|
return fn[signatureSymbol];
|
|
17
21
|
}
|
|
18
22
|
function innerFixtureParameterNames(fn) {
|
|
19
23
|
const text = filterOutComments(fn.toString());
|
|
20
24
|
const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
|
|
21
|
-
if (!match)
|
|
25
|
+
if (!match) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
22
28
|
const trimmedParams = match[1].trim();
|
|
23
|
-
if (!trimmedParams)
|
|
29
|
+
if (!trimmedParams) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
24
32
|
const [firstParam] = splitByComma(trimmedParams);
|
|
25
33
|
if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
|
|
26
34
|
throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
|
|
@@ -40,9 +48,13 @@ function filterOutComments(s) {
|
|
|
40
48
|
let commentState = 'none';
|
|
41
49
|
for (let i = 0; i < s.length; ++i) {
|
|
42
50
|
if (commentState === 'singleline') {
|
|
43
|
-
if (s[i] === '\n')
|
|
51
|
+
if (s[i] === '\n') {
|
|
52
|
+
commentState = 'none';
|
|
53
|
+
}
|
|
44
54
|
} else if (commentState === 'multiline') {
|
|
45
|
-
if (s[i - 1] === '*' && s[i] === '/')
|
|
55
|
+
if (s[i - 1] === '*' && s[i] === '/') {
|
|
56
|
+
commentState = 'none';
|
|
57
|
+
}
|
|
46
58
|
} else if (commentState === 'none') {
|
|
47
59
|
if (s[i] === '/' && s[i + 1] === '/') {
|
|
48
60
|
commentState = 'singleline';
|
|
@@ -67,11 +79,15 @@ function splitByComma(s) {
|
|
|
67
79
|
stack.pop();
|
|
68
80
|
} else if (!stack.length && s[i] === ',') {
|
|
69
81
|
const token = s.substring(start, i).trim();
|
|
70
|
-
if (token)
|
|
82
|
+
if (token) {
|
|
83
|
+
result.push(token);
|
|
84
|
+
}
|
|
71
85
|
start = i + 1;
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
const lastToken = s.substring(start).trim();
|
|
75
|
-
if (lastToken)
|
|
89
|
+
if (lastToken) {
|
|
90
|
+
result.push(lastToken);
|
|
91
|
+
}
|
|
76
92
|
return result;
|
|
77
93
|
}
|
|
@@ -13,21 +13,27 @@ var _utils = require("./utils");
|
|
|
13
13
|
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
|
|
14
14
|
*/
|
|
15
15
|
function getLocationInFile(filePath) {
|
|
16
|
+
const filePathUrl = _url.default.pathToFileURL(filePath).toString();
|
|
16
17
|
const {
|
|
17
18
|
sourceMapSupport
|
|
18
19
|
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
19
20
|
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
20
21
|
Error.prepareStackTrace = (error, stackFrames) => {
|
|
21
|
-
const frameInFile = stackFrames.find(frame =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const frameInFile = stackFrames.find(frame => {
|
|
23
|
+
const frameFile = frame.getFileName();
|
|
24
|
+
return frameFile === filePath || frameFile === filePathUrl;
|
|
25
|
+
});
|
|
26
|
+
if (!frameInFile) {
|
|
27
|
+
return {
|
|
28
|
+
file: '',
|
|
29
|
+
line: 0,
|
|
30
|
+
column: 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
27
33
|
const frame = sourceMapSupport.wrapCallSite(frameInFile);
|
|
28
34
|
const fileName = frame.getFileName();
|
|
29
35
|
// Node error stacks for modules use file:// urls instead of paths.
|
|
30
|
-
const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
|
|
36
|
+
const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
|
|
31
37
|
return {
|
|
32
38
|
file,
|
|
33
39
|
line: frame.getLineNumber(),
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.isTestContainsSubtest = isTestContainsSubtest;
|
|
7
7
|
exports.runStepWithCustomLocation = runStepWithCustomLocation;
|
|
8
8
|
var _test = require("@playwright/test");
|
|
9
9
|
var _utils = require("../utils");
|
|
@@ -39,13 +39,17 @@ async function runStepWithCustomLocation(test, stepText, location, body) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Returns true if all fixtures of
|
|
42
|
+
* Returns true if test contains all fixtures of subtest.
|
|
43
|
+
* - test was extended from subtest
|
|
44
|
+
* - test is a result of mergeTests(subtest, ...)
|
|
43
45
|
*/
|
|
44
|
-
function
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
function isTestContainsSubtest(test, subtest) {
|
|
47
|
+
if (test === subtest) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const testFixtures = new Set(getTestFixtures(test).map(f => locationToString(f.location)));
|
|
51
|
+
return getTestFixtures(subtest).every(f => {
|
|
52
|
+
return testFixtures.has(locationToString(f.location));
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
function locationToString({
|
|
@@ -30,13 +30,17 @@ function installTransform() {
|
|
|
30
30
|
function resolveFilename(specifier, parent, ...rest) {
|
|
31
31
|
if (!reverted && parent) {
|
|
32
32
|
const resolved = resolveHook(parent.filename, specifier);
|
|
33
|
-
if (resolved !== undefined)
|
|
33
|
+
if (resolved !== undefined) {
|
|
34
|
+
specifier = resolved;
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
return originalResolveFilename.call(this, specifier, parent, ...rest);
|
|
36
38
|
}
|
|
37
39
|
_module.default._resolveFilename = resolveFilename;
|
|
38
40
|
const revertPirates = pirates.addHook((code, filename) => {
|
|
39
|
-
if (!shouldTransform(filename))
|
|
41
|
+
if (!shouldTransform(filename)) {
|
|
42
|
+
return code;
|
|
43
|
+
}
|
|
40
44
|
return transformHook(code, filename);
|
|
41
45
|
}, {
|
|
42
46
|
exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StepInvoker = void 0;
|
|
7
|
+
var _loadSteps = require("../cucumber/loadSteps");
|
|
8
|
+
var _getLocationInFile = require("../playwright/getLocationInFile");
|
|
9
|
+
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
10
|
+
var _defineStep = require("../stepDefinitions/defineStep");
|
|
11
|
+
var _lang = require("../config/lang");
|
|
12
|
+
/**
|
|
13
|
+
* Class to invoke steps in generated files.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class StepInvoker {
|
|
17
|
+
world;
|
|
18
|
+
keyword;
|
|
19
|
+
text = '';
|
|
20
|
+
argument;
|
|
21
|
+
constructor(world, keyword) {
|
|
22
|
+
this.world = world;
|
|
23
|
+
this.keyword = keyword;
|
|
24
|
+
this.invoke = this.invoke.bind(this);
|
|
25
|
+
}
|
|
26
|
+
async invoke(text, argument, stepFixtures) {
|
|
27
|
+
this.text = text;
|
|
28
|
+
this.argument = argument;
|
|
29
|
+
const {
|
|
30
|
+
world
|
|
31
|
+
} = this;
|
|
32
|
+
world.stepFixtures = stepFixtures || {};
|
|
33
|
+
const stepDefinition = this.getStepDefinition();
|
|
34
|
+
// Get location of step call in generated test file.
|
|
35
|
+
// This call must be exactly here to have correct call stack (before async calls)
|
|
36
|
+
const location = (0, _getLocationInFile.getLocationInFile)(world.test.info().file);
|
|
37
|
+
const stepTitle = this.getStepTitle();
|
|
38
|
+
const code = (0, _defineStep.getStepCode)(stepDefinition);
|
|
39
|
+
const parameters = await this.getStepParameters(stepDefinition);
|
|
40
|
+
return (0, _testTypeImpl.runStepWithCustomLocation)(world.test, stepTitle, location, () => code.apply(world, parameters));
|
|
41
|
+
}
|
|
42
|
+
getStepDefinition() {
|
|
43
|
+
const stepDefinition = (0, _loadSteps.findStepDefinition)(this.world.options.supportCodeLibrary, this.text, this.world.testInfo.file);
|
|
44
|
+
if (!stepDefinition) {
|
|
45
|
+
throw new Error(`Undefined step: "${this.text}"`);
|
|
46
|
+
}
|
|
47
|
+
return stepDefinition;
|
|
48
|
+
}
|
|
49
|
+
async getStepParameters(stepDefinition) {
|
|
50
|
+
const {
|
|
51
|
+
text,
|
|
52
|
+
argument,
|
|
53
|
+
world
|
|
54
|
+
} = this;
|
|
55
|
+
const {
|
|
56
|
+
parameters
|
|
57
|
+
} = await stepDefinition.getInvocationParameters({
|
|
58
|
+
hookParameter: {},
|
|
59
|
+
step: {
|
|
60
|
+
text,
|
|
61
|
+
argument
|
|
62
|
+
},
|
|
63
|
+
world
|
|
64
|
+
});
|
|
65
|
+
return parameters;
|
|
66
|
+
}
|
|
67
|
+
getStepTitle() {
|
|
68
|
+
// Currently prepend keyword only for English.
|
|
69
|
+
// For other langs it's more complex as we need to pass original keyword from step.
|
|
70
|
+
return (0, _lang.isEnglish)(this.world.options.lang) ? `${this.keyword} ${this.text}` : this.text;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.StepInvoker = StepInvoker;
|
|
@@ -13,12 +13,15 @@ var _config = require("../config");
|
|
|
13
13
|
var _env = require("../config/env");
|
|
14
14
|
var _steps = require("../stepDefinitions/decorators/steps");
|
|
15
15
|
var _dir = require("../config/dir");
|
|
16
|
+
var _scenario = require("../hooks/scenario");
|
|
17
|
+
var _worker = require("../hooks/worker");
|
|
18
|
+
var _StepInvoker = require("./StepInvoker");
|
|
16
19
|
const test = exports.test = _test.test.extend({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, use,
|
|
21
|
-
const config = (0, _env.getConfigFromEnv)(
|
|
20
|
+
// load cucumber once per worker (auto-fixture)
|
|
21
|
+
// todo: maybe remove caching in cucumber/loadConfig.ts and cucumber/loadSteps.ts
|
|
22
|
+
// as we call it once per worker. Check generation phase.
|
|
23
|
+
$cucumber: [async ({}, use, workerInfo) => {
|
|
24
|
+
const config = (0, _env.getConfigFromEnv)(workerInfo.project.testDir);
|
|
22
25
|
const environment = {
|
|
23
26
|
cwd: (0, _dir.getPlaywrightConfigDir)()
|
|
24
27
|
};
|
|
@@ -30,11 +33,37 @@ const test = exports.test = _test.test.extend({
|
|
|
30
33
|
const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
|
|
31
34
|
(0, _steps.appendDecoratorSteps)(supportCodeLibrary);
|
|
32
35
|
const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
|
|
36
|
+
await use({
|
|
37
|
+
runConfiguration,
|
|
38
|
+
supportCodeLibrary,
|
|
39
|
+
World
|
|
40
|
+
});
|
|
41
|
+
}, {
|
|
42
|
+
auto: true,
|
|
43
|
+
scope: 'worker'
|
|
44
|
+
}],
|
|
45
|
+
$lang: ({}, use) => use(''),
|
|
46
|
+
// init $bddWorldFixtures with empty object, will be owerwritten in test file for cucumber-style
|
|
47
|
+
$bddWorldFixtures: ({}, use) => use({}),
|
|
48
|
+
$bddWorld: async ({
|
|
49
|
+
$tags,
|
|
50
|
+
$test,
|
|
51
|
+
$bddWorldFixtures,
|
|
52
|
+
$cucumber,
|
|
53
|
+
$lang
|
|
54
|
+
}, use, testInfo) => {
|
|
55
|
+
const {
|
|
56
|
+
runConfiguration,
|
|
57
|
+
supportCodeLibrary,
|
|
58
|
+
World
|
|
59
|
+
} = $cucumber;
|
|
33
60
|
const world = new World({
|
|
34
61
|
testInfo,
|
|
35
62
|
supportCodeLibrary,
|
|
36
63
|
$tags,
|
|
37
64
|
$test,
|
|
65
|
+
$bddWorldFixtures,
|
|
66
|
+
lang: $lang,
|
|
38
67
|
parameters: runConfiguration.runtime.worldParameters || {},
|
|
39
68
|
log: () => {},
|
|
40
69
|
attach: async () => {}
|
|
@@ -43,63 +72,97 @@ const test = exports.test = _test.test.extend({
|
|
|
43
72
|
await use(world);
|
|
44
73
|
await world.destroy();
|
|
45
74
|
},
|
|
46
|
-
$bddWorld: async ({
|
|
47
|
-
$bddWorldBase,
|
|
48
|
-
page,
|
|
49
|
-
context,
|
|
50
|
-
browser,
|
|
51
|
-
browserName,
|
|
52
|
-
request
|
|
53
|
-
}, use) => {
|
|
54
|
-
$bddWorldBase.builtinFixtures = {
|
|
55
|
-
page,
|
|
56
|
-
context,
|
|
57
|
-
browser,
|
|
58
|
-
browserName,
|
|
59
|
-
request
|
|
60
|
-
};
|
|
61
|
-
await use($bddWorldBase);
|
|
62
|
-
},
|
|
63
|
-
// below fixtures are used in playwright-style
|
|
64
|
-
// and does not automatically init Playwright builtin fixtures
|
|
65
75
|
Given: ({
|
|
66
|
-
$bddWorldBase
|
|
67
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
68
|
-
When: ({
|
|
69
|
-
$bddWorldBase
|
|
70
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
71
|
-
Then: ({
|
|
72
|
-
$bddWorldBase
|
|
73
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
74
|
-
And: ({
|
|
75
|
-
$bddWorldBase
|
|
76
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
77
|
-
But: ({
|
|
78
|
-
$bddWorldBase
|
|
79
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
80
|
-
// below fixtures are used in cucumber-style
|
|
81
|
-
// and automatically init Playwright builtin fixtures
|
|
82
|
-
Given_: ({
|
|
83
76
|
$bddWorld
|
|
84
|
-
}, use) => use($bddWorld.
|
|
85
|
-
|
|
77
|
+
}, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Given').invoke),
|
|
78
|
+
When: ({
|
|
86
79
|
$bddWorld
|
|
87
|
-
}, use) => use($bddWorld.
|
|
88
|
-
|
|
80
|
+
}, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'When').invoke),
|
|
81
|
+
Then: ({
|
|
89
82
|
$bddWorld
|
|
90
|
-
}, use) => use($bddWorld.
|
|
91
|
-
|
|
83
|
+
}, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Then').invoke),
|
|
84
|
+
And: ({
|
|
92
85
|
$bddWorld
|
|
93
|
-
}, use) => use($bddWorld.
|
|
94
|
-
|
|
86
|
+
}, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'And').invoke),
|
|
87
|
+
But: ({
|
|
95
88
|
$bddWorld
|
|
96
|
-
}, use) => use($bddWorld.
|
|
97
|
-
//
|
|
98
|
-
// eslint-disable-next-line
|
|
89
|
+
}, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'But').invoke),
|
|
90
|
+
// init $tags with empty array, can be owerwritten in test file
|
|
99
91
|
$tags: ({}, use) => use([]),
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
// init $test with base test, but it will be always overwritten in test file
|
|
93
|
+
$test: ({}, use) => use(_test.test),
|
|
94
|
+
// can be owerwritten in test file if there are scenario hooks
|
|
95
|
+
$scenarioHookFixtures: ({}, use) => use({}),
|
|
96
|
+
$before: [
|
|
97
|
+
// Unused dependencies are important:
|
|
98
|
+
// 1. $beforeAll / $afterAll: in pw < 1.39 worker-scoped auto-fixtures were called after test-scoped
|
|
99
|
+
// 2. $after: to call after hooks in case of errors in before hooks
|
|
100
|
+
async ({
|
|
101
|
+
$scenarioHookFixtures,
|
|
102
|
+
$bddWorld,
|
|
103
|
+
$tags,
|
|
104
|
+
$beforeAll,
|
|
105
|
+
$afterAll,
|
|
106
|
+
$after
|
|
107
|
+
}, use, $testInfo) => {
|
|
108
|
+
await (0, _scenario.runScenarioHooks)('before', {
|
|
109
|
+
$bddWorld,
|
|
110
|
+
$tags,
|
|
111
|
+
$testInfo,
|
|
112
|
+
...$scenarioHookFixtures
|
|
113
|
+
});
|
|
114
|
+
await use();
|
|
115
|
+
}, {
|
|
116
|
+
auto: true
|
|
117
|
+
}],
|
|
118
|
+
$after: [async ({
|
|
119
|
+
$scenarioHookFixtures,
|
|
120
|
+
$bddWorld,
|
|
121
|
+
$tags
|
|
122
|
+
}, use, $testInfo) => {
|
|
123
|
+
await use();
|
|
124
|
+
await (0, _scenario.runScenarioHooks)('after', {
|
|
125
|
+
$bddWorld,
|
|
126
|
+
$tags,
|
|
127
|
+
$testInfo,
|
|
128
|
+
...$scenarioHookFixtures
|
|
129
|
+
});
|
|
130
|
+
}, {
|
|
131
|
+
auto: true
|
|
132
|
+
}],
|
|
133
|
+
// can be owerwritten in test file if there are worker hooks
|
|
134
|
+
$workerHookFixtures: [({}, use) => use({}), {
|
|
135
|
+
scope: 'worker'
|
|
136
|
+
}],
|
|
137
|
+
$beforeAll: [
|
|
138
|
+
// Important unused dependencies:
|
|
139
|
+
// 1. $afterAll: in pw < 1.39 worker-scoped auto-fixtures are called in incorrect order
|
|
140
|
+
// 2. $cucumber: to load hooks before this fixtures
|
|
141
|
+
async ({
|
|
142
|
+
$workerHookFixtures,
|
|
143
|
+
$cucumber
|
|
144
|
+
}, use, $workerInfo) => {
|
|
145
|
+
await (0, _worker.runWorkerHooks)('beforeAll', {
|
|
146
|
+
$workerInfo,
|
|
147
|
+
...$workerHookFixtures
|
|
148
|
+
});
|
|
149
|
+
await use();
|
|
150
|
+
}, {
|
|
151
|
+
auto: true,
|
|
152
|
+
scope: 'worker'
|
|
153
|
+
}],
|
|
154
|
+
$afterAll: [async ({
|
|
155
|
+
$workerHookFixtures
|
|
156
|
+
}, use, $workerInfo) => {
|
|
157
|
+
await use();
|
|
158
|
+
await (0, _worker.runWorkerHooks)('afterAll', {
|
|
159
|
+
$workerInfo,
|
|
160
|
+
...$workerHookFixtures
|
|
161
|
+
});
|
|
162
|
+
}, {
|
|
163
|
+
auto: true,
|
|
164
|
+
scope: 'worker'
|
|
165
|
+
}]
|
|
103
166
|
});
|
|
104
167
|
const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
|
|
105
168
|
function isBddAutoInjectFixture(name) {
|