@zohodesk/testinglibrary 0.1.8-exp-bdd-v3 → 0.1.8-exp-bdd-v4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -1
- package/build/bdd-framework/cli/commands/env.js +42 -0
- package/build/bdd-framework/cli/commands/export.js +47 -0
- package/build/bdd-framework/cli/commands/test.js +64 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +19 -0
- package/build/bdd-framework/cli/worker.js +13 -0
- package/build/bdd-framework/config/dir.js +27 -0
- package/build/bdd-framework/config/env.js +50 -0
- package/build/bdd-framework/config/index.js +90 -0
- package/build/bdd-framework/config/lang.js +14 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
- package/build/bdd-framework/cucumber/gherkin.d.js +5 -0
- package/build/bdd-framework/cucumber/loadConfig.js +17 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
- package/build/bdd-framework/cucumber/loadSources.js +57 -0
- package/build/bdd-framework/cucumber/loadSteps.js +40 -0
- package/build/bdd-framework/decorators.js +18 -0
- package/build/bdd-framework/gen/fixtures.js +48 -0
- package/build/bdd-framework/gen/formatter.js +135 -0
- package/build/bdd-framework/gen/i18n.js +39 -0
- package/build/bdd-framework/gen/index.js +164 -0
- package/build/bdd-framework/gen/testFile.js +422 -0
- package/build/bdd-framework/gen/testNode.js +61 -0
- package/build/bdd-framework/gen/testPoms.js +133 -0
- package/build/bdd-framework/hooks/scenario.js +107 -0
- package/build/bdd-framework/hooks/worker.js +83 -0
- package/build/bdd-framework/index.js +45 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +93 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +52 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +61 -0
- package/build/bdd-framework/playwright/transform.js +84 -0
- package/build/bdd-framework/playwright/types.js +5 -0
- package/build/bdd-framework/playwright/utils.js +34 -0
- package/build/bdd-framework/run/StepInvoker.js +73 -0
- package/build/bdd-framework/run/bddFixtures.js +170 -0
- package/build/bdd-framework/run/bddWorld.js +76 -0
- package/build/bdd-framework/snippets/index.js +136 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +43 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +66 -0
- package/build/bdd-framework/stepDefinitions/decorators/class.js +68 -0
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +99 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
- package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
- package/build/bdd-framework/utils/exit.js +58 -0
- package/build/bdd-framework/utils/index.js +70 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +30 -0
- package/build/bdd-poc/core-runner/main.js +10 -0
- package/build/bdd-poc/core-runner/stepDefinitions.js +0 -1
- package/build/bdd-poc/index.js +26 -0
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +6 -6
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +1 -2
- package/build/bdd-poc/test/testDataMap.js +5 -5
- package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
- package/build/core/playwright/builtInFixtures/addTags.js +19 -0
- package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
- package/build/core/playwright/builtInFixtures/context.js +15 -0
- package/build/core/playwright/builtInFixtures/index.js +26 -0
- package/build/core/playwright/builtInFixtures/page.js +51 -0
- package/build/core/playwright/clear-caches.js +29 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/index.js +10 -79
- package/build/core/playwright/readConfigFile.js +12 -6
- package/build/core/playwright/report-generator.js +2 -1
- package/build/core/playwright/setup/config-creator.js +23 -17
- package/build/core/playwright/setup/config-utils.js +32 -1
- 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 +10 -10
- package/build/index.d.ts +59 -4
- package/build/index.js +10 -9
- package/build/lib/cli.js +10 -1
- package/build/parser/parser.js +0 -1
- package/build/setup-folder-structure/helper.js +34 -0
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
- package/build/setup-folder-structure/samples/uat-config-sample.js +3 -2
- package/build/setup-folder-structure/setupProject.js +10 -5
- package/build/utils/fileUtils.js +15 -4
- package/build/utils/logger.js +1 -2
- package/build/utils/stepDefinitionsFormatter.js +1 -2
- package/changelog.md +57 -0
- package/npm-shrinkwrap.json +1426 -2172
- package/package.json +5 -4
- package/build/bdd-poc/main.js +0 -10
- /package/build/bdd-poc/{runner.js → core-runner/runner.js} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BDDInputConfig", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _config.BDDInputConfig;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "BddWorld", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _bddWorld.BddWorld;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "BddWorldOptions", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _bddWorld.BddWorldOptions;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "createBdd", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _createBdd.createBdd;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "defineBddConfig", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _config.defineBddConfig;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "test", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _bddFixtures.test;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _config = require("./config");
|
|
43
|
+
var _createBdd = require("./stepDefinitions/createBdd");
|
|
44
|
+
var _bddFixtures = require("./run/bddFixtures");
|
|
45
|
+
var _bddWorld = require("./run/bddWorld");
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fixtureParameterNames = fixtureParameterNames;
|
|
7
|
+
/**
|
|
8
|
+
* Extracted from playwright.
|
|
9
|
+
* https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
|
|
10
|
+
*/
|
|
11
|
+
/* eslint-disable max-statements, complexity, max-len, max-depth */
|
|
12
|
+
const signatureSymbol = Symbol('signature');
|
|
13
|
+
function fixtureParameterNames(fn) {
|
|
14
|
+
if (typeof fn !== 'function') {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (!fn[signatureSymbol]) {
|
|
18
|
+
fn[signatureSymbol] = innerFixtureParameterNames(fn);
|
|
19
|
+
}
|
|
20
|
+
return fn[signatureSymbol];
|
|
21
|
+
}
|
|
22
|
+
function innerFixtureParameterNames(fn) {
|
|
23
|
+
const text = filterOutComments(fn.toString());
|
|
24
|
+
const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
|
|
25
|
+
if (!match) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const trimmedParams = match[1].trim();
|
|
29
|
+
if (!trimmedParams) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const [firstParam] = splitByComma(trimmedParams);
|
|
33
|
+
if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
|
|
34
|
+
throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
|
|
35
|
+
}
|
|
36
|
+
const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
|
|
37
|
+
const colon = prop.indexOf(':');
|
|
38
|
+
return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
|
|
39
|
+
});
|
|
40
|
+
const restProperty = props.find(prop => prop.startsWith('...'));
|
|
41
|
+
if (restProperty) {
|
|
42
|
+
throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
|
|
43
|
+
}
|
|
44
|
+
return props;
|
|
45
|
+
}
|
|
46
|
+
function filterOutComments(s) {
|
|
47
|
+
const result = [];
|
|
48
|
+
let commentState = 'none';
|
|
49
|
+
for (let i = 0; i < s.length; ++i) {
|
|
50
|
+
if (commentState === 'singleline') {
|
|
51
|
+
if (s[i] === '\n') {
|
|
52
|
+
commentState = 'none';
|
|
53
|
+
}
|
|
54
|
+
} else if (commentState === 'multiline') {
|
|
55
|
+
if (s[i - 1] === '*' && s[i] === '/') {
|
|
56
|
+
commentState = 'none';
|
|
57
|
+
}
|
|
58
|
+
} else if (commentState === 'none') {
|
|
59
|
+
if (s[i] === '/' && s[i + 1] === '/') {
|
|
60
|
+
commentState = 'singleline';
|
|
61
|
+
} else if (s[i] === '/' && s[i + 1] === '*') {
|
|
62
|
+
commentState = 'multiline';
|
|
63
|
+
i += 2;
|
|
64
|
+
} else {
|
|
65
|
+
result.push(s[i]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result.join('');
|
|
70
|
+
}
|
|
71
|
+
function splitByComma(s) {
|
|
72
|
+
const result = [];
|
|
73
|
+
const stack = [];
|
|
74
|
+
let start = 0;
|
|
75
|
+
for (let i = 0; i < s.length; i++) {
|
|
76
|
+
if (s[i] === '{' || s[i] === '[') {
|
|
77
|
+
stack.push(s[i] === '{' ? '}' : ']');
|
|
78
|
+
} else if (s[i] === stack[stack.length - 1]) {
|
|
79
|
+
stack.pop();
|
|
80
|
+
} else if (!stack.length && s[i] === ',') {
|
|
81
|
+
const token = s.substring(start, i).trim();
|
|
82
|
+
if (token) {
|
|
83
|
+
result.push(token);
|
|
84
|
+
}
|
|
85
|
+
start = i + 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const lastToken = s.substring(start).trim();
|
|
89
|
+
if (lastToken) {
|
|
90
|
+
result.push(lastToken);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getLocationInFile = getLocationInFile;
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Inspects stacktrace and finds call location in provided file.
|
|
12
|
+
* This function is based on Playwright's getLocationByStacktrace().
|
|
13
|
+
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
|
|
14
|
+
*/
|
|
15
|
+
function getLocationInFile(filePath) {
|
|
16
|
+
const filePathUrl = _url.default.pathToFileURL(filePath).toString();
|
|
17
|
+
const {
|
|
18
|
+
sourceMapSupport
|
|
19
|
+
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
20
|
+
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
21
|
+
Error.prepareStackTrace = (error, stackFrames) => {
|
|
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
|
+
}
|
|
33
|
+
const frame = sourceMapSupport.wrapCallSite(frameInFile);
|
|
34
|
+
const fileName = frame.getFileName();
|
|
35
|
+
// Node error stacks for modules use file:// urls instead of paths.
|
|
36
|
+
const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
|
|
37
|
+
return {
|
|
38
|
+
file,
|
|
39
|
+
line: frame.getLineNumber(),
|
|
40
|
+
column: frame.getColumnNumber()
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
// commented stackTraceLImit modification, todo: check if it has perf impact
|
|
44
|
+
// const oldStackTraceLimit = Error.stackTraceLimit;
|
|
45
|
+
// Error.stackTraceLimit = level + 1;
|
|
46
|
+
const obj = {};
|
|
47
|
+
Error.captureStackTrace(obj);
|
|
48
|
+
const location = obj.stack;
|
|
49
|
+
// Error.stackTraceLimit = oldStackTraceLimit;
|
|
50
|
+
Error.prepareStackTrace = oldPrepareStackTrace;
|
|
51
|
+
return location;
|
|
52
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loadConfig = loadConfig;
|
|
8
|
+
exports.resolveConfigFile = resolveConfigFile;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
+
var _utils = require("./utils");
|
|
12
|
+
var _transform = require("./transform");
|
|
13
|
+
var _exit = require("../utils/exit");
|
|
14
|
+
/**
|
|
15
|
+
* Loading Playwright config.
|
|
16
|
+
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/configLoader.ts
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
async function loadConfig(cliConfigPath) {
|
|
20
|
+
const resolvedConfigFile = resolveConfigFile(cliConfigPath);
|
|
21
|
+
assertConfigFileExists(resolvedConfigFile, cliConfigPath);
|
|
22
|
+
await (0, _transform.requireTransform)().requireOrImport(resolvedConfigFile);
|
|
23
|
+
return {
|
|
24
|
+
resolvedConfigFile
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function resolveConfigFile(cliConfigPath) {
|
|
28
|
+
const {
|
|
29
|
+
resolveConfigFile
|
|
30
|
+
} = (0, _utils.requirePlaywrightModule)('lib/common/configLoader.js');
|
|
31
|
+
const configFileOrDirectory = getConfigFilePath(cliConfigPath);
|
|
32
|
+
return resolveConfigFile(configFileOrDirectory) || '';
|
|
33
|
+
}
|
|
34
|
+
function getConfigFilePath(cliConfigPath) {
|
|
35
|
+
return cliConfigPath ? _path.default.resolve(process.cwd(), cliConfigPath) : process.cwd();
|
|
36
|
+
}
|
|
37
|
+
function assertConfigFileExists(resolvedConfigFile, cliConfigPath) {
|
|
38
|
+
if (!resolvedConfigFile || !_fs.default.existsSync(resolvedConfigFile)) {
|
|
39
|
+
const configFilePath = getConfigFilePath(cliConfigPath);
|
|
40
|
+
(0, _exit.exit)(`Can't find Playwright config file in: ${configFilePath}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isTestContainsSubtest = isTestContainsSubtest;
|
|
7
|
+
exports.runStepWithCustomLocation = runStepWithCustomLocation;
|
|
8
|
+
var _test = require("@playwright/test");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
/**
|
|
11
|
+
* Helpers to deal with Playwright test internal stuff.
|
|
12
|
+
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/testType.ts
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const testTypeSymbol = (0, _utils.getSymbolByName)(_test.test, 'testType');
|
|
16
|
+
/**
|
|
17
|
+
* Returns test fixtures using Symbol.
|
|
18
|
+
*/
|
|
19
|
+
function getTestFixtures(test) {
|
|
20
|
+
return getTestImpl(test).fixtures;
|
|
21
|
+
}
|
|
22
|
+
function getTestImpl(test) {
|
|
23
|
+
return test[testTypeSymbol];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run step with location pointing to Given, When, Then call.
|
|
27
|
+
*/
|
|
28
|
+
// eslint-disable-next-line max-params
|
|
29
|
+
async function runStepWithCustomLocation(test, stepText, location, body) {
|
|
30
|
+
const testInfo = test.info();
|
|
31
|
+
// See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/common/testType.ts#L221
|
|
32
|
+
// @ts-expect-error _runAsStep is hidden from public
|
|
33
|
+
return testInfo._runAsStep({
|
|
34
|
+
category: 'test.step',
|
|
35
|
+
title: stepText,
|
|
36
|
+
location
|
|
37
|
+
}, async () => {
|
|
38
|
+
return await body();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if test contains all fixtures of subtest.
|
|
43
|
+
* - test was extended from subtest
|
|
44
|
+
* - test is a result of mergeTests(subtest, ...)
|
|
45
|
+
*/
|
|
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));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function locationToString({
|
|
56
|
+
file,
|
|
57
|
+
line,
|
|
58
|
+
column
|
|
59
|
+
}) {
|
|
60
|
+
return `${file}:${line}:${column}`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.installTransform = installTransform;
|
|
8
|
+
exports.requireTransform = requireTransform;
|
|
9
|
+
var _module = _interopRequireDefault(require("module"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
/* eslint-disable max-params */
|
|
14
|
+
/**
|
|
15
|
+
* Installs require hook to transform ts.
|
|
16
|
+
* Extracted from playwright.
|
|
17
|
+
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/transform/transform.ts
|
|
18
|
+
*/
|
|
19
|
+
function installTransform() {
|
|
20
|
+
const {
|
|
21
|
+
pirates
|
|
22
|
+
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
23
|
+
const {
|
|
24
|
+
resolveHook,
|
|
25
|
+
shouldTransform,
|
|
26
|
+
transformHook
|
|
27
|
+
} = requireTransform();
|
|
28
|
+
let reverted = false;
|
|
29
|
+
const originalResolveFilename = _module.default._resolveFilename;
|
|
30
|
+
function resolveFilename(specifier, parent, ...rest) {
|
|
31
|
+
if (!reverted && parent) {
|
|
32
|
+
const resolved = resolveHook(parent.filename, specifier);
|
|
33
|
+
if (resolved !== undefined) {
|
|
34
|
+
specifier = resolved;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return originalResolveFilename.call(this, specifier, parent, ...rest);
|
|
38
|
+
}
|
|
39
|
+
_module.default._resolveFilename = resolveFilename;
|
|
40
|
+
const revertPirates = pirates.addHook((code, filename) => {
|
|
41
|
+
if (!shouldTransform(filename)) {
|
|
42
|
+
return code;
|
|
43
|
+
}
|
|
44
|
+
return transformHook(code, filename);
|
|
45
|
+
}, {
|
|
46
|
+
exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
reverted = true;
|
|
50
|
+
_module.default._resolveFilename = originalResolveFilename;
|
|
51
|
+
revertPirates();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function requireTransform() {
|
|
55
|
+
const transformPathSince1_35 = (0, _utils.getPlaywrightModulePath)('lib/transform/transform.js');
|
|
56
|
+
if (_fs.default.existsSync(transformPathSince1_35)) {
|
|
57
|
+
const {
|
|
58
|
+
resolveHook,
|
|
59
|
+
shouldTransform,
|
|
60
|
+
transformHook,
|
|
61
|
+
requireOrImport
|
|
62
|
+
} = (0, _utils.requirePlaywrightModule)(transformPathSince1_35);
|
|
63
|
+
return {
|
|
64
|
+
resolveHook,
|
|
65
|
+
shouldTransform,
|
|
66
|
+
transformHook,
|
|
67
|
+
requireOrImport
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
const {
|
|
71
|
+
resolveHook,
|
|
72
|
+
transformHook,
|
|
73
|
+
requireOrImport
|
|
74
|
+
} = (0, _utils.requirePlaywrightModule)('lib/common/transform.js');
|
|
75
|
+
// see: https://github.com/microsoft/playwright/blob/b4ffb848de1b00e9a0abad6dacdccce60cce9bed/packages/playwright-test/src/reporters/base.ts#L524
|
|
76
|
+
const shouldTransform = file => !file.includes(`${_path.default.sep}node_modules${_path.default.sep}`);
|
|
77
|
+
return {
|
|
78
|
+
resolveHook,
|
|
79
|
+
shouldTransform,
|
|
80
|
+
transformHook,
|
|
81
|
+
requireOrImport
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getPlaywrightModulePath = getPlaywrightModulePath;
|
|
8
|
+
exports.requirePlaywrightModule = requirePlaywrightModule;
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
// cache playwright root
|
|
13
|
+
let playwrightRoot = '';
|
|
14
|
+
/**
|
|
15
|
+
* Requires Playwright's internal module that is not exported via package.exports.
|
|
16
|
+
*/
|
|
17
|
+
function requirePlaywrightModule(modulePath) {
|
|
18
|
+
const absPath = _path.default.isAbsolute(modulePath) ? modulePath : getPlaywrightModulePath(modulePath);
|
|
19
|
+
return require(absPath);
|
|
20
|
+
}
|
|
21
|
+
function getPlaywrightModulePath(relativePath) {
|
|
22
|
+
return _path.default.join(getPlaywrightRoot(), relativePath);
|
|
23
|
+
}
|
|
24
|
+
function getPlaywrightRoot() {
|
|
25
|
+
if (!playwrightRoot) {
|
|
26
|
+
// Since 1.38 all modules moved from @playwright/test to playwright.
|
|
27
|
+
// Here we check existance of 'lib' dir instead of checking version.
|
|
28
|
+
// See: https://github.com/microsoft/playwright/pull/26946
|
|
29
|
+
const playwrightTestRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
|
|
30
|
+
const libDir = _path.default.join(playwrightTestRoot, 'lib');
|
|
31
|
+
playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : (0, _utils.resolvePackageRoot)('playwright');
|
|
32
|
+
}
|
|
33
|
+
return playwrightRoot;
|
|
34
|
+
}
|
|
@@ -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;
|