@zohodesk/testinglibrary 0.0.5-exp.8 → 0.0.5-n20-experimental
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 +9 -1
- package/.eslintrc.js +31 -0
- package/.gitlab-ci.yml +191 -0
- package/.prettierrc +6 -0
- package/README.md +151 -1
- package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
- package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +19 -0
- package/build/common/multi-actor/steps/multiActorHandling.spec.js +26 -0
- package/build/common/searchFake/helpers/rpcRequestHelper.js +41 -0
- package/build/common/searchFake/steps/searchFake.spec.js +26 -0
- package/build/core/dataGenerator/DataGenerator.js +108 -0
- package/build/core/dataGenerator/DataGeneratorError.js +50 -0
- package/build/core/dataGenerator/DataGeneratorHelper.js +49 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +3 -9
- package/build/core/jest/runner/jest-runner.js +1 -0
- package/build/core/jest/setup/index.js +1 -7
- package/build/core/playwright/builtInFixtures/actorContext.js +75 -0
- 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 +32 -0
- package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
- package/build/core/playwright/builtInFixtures/i18N.js +41 -0
- package/build/core/playwright/builtInFixtures/index.js +46 -0
- package/build/core/playwright/builtInFixtures/page.js +38 -0
- package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
- package/build/core/playwright/clear-caches.js +49 -0
- package/build/core/playwright/codegen.js +5 -6
- package/build/core/playwright/configuration/Configuration.js +25 -0
- package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
- package/build/core/playwright/configuration/UserArgs.js +12 -0
- package/build/core/playwright/constants/browserTypes.js +12 -0
- package/build/core/playwright/constants/fileMutexConfig.js +9 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/env-initializer.js +28 -6
- package/build/core/playwright/fixtures.js +24 -0
- package/build/core/playwright/helpers/additionalProfiles.js +25 -0
- package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
- package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
- package/build/core/playwright/helpers/auth/getUsers.js +118 -0
- package/build/core/playwright/helpers/auth/index.js +76 -0
- package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +54 -0
- package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
- package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
- package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
- package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
- package/build/core/playwright/helpers/fileMutex.js +71 -0
- package/build/core/playwright/helpers/getUserFixtures.js +23 -0
- package/build/core/playwright/helpers/mergeObjects.js +13 -0
- package/build/core/playwright/helpers/parseUserArgs.js +10 -0
- package/build/core/playwright/index.js +10 -96
- package/build/core/playwright/readConfigFile.js +97 -14
- package/build/core/playwright/report-generator.js +9 -10
- package/build/core/playwright/runner/Runner.js +22 -0
- package/build/core/playwright/runner/RunnerHelper.js +43 -0
- package/build/core/playwright/runner/RunnerTypes.js +17 -0
- package/build/core/playwright/runner/SpawnRunner.js +113 -0
- package/build/core/playwright/setup/config-creator.js +101 -90
- package/build/core/playwright/setup/config-utils.js +188 -0
- package/build/core/playwright/setup/custom-reporter.js +136 -0
- package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
- package/build/core/playwright/tagProcessor.js +69 -0
- package/build/core/playwright/test-runner.js +84 -67
- package/build/core/playwright/types.js +44 -0
- package/build/core/playwright/validateFeature.js +28 -0
- package/build/decorators.d.ts +1 -0
- package/build/decorators.js +16 -0
- package/build/index.d.ts +78 -0
- package/build/index.js +73 -5
- package/build/lib/cli.js +38 -5
- package/build/lib/post-install.js +19 -11
- package/build/lint/index.js +3 -6
- package/build/parser/parser.js +205 -0
- package/build/parser/sample.feature +34 -0
- package/build/parser/sample.spec.js +37 -0
- package/build/parser/verifier.js +130 -0
- package/build/setup-folder-structure/helper.js +37 -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/accountLogin-sample.js +19 -0
- package/build/setup-folder-structure/samples/actors-index.js +2 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
- package/build/setup-folder-structure/samples/editions-index.js +3 -0
- package/build/setup-folder-structure/samples/free-sample.json +25 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
- package/build/setup-folder-structure/samples/settings.json +7 -0
- package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
- package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
- package/build/setup-folder-structure/setupProject.js +36 -18
- package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
- package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
- package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
- package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
- package/build/test/core/playwright/helpers/__tests__/additionalProfiles.test.js +45 -0
- package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
- package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
- package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
- package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
- package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
- package/build/utils/cliArgsToObject.js +9 -1
- package/build/utils/commonUtils.js +17 -0
- package/build/utils/fileUtils.js +109 -0
- package/build/utils/logger.js +7 -35
- package/build/utils/rootPath.js +16 -9
- package/build/utils/stepDefinitionsFormatter.js +11 -0
- package/changelog.md +136 -10
- package/jest.config.js +29 -11
- package/npm-shrinkwrap.json +10241 -6175
- package/package.json +40 -26
- package/playwright.config.js +5 -55
- package/test-results/.last-run.json +4 -0
- package/unit_reports/unit-report.html +277 -0
- package/build/bdd-framework/cli/commands/env.js +0 -44
- package/build/bdd-framework/cli/commands/export.js +0 -47
- package/build/bdd-framework/cli/commands/test.js +0 -60
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -21
- package/build/bdd-framework/cli/worker.js +0 -13
- package/build/bdd-framework/config/dir.js +0 -27
- package/build/bdd-framework/config/env.js +0 -49
- package/build/bdd-framework/config/index.js +0 -92
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -45
- package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
- package/build/bdd-framework/cucumber/loadConfig.js +0 -17
- package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
- package/build/bdd-framework/cucumber/loadSources.js +0 -58
- package/build/bdd-framework/cucumber/loadSteps.js +0 -41
- package/build/bdd-framework/decorators.js +0 -21
- package/build/bdd-framework/gen/formatter.js +0 -92
- package/build/bdd-framework/gen/i18n.js +0 -44
- package/build/bdd-framework/gen/index.js +0 -150
- package/build/bdd-framework/gen/poms.js +0 -47
- package/build/bdd-framework/gen/testFile.js +0 -356
- package/build/bdd-framework/gen/testNode.js +0 -50
- package/build/bdd-framework/index.js +0 -33
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -103
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -50
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -47
- package/build/bdd-framework/playwright/transform.js +0 -85
- package/build/bdd-framework/playwright/utils.js +0 -24
- package/build/bdd-framework/run/bddFixtures.js +0 -109
- package/build/bdd-framework/run/bddWorld.js +0 -91
- package/build/bdd-framework/snippets/index.js +0 -132
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -50
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -32
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
- package/build/bdd-framework/stepDefinitions/createBdd.js +0 -52
- package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -110
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
- package/build/bdd-framework/utils/index.js +0 -52
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -21
- package/build/setup-folder-structure/env-config-sample.json +0 -17
- package/build/setup-folder-structure/uat-config-sample.js +0 -31
- package/build/setup-folder-structure/user-example.json +0 -3
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
|
|
13
|
-
/* eslint-disable max-statements, complexity, max-len, max-depth */
|
|
14
|
-
|
|
15
|
-
const signatureSymbol = Symbol('signature');
|
|
16
|
-
function fixtureParameterNames(fn) {
|
|
17
|
-
if (typeof fn !== 'function') {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
;
|
|
21
|
-
if (!fn[signatureSymbol]) {
|
|
22
|
-
fn[signatureSymbol] = innerFixtureParameterNames(fn);
|
|
23
|
-
}
|
|
24
|
-
return fn[signatureSymbol];
|
|
25
|
-
}
|
|
26
|
-
function innerFixtureParameterNames(fn) {
|
|
27
|
-
const text = filterOutComments(fn.toString());
|
|
28
|
-
const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
|
|
29
|
-
if (!match) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
;
|
|
33
|
-
const trimmedParams = match[1].trim();
|
|
34
|
-
if (!trimmedParams) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
;
|
|
38
|
-
const [firstParam] = splitByComma(trimmedParams);
|
|
39
|
-
if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
|
|
40
|
-
throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
|
|
41
|
-
}
|
|
42
|
-
const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
|
|
43
|
-
const colon = prop.indexOf(':');
|
|
44
|
-
return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
|
|
45
|
-
});
|
|
46
|
-
const restProperty = props.find(prop => prop.startsWith('...'));
|
|
47
|
-
if (restProperty) {
|
|
48
|
-
throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
|
|
49
|
-
}
|
|
50
|
-
return props;
|
|
51
|
-
}
|
|
52
|
-
function filterOutComments(s) {
|
|
53
|
-
const result = [];
|
|
54
|
-
let commentState = 'none';
|
|
55
|
-
for (let i = 0; i < s.length; ++i) {
|
|
56
|
-
if (commentState === 'singleline') {
|
|
57
|
-
if (s[i] === '\n') {
|
|
58
|
-
commentState = 'none';
|
|
59
|
-
}
|
|
60
|
-
;
|
|
61
|
-
} else if (commentState === 'multiline') {
|
|
62
|
-
if (s[i - 1] === '*' && s[i] === '/') {
|
|
63
|
-
commentState = 'none';
|
|
64
|
-
}
|
|
65
|
-
;
|
|
66
|
-
} else if (commentState === 'none') {
|
|
67
|
-
if (s[i] === '/' && s[i + 1] === '/') {
|
|
68
|
-
commentState = 'singleline';
|
|
69
|
-
} else if (s[i] === '/' && s[i + 1] === '*') {
|
|
70
|
-
commentState = 'multiline';
|
|
71
|
-
i += 2;
|
|
72
|
-
} else {
|
|
73
|
-
result.push(s[i]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return result.join('');
|
|
78
|
-
}
|
|
79
|
-
function splitByComma(s) {
|
|
80
|
-
const result = [];
|
|
81
|
-
const stack = [];
|
|
82
|
-
let start = 0;
|
|
83
|
-
for (let i = 0; i < s.length; i++) {
|
|
84
|
-
if (s[i] === '{' || s[i] === '[') {
|
|
85
|
-
stack.push(s[i] === '{' ? '}' : ']');
|
|
86
|
-
} else if (s[i] === stack[stack.length - 1]) {
|
|
87
|
-
stack.pop();
|
|
88
|
-
} else if (!stack.length && s[i] === ',') {
|
|
89
|
-
const token = s.substring(start, i).trim();
|
|
90
|
-
if (token) {
|
|
91
|
-
result.push(token);
|
|
92
|
-
}
|
|
93
|
-
;
|
|
94
|
-
start = i + 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const lastToken = s.substring(start).trim();
|
|
98
|
-
if (lastToken) {
|
|
99
|
-
result.push(lastToken);
|
|
100
|
-
}
|
|
101
|
-
;
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.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 {
|
|
17
|
-
sourceMapSupport
|
|
18
|
-
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
19
|
-
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
20
|
-
Error.prepareStackTrace = (error, stackFrames) => {
|
|
21
|
-
const frameInFile = stackFrames.find(frame => frame.getFileName() === filePath);
|
|
22
|
-
if (!frameInFile) {
|
|
23
|
-
return {
|
|
24
|
-
file: '',
|
|
25
|
-
line: 0,
|
|
26
|
-
column: 0
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
;
|
|
30
|
-
const frame = sourceMapSupport.wrapCallSite(frameInFile);
|
|
31
|
-
const fileName = frame.getFileName();
|
|
32
|
-
// Node error stacks for modules use file:// urls instead of paths.
|
|
33
|
-
const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
|
|
34
|
-
return {
|
|
35
|
-
file,
|
|
36
|
-
line: frame.getLineNumber(),
|
|
37
|
-
column: frame.getColumnNumber()
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
// commented stackTraceLImit modification, todo: check if it has perf impact
|
|
41
|
-
// const oldStackTraceLimit = Error.stackTraceLimit;
|
|
42
|
-
// Error.stackTraceLimit = level + 1;
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
const obj = {};
|
|
45
|
-
Error.captureStackTrace(obj);
|
|
46
|
-
const location = obj.stack;
|
|
47
|
-
// Error.stackTraceLimit = oldStackTraceLimit;
|
|
48
|
-
Error.prepareStackTrace = oldPrepareStackTrace;
|
|
49
|
-
return location;
|
|
50
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.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 _utils2 = require("../utils");
|
|
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, _utils2.exitWithMessage)(`Can't find Playwright config file in: ${configFilePath}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getTestImpl = getTestImpl;
|
|
7
|
-
exports.isParentChildTest = isParentChildTest;
|
|
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
|
-
/**
|
|
18
|
-
* Returns test fixtures using Symbol.
|
|
19
|
-
*/
|
|
20
|
-
function getTestFixtures(test) {
|
|
21
|
-
return getTestImpl(test).fixtures;
|
|
22
|
-
}
|
|
23
|
-
function getTestImpl(test) {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
return test[testTypeSymbol];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns true if all fixtures of parent test found in child test.
|
|
30
|
-
*/
|
|
31
|
-
function isParentChildTest(parent, child) {
|
|
32
|
-
if (parent === child) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
;
|
|
36
|
-
const childLocationsSet = new Set(getTestFixtures(child).map(f => locationToString(f.location)));
|
|
37
|
-
return getTestFixtures(parent).every(f => {
|
|
38
|
-
return childLocationsSet.has(locationToString(f.location));
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function locationToString({
|
|
42
|
-
file,
|
|
43
|
-
line,
|
|
44
|
-
column
|
|
45
|
-
}) {
|
|
46
|
-
return `${file}:${line}:${column}`;
|
|
47
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.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 @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
|
|
14
|
-
/* eslint-disable max-params */
|
|
15
|
-
/**
|
|
16
|
-
* Installs require hook to transform ts.
|
|
17
|
-
* Extracted from playwright.
|
|
18
|
-
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/transform/transform.ts
|
|
19
|
-
*/
|
|
20
|
-
function installTransform() {
|
|
21
|
-
const {
|
|
22
|
-
pirates
|
|
23
|
-
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
24
|
-
const {
|
|
25
|
-
resolveHook,
|
|
26
|
-
shouldTransform,
|
|
27
|
-
transformHook
|
|
28
|
-
} = requireTransform();
|
|
29
|
-
let reverted = false;
|
|
30
|
-
const originalResolveFilename = _module.default._resolveFilename;
|
|
31
|
-
function resolveFilename(specifier, parent, ...rest) {
|
|
32
|
-
if (!reverted && parent) {
|
|
33
|
-
const resolved = resolveHook(parent.filename, specifier);
|
|
34
|
-
if (resolved !== undefined) {
|
|
35
|
-
specifier = resolved;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return originalResolveFilename.call(this, specifier, parent, ...rest);
|
|
39
|
-
}
|
|
40
|
-
_module.default._resolveFilename = resolveFilename;
|
|
41
|
-
const revertPirates = pirates.addHook((code, filename) => {
|
|
42
|
-
if (!shouldTransform(filename)) {
|
|
43
|
-
return code;
|
|
44
|
-
}
|
|
45
|
-
return transformHook(code, filename);
|
|
46
|
-
}, {
|
|
47
|
-
exts: ['.ts', '.tsx', '.js', '.jsx', '.mjs']
|
|
48
|
-
});
|
|
49
|
-
return () => {
|
|
50
|
-
reverted = true;
|
|
51
|
-
_module.default._resolveFilename = originalResolveFilename;
|
|
52
|
-
revertPirates();
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function requireTransform() {
|
|
56
|
-
const transformPathSince1_35 = (0, _utils.getPlaywrightModulePath)('lib/transform/transform.js');
|
|
57
|
-
if (_fs.default.existsSync(transformPathSince1_35)) {
|
|
58
|
-
const {
|
|
59
|
-
resolveHook,
|
|
60
|
-
shouldTransform,
|
|
61
|
-
transformHook,
|
|
62
|
-
requireOrImport
|
|
63
|
-
} = (0, _utils.requirePlaywrightModule)(transformPathSince1_35);
|
|
64
|
-
return {
|
|
65
|
-
resolveHook,
|
|
66
|
-
shouldTransform,
|
|
67
|
-
transformHook,
|
|
68
|
-
requireOrImport
|
|
69
|
-
};
|
|
70
|
-
} else {
|
|
71
|
-
const {
|
|
72
|
-
resolveHook,
|
|
73
|
-
transformHook,
|
|
74
|
-
requireOrImport
|
|
75
|
-
} = (0, _utils.requirePlaywrightModule)('lib/common/transform.js');
|
|
76
|
-
// see: https://github.com/microsoft/playwright/blob/b4ffb848de1b00e9a0abad6dacdccce60cce9bed/packages/playwright-test/src/reporters/base.ts#L524
|
|
77
|
-
const shouldTransform = file => !file.includes(`${_path.default.sep}node_modules${_path.default.sep}`);
|
|
78
|
-
return {
|
|
79
|
-
resolveHook,
|
|
80
|
-
shouldTransform,
|
|
81
|
-
transformHook,
|
|
82
|
-
requireOrImport
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getPlaywrightModulePath = getPlaywrightModulePath;
|
|
8
|
-
exports.requirePlaywrightModule = requirePlaywrightModule;
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
const playwrightRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Requires Playwright's internal module that is not exported via package.exports.
|
|
15
|
-
*/
|
|
16
|
-
function requirePlaywrightModule(modulePath) {
|
|
17
|
-
const absPath = _path.default.isAbsolute(modulePath) ? modulePath : getPlaywrightModulePath(modulePath);
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
-
return require(absPath);
|
|
20
|
-
}
|
|
21
|
-
function getPlaywrightModulePath(relativePath) {
|
|
22
|
-
const parts = relativePath.split('/');
|
|
23
|
-
return _path.default.join(playwrightRoot, ...parts);
|
|
24
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isBddAutoInjectFixture = isBddAutoInjectFixture;
|
|
7
|
-
exports.test = void 0;
|
|
8
|
-
var _test = require("@playwright/test");
|
|
9
|
-
var _loadConfig = require("../cucumber/loadConfig");
|
|
10
|
-
var _loadSteps = require("../cucumber/loadSteps");
|
|
11
|
-
var _bddWorld = require("./bddWorld");
|
|
12
|
-
var _config = require("../config");
|
|
13
|
-
var _env = require("../config/env");
|
|
14
|
-
var _createDecorators = require("../stepDefinitions/createDecorators");
|
|
15
|
-
var _dir = require("../config/dir");
|
|
16
|
-
const test = _test.test.extend({
|
|
17
|
-
$bddWorldBase: async ({
|
|
18
|
-
$tags,
|
|
19
|
-
$test
|
|
20
|
-
}, use, testInfo) => {
|
|
21
|
-
const config = (0, _env.getConfigFromEnv)(testInfo.project.testDir);
|
|
22
|
-
const environment = {
|
|
23
|
-
cwd: (0, _dir.getPlaywrightConfigDir)()
|
|
24
|
-
};
|
|
25
|
-
const {
|
|
26
|
-
runConfiguration
|
|
27
|
-
} = await (0, _loadConfig.loadConfig)({
|
|
28
|
-
provided: (0, _config.extractCucumberConfig)(config)
|
|
29
|
-
}, environment);
|
|
30
|
-
const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
|
|
31
|
-
(0, _createDecorators.appendDecoratorSteps)(supportCodeLibrary);
|
|
32
|
-
const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
|
|
33
|
-
const world = new World({
|
|
34
|
-
testInfo,
|
|
35
|
-
supportCodeLibrary,
|
|
36
|
-
$tags,
|
|
37
|
-
$test,
|
|
38
|
-
parameters: runConfiguration.runtime.worldParameters || {},
|
|
39
|
-
log: () => {},
|
|
40
|
-
attach: async () => {} // eslint-disable-line @typescript-eslint/no-empty-function
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await world.init();
|
|
44
|
-
await use(world);
|
|
45
|
-
await world.destroy();
|
|
46
|
-
},
|
|
47
|
-
$bddWorld: async ({
|
|
48
|
-
$bddWorldBase,
|
|
49
|
-
page,
|
|
50
|
-
context,
|
|
51
|
-
browser,
|
|
52
|
-
browserName,
|
|
53
|
-
request
|
|
54
|
-
}, use) => {
|
|
55
|
-
$bddWorldBase.builtinFixtures = {
|
|
56
|
-
page,
|
|
57
|
-
context,
|
|
58
|
-
browser,
|
|
59
|
-
browserName,
|
|
60
|
-
request
|
|
61
|
-
};
|
|
62
|
-
await use($bddWorldBase);
|
|
63
|
-
},
|
|
64
|
-
// below fixtures are used in playwright-style
|
|
65
|
-
// and does not automatically init Playwright builtin fixtures
|
|
66
|
-
Given: ({
|
|
67
|
-
$bddWorldBase
|
|
68
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
69
|
-
When: ({
|
|
70
|
-
$bddWorldBase
|
|
71
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
72
|
-
Then: ({
|
|
73
|
-
$bddWorldBase
|
|
74
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
75
|
-
And: ({
|
|
76
|
-
$bddWorldBase
|
|
77
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
78
|
-
But: ({
|
|
79
|
-
$bddWorldBase
|
|
80
|
-
}, use) => use($bddWorldBase.invokeStep),
|
|
81
|
-
// below fixtures are used in cucumber-style
|
|
82
|
-
// and automatically init Playwright builtin fixtures
|
|
83
|
-
Given_: ({
|
|
84
|
-
$bddWorld
|
|
85
|
-
}, use) => use($bddWorld.invokeStep),
|
|
86
|
-
When_: ({
|
|
87
|
-
$bddWorld
|
|
88
|
-
}, use) => use($bddWorld.invokeStep),
|
|
89
|
-
Then_: ({
|
|
90
|
-
$bddWorld
|
|
91
|
-
}, use) => use($bddWorld.invokeStep),
|
|
92
|
-
And_: ({
|
|
93
|
-
$bddWorld
|
|
94
|
-
}, use) => use($bddWorld.invokeStep),
|
|
95
|
-
But_: ({
|
|
96
|
-
$bddWorld
|
|
97
|
-
}, use) => use($bddWorld.invokeStep),
|
|
98
|
-
// Init $tags fixture with empty array. Can be owerwritten in test file
|
|
99
|
-
// eslint-disable-next-line
|
|
100
|
-
$tags: ({}, use) => use([]),
|
|
101
|
-
// Init $test fixture with base test, but it will be always overwritten in test file
|
|
102
|
-
// eslint-disable-next-line
|
|
103
|
-
$test: ({}, use) => use(_test.test)
|
|
104
|
-
});
|
|
105
|
-
exports.test = test;
|
|
106
|
-
const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
|
|
107
|
-
function isBddAutoInjectFixture(name) {
|
|
108
|
-
return BDD_AUTO_INJECT_FIXTURES.includes(name);
|
|
109
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BddWorld = void 0;
|
|
7
|
-
exports.getWorldConstructor = getWorldConstructor;
|
|
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
|
-
// See: https://playwright.dev/docs/test-fixtures#built-in-fixtures
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
class BddWorld extends _cucumber.World {
|
|
17
|
-
builtinFixtures;
|
|
18
|
-
customFixtures;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
super(options);
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.invokeStep = this.invokeStep.bind(this);
|
|
23
|
-
}
|
|
24
|
-
async invokeStep(text, argument, customFixtures) {
|
|
25
|
-
const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, text, this.testInfo.file);
|
|
26
|
-
if (!stepDefinition) {
|
|
27
|
-
throw new Error(`Undefined step: "${text}"`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// attach custom fixtures to world - the only way to pass them to cucumber step fn
|
|
31
|
-
this.customFixtures = customFixtures;
|
|
32
|
-
const code = stepDefinition.code;
|
|
33
|
-
|
|
34
|
-
// get location of step call in generated test file
|
|
35
|
-
const location = (0, _getLocationInFile.getLocationInFile)(this.test.info().file);
|
|
36
|
-
const {
|
|
37
|
-
parameters
|
|
38
|
-
} = await stepDefinition.getInvocationParameters({
|
|
39
|
-
hookParameter: {},
|
|
40
|
-
step: {
|
|
41
|
-
text,
|
|
42
|
-
argument
|
|
43
|
-
},
|
|
44
|
-
world: this
|
|
45
|
-
});
|
|
46
|
-
const res = await (0, _testTypeImpl.getTestImpl)(this.test)._step(location, text, () => code.apply(this, parameters));
|
|
47
|
-
delete this.customFixtures;
|
|
48
|
-
return res;
|
|
49
|
-
}
|
|
50
|
-
get page() {
|
|
51
|
-
return this.builtinFixtures.page;
|
|
52
|
-
}
|
|
53
|
-
get context() {
|
|
54
|
-
return this.builtinFixtures.context;
|
|
55
|
-
}
|
|
56
|
-
get browser() {
|
|
57
|
-
return this.builtinFixtures.browser;
|
|
58
|
-
}
|
|
59
|
-
get browserName() {
|
|
60
|
-
return this.builtinFixtures.browserName;
|
|
61
|
-
}
|
|
62
|
-
get request() {
|
|
63
|
-
return this.builtinFixtures.request;
|
|
64
|
-
}
|
|
65
|
-
get testInfo() {
|
|
66
|
-
return this.options.testInfo;
|
|
67
|
-
}
|
|
68
|
-
get tags() {
|
|
69
|
-
return this.options.$tags;
|
|
70
|
-
}
|
|
71
|
-
get test() {
|
|
72
|
-
return this.options.$test;
|
|
73
|
-
}
|
|
74
|
-
async init() {
|
|
75
|
-
// async setup before each test
|
|
76
|
-
}
|
|
77
|
-
async destroy() {
|
|
78
|
-
// async teardown after each test
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.BddWorld = BddWorld;
|
|
82
|
-
function getWorldConstructor(supportCodeLibrary) {
|
|
83
|
-
// setWorldConstructor was not called
|
|
84
|
-
if (supportCodeLibrary.World === _cucumber.World) {
|
|
85
|
-
return BddWorld;
|
|
86
|
-
}
|
|
87
|
-
if (!Object.prototype.isPrototypeOf.call(BddWorld, supportCodeLibrary.World)) {
|
|
88
|
-
throw new Error(`CustomWorld should inherit from playwright-bdd World`);
|
|
89
|
-
}
|
|
90
|
-
return supportCodeLibrary.World;
|
|
91
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Snippets = void 0;
|
|
7
|
-
var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
var _defineStep = require("../stepDefinitions/defineStep");
|
|
10
|
-
var _logger = require("../utils/logger");
|
|
11
|
-
/**
|
|
12
|
-
* Generate and show snippets for undefined steps
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
class Snippets {
|
|
16
|
-
snippetBuilder;
|
|
17
|
-
bddBuiltInSyntax = false;
|
|
18
|
-
constructor(files, runConfiguration, supportCodeLibrary) {
|
|
19
|
-
this.files = files;
|
|
20
|
-
this.runConfiguration = runConfiguration;
|
|
21
|
-
this.supportCodeLibrary = supportCodeLibrary;
|
|
22
|
-
}
|
|
23
|
-
async printSnippetsAndExit() {
|
|
24
|
-
this.snippetBuilder = await this.createSnippetBuilder();
|
|
25
|
-
const snippets = this.getSnippets();
|
|
26
|
-
this.printHeader();
|
|
27
|
-
this.printSnippets(snippets);
|
|
28
|
-
this.printFooter(snippets);
|
|
29
|
-
}
|
|
30
|
-
async createSnippetBuilder() {
|
|
31
|
-
const {
|
|
32
|
-
snippetInterface
|
|
33
|
-
} = this.runConfiguration.formats.options;
|
|
34
|
-
const snippetSyntax = this.getSnippetSyntax();
|
|
35
|
-
return (0, _loadSnippetBuilder.loadSnippetBuilder)(this.supportCodeLibrary, snippetInterface, snippetSyntax);
|
|
36
|
-
}
|
|
37
|
-
getSnippetSyntax() {
|
|
38
|
-
const {
|
|
39
|
-
snippetSyntax
|
|
40
|
-
} = this.runConfiguration.formats.options;
|
|
41
|
-
if (!snippetSyntax && this.isPlaywrightStyle()) {
|
|
42
|
-
this.bddBuiltInSyntax = true;
|
|
43
|
-
return this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
|
|
44
|
-
} else {
|
|
45
|
-
return snippetSyntax;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
getSnippets() {
|
|
49
|
-
const snippetsSet = new Set();
|
|
50
|
-
const snippets = [];
|
|
51
|
-
this.files.forEach(file => {
|
|
52
|
-
file.undefinedSteps.forEach(undefinedStep => {
|
|
53
|
-
const {
|
|
54
|
-
snippet,
|
|
55
|
-
snippetWithLocation
|
|
56
|
-
} = this.getSnippet(file, snippets.length + 1, undefinedStep);
|
|
57
|
-
if (!snippetsSet.has(snippet)) {
|
|
58
|
-
snippetsSet.add(snippet);
|
|
59
|
-
snippets.push(snippetWithLocation);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
return snippets;
|
|
64
|
-
}
|
|
65
|
-
getSnippet(file, index, undefinedStep) {
|
|
66
|
-
const snippet = this.snippetBuilder.build({
|
|
67
|
-
keywordType: undefinedStep.keywordType,
|
|
68
|
-
pickleStep: undefinedStep.pickleStep
|
|
69
|
-
});
|
|
70
|
-
const {
|
|
71
|
-
line,
|
|
72
|
-
column
|
|
73
|
-
} = undefinedStep.step.location;
|
|
74
|
-
const snippetWithLocation = [`// ${index}. Missing step definition for "${file.sourceFile}:${line}:${column}"`, snippet].join('\n');
|
|
75
|
-
return {
|
|
76
|
-
snippet,
|
|
77
|
-
snippetWithLocation
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
isTypeScript() {
|
|
81
|
-
const {
|
|
82
|
-
requirePaths,
|
|
83
|
-
importPaths
|
|
84
|
-
} = this.supportCodeLibrary.originalCoordinates;
|
|
85
|
-
return requirePaths.some(p => p.endsWith('.ts')) || importPaths.some(p => p.endsWith('.ts'));
|
|
86
|
-
}
|
|
87
|
-
isPlaywrightStyle() {
|
|
88
|
-
const {
|
|
89
|
-
stepDefinitions
|
|
90
|
-
} = this.supportCodeLibrary;
|
|
91
|
-
return stepDefinitions.length > 0 ? stepDefinitions.some(step => (0, _defineStep.isPlaywrightStyle)(step)) : true;
|
|
92
|
-
}
|
|
93
|
-
isDecorators() {
|
|
94
|
-
const {
|
|
95
|
-
stepDefinitions
|
|
96
|
-
} = this.supportCodeLibrary;
|
|
97
|
-
const decoratorSteps = stepDefinitions.filter(step => {
|
|
98
|
-
var _getStepConfig;
|
|
99
|
-
return (_getStepConfig = (0, _defineStep.getStepConfig)(step)) === null || _getStepConfig === void 0 ? void 0 : _getStepConfig.isDecorator;
|
|
100
|
-
});
|
|
101
|
-
return decoratorSteps.length > stepDefinitions.length / 2;
|
|
102
|
-
}
|
|
103
|
-
printHeader() {
|
|
104
|
-
const lines = [`Missing steps found. Use snippets below:`];
|
|
105
|
-
if (this.bddBuiltInSyntax) {
|
|
106
|
-
if (this.isDecorators()) {
|
|
107
|
-
// TODO: For Decorators support
|
|
108
|
-
lines.push(`import { Fixture, Given, When, Then } from 'playwright-bdd/decorators';\n`);
|
|
109
|
-
} else {
|
|
110
|
-
lines.push(`import { createBdd } from '@zohodesk/testinglibrary';`, `const { Given, When, Then } = createBdd();\n`);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
lines.push(`import { Given, When, Then } from '@cucumber/cucumber';\n`);
|
|
114
|
-
}
|
|
115
|
-
_logger.logger.error(lines.join('\n\n'));
|
|
116
|
-
}
|
|
117
|
-
printSnippets(snippets) {
|
|
118
|
-
_logger.logger.error(snippets.concat(['']).join('\n\n'));
|
|
119
|
-
}
|
|
120
|
-
printFooter(snippets) {
|
|
121
|
-
(0, _utils.exitWithMessage)(`Missing step definitions (${snippets.length}).`, 'Use snippets above to create them.', this.getWarnOnZeroScannedFiles());
|
|
122
|
-
}
|
|
123
|
-
getWarnOnZeroScannedFiles() {
|
|
124
|
-
const {
|
|
125
|
-
requirePaths,
|
|
126
|
-
importPaths
|
|
127
|
-
} = this.supportCodeLibrary.originalCoordinates;
|
|
128
|
-
const scannedFilesCount = requirePaths.length + importPaths.length;
|
|
129
|
-
return scannedFilesCount === 0 && !this.isDecorators() ? `\nNote that 0 step definition files found, check the config.` : '';
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
exports.Snippets = Snippets;
|