@zohodesk/testinglibrary 0.0.7-exp.1 → 0.0.7-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 +7 -2
- package/.eslintrc.js +5 -1
- package/.gitlab-ci.yml +206 -0
- package/README.md +172 -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 +52 -0
- package/build/common/searchFake/steps/searchFake.spec.js +77 -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/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 +4 -4
- 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 +51 -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 +72 -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 -98
- package/build/core/playwright/readConfigFile.js +71 -25
- package/build/core/playwright/report-generator.js +9 -8
- 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/Project.js +35 -0
- package/build/core/playwright/setup/ProjectConfiguration.js +80 -0
- package/build/core/playwright/setup/config-creator.js +54 -33
- package/build/core/playwright/setup/config-utils.js +99 -16
- 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 +57 -43
- package/build/core/playwright/types.js +44 -0
- package/build/core/playwright/validateFeature.js +28 -0
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +1 -1
- package/build/index.d.ts +76 -3
- package/build/index.js +63 -17
- package/build/lib/cli.js +28 -4
- package/build/lib/post-install.js +19 -11
- package/build/parser/parser.js +0 -1
- 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 +10 -67
- 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 +8 -4
- 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 +7 -3
- package/build/setup-folder-structure/setupProject.js +34 -12
- 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 +8 -1
- package/build/utils/commonUtils.js +17 -0
- package/build/utils/fileUtils.js +60 -4
- package/build/utils/logger.js +1 -31
- package/build/utils/rootPath.js +16 -9
- package/build/utils/stepDefinitionsFormatter.js +1 -2
- package/changelog.md +167 -0
- package/jest.config.js +29 -11
- package/npm-shrinkwrap.json +9731 -6645
- package/package.json +34 -27
- package/playwright.config.js +0 -50
- package/test-results/.last-run.json +4 -0
- package/unit_reports/unit-report.html +260 -0
- package/Changelog.md +0 -49
- package/build/bdd-framework/cli/commands/env.js +0 -43
- package/build/bdd-framework/cli/commands/export.js +0 -48
- package/build/bdd-framework/cli/commands/test.js +0 -59
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -20
- 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 -91
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
- package/build/bdd-framework/cucumber/gherkin.d.js +0 -5
- 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 -57
- package/build/bdd-framework/cucumber/loadSteps.js +0 -35
- package/build/bdd-framework/decorators.js +0 -22
- package/build/bdd-framework/gen/formatter.js +0 -88
- package/build/bdd-framework/gen/i18n.js +0 -35
- package/build/bdd-framework/gen/index.js +0 -160
- package/build/bdd-framework/gen/poms.js +0 -46
- package/build/bdd-framework/gen/testFile.js +0 -356
- package/build/bdd-framework/gen/testNode.js +0 -48
- package/build/bdd-framework/gen/testPoms.js +0 -123
- package/build/bdd-framework/index.js +0 -45
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -77
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -46
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -41
- package/build/bdd-framework/playwright/transform.js +0 -80
- package/build/bdd-framework/playwright/types.js +0 -5
- package/build/bdd-framework/playwright/utils.js +0 -34
- package/build/bdd-framework/run/bddFixtures.js +0 -108
- package/build/bdd-framework/run/bddWorld.js +0 -87
- package/build/bdd-framework/snippets/index.js +0 -131
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -41
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
- package/build/bdd-framework/stepDefinitions/createBdd.js +0 -49
- package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -109
- package/build/bdd-framework/stepDefinitions/decorators/poms.js +0 -50
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -94
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -61
- package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
- package/build/bdd-framework/utils/index.js +0 -50
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -29
- package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
- package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
|
@@ -1,131 +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 _logger = require("../utils/logger");
|
|
10
|
-
var _stepConfig = require("../stepDefinitions/stepConfig");
|
|
11
|
-
/**
|
|
12
|
-
* Generate and show snippets for undefined steps
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
class Snippets {
|
|
16
|
-
files;
|
|
17
|
-
runConfiguration;
|
|
18
|
-
supportCodeLibrary;
|
|
19
|
-
snippetBuilder;
|
|
20
|
-
bddBuiltInSyntax = false;
|
|
21
|
-
constructor(files, runConfiguration, supportCodeLibrary) {
|
|
22
|
-
this.files = files;
|
|
23
|
-
this.runConfiguration = runConfiguration;
|
|
24
|
-
this.supportCodeLibrary = supportCodeLibrary;
|
|
25
|
-
}
|
|
26
|
-
async printSnippetsAndExit() {
|
|
27
|
-
this.snippetBuilder = await this.createSnippetBuilder();
|
|
28
|
-
const snippets = this.getSnippets();
|
|
29
|
-
this.printHeader();
|
|
30
|
-
this.printSnippets(snippets);
|
|
31
|
-
this.printFooter(snippets);
|
|
32
|
-
}
|
|
33
|
-
async createSnippetBuilder() {
|
|
34
|
-
const {
|
|
35
|
-
snippetInterface
|
|
36
|
-
} = this.runConfiguration.formats.options;
|
|
37
|
-
const snippetSyntax = this.getSnippetSyntax();
|
|
38
|
-
return (0, _loadSnippetBuilder.loadSnippetBuilder)(this.supportCodeLibrary, snippetInterface, snippetSyntax);
|
|
39
|
-
}
|
|
40
|
-
getSnippetSyntax() {
|
|
41
|
-
const {
|
|
42
|
-
snippetSyntax
|
|
43
|
-
} = this.runConfiguration.formats.options;
|
|
44
|
-
if (!snippetSyntax && this.isPlaywrightStyle()) {
|
|
45
|
-
this.bddBuiltInSyntax = true;
|
|
46
|
-
return this.isDecorators() ? require.resolve('./snippetSyntaxDecorators.js') : this.isTypeScript() ? require.resolve('./snippetSyntaxTs.js') : require.resolve('./snippetSyntax.js');
|
|
47
|
-
} else {
|
|
48
|
-
return snippetSyntax;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getSnippets() {
|
|
52
|
-
const snippetsSet = new Set();
|
|
53
|
-
const snippets = [];
|
|
54
|
-
this.files.forEach(file => {
|
|
55
|
-
file.undefinedSteps.forEach(undefinedStep => {
|
|
56
|
-
const {
|
|
57
|
-
snippet,
|
|
58
|
-
snippetWithLocation
|
|
59
|
-
} = this.getSnippet(file, snippets.length + 1, undefinedStep);
|
|
60
|
-
if (!snippetsSet.has(snippet)) {
|
|
61
|
-
snippetsSet.add(snippet);
|
|
62
|
-
snippets.push(snippetWithLocation);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
return snippets;
|
|
67
|
-
}
|
|
68
|
-
getSnippet(file, index, undefinedStep) {
|
|
69
|
-
const snippet = this.snippetBuilder.build({
|
|
70
|
-
keywordType: undefinedStep.keywordType,
|
|
71
|
-
pickleStep: undefinedStep.pickleStep
|
|
72
|
-
});
|
|
73
|
-
const {
|
|
74
|
-
line,
|
|
75
|
-
column
|
|
76
|
-
} = undefinedStep.step.location;
|
|
77
|
-
const snippetWithLocation = [`// ${index}. Missing step definition for "${file.sourceFile}:${line}:${column}"`, snippet].join('\n');
|
|
78
|
-
return {
|
|
79
|
-
snippet,
|
|
80
|
-
snippetWithLocation
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
isTypeScript() {
|
|
84
|
-
const {
|
|
85
|
-
requirePaths,
|
|
86
|
-
importPaths
|
|
87
|
-
} = this.supportCodeLibrary.originalCoordinates;
|
|
88
|
-
return requirePaths.some(p => p.endsWith('.ts')) || importPaths.some(p => p.endsWith('.ts'));
|
|
89
|
-
}
|
|
90
|
-
isPlaywrightStyle() {
|
|
91
|
-
const {
|
|
92
|
-
stepDefinitions
|
|
93
|
-
} = this.supportCodeLibrary;
|
|
94
|
-
return stepDefinitions.length > 0 ? stepDefinitions.some(step => (0, _stepConfig.isPlaywrightStyle)((0, _stepConfig.getStepConfig)(step))) : true;
|
|
95
|
-
}
|
|
96
|
-
isDecorators() {
|
|
97
|
-
const {
|
|
98
|
-
stepDefinitions
|
|
99
|
-
} = this.supportCodeLibrary;
|
|
100
|
-
const decoratorSteps = stepDefinitions.filter(step => (0, _stepConfig.isDecorator)((0, _stepConfig.getStepConfig)(step)));
|
|
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
|
-
lines.push(`import { Fixture, Given, When, Then } from 'playwright-bdd/decorators';\n`);
|
|
108
|
-
} else {
|
|
109
|
-
lines.push(`import { createBdd } from '@zohodesk/testinglibrary';`, `const { Given, When, Then } = createBdd();\n`);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
lines.push(`import { Given, When, Then } from '@cucumber/cucumber';\n`);
|
|
113
|
-
}
|
|
114
|
-
_logger.logger.error(lines.join('\n\n'));
|
|
115
|
-
}
|
|
116
|
-
printSnippets(snippets) {
|
|
117
|
-
_logger.logger.error(snippets.concat(['']).join('\n\n'));
|
|
118
|
-
}
|
|
119
|
-
printFooter(snippets) {
|
|
120
|
-
(0, _utils.exitWithMessage)(`Missing step definitions (${snippets.length}).`, 'Use snippets above to create them.', this.getWarnOnZeroScannedFiles());
|
|
121
|
-
}
|
|
122
|
-
getWarnOnZeroScannedFiles() {
|
|
123
|
-
const {
|
|
124
|
-
requirePaths,
|
|
125
|
-
importPaths
|
|
126
|
-
} = this.supportCodeLibrary.originalCoordinates;
|
|
127
|
-
const scannedFilesCount = requirePaths.length + importPaths.length;
|
|
128
|
-
return scannedFilesCount === 0 && !this.isDecorators() ? `\nNote that 0 step definition files found, check the config.` : '';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.Snippets = Snippets;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// todo: custom cucumber parameters
|
|
8
|
-
// See: https://github.com/cucumber/cucumber-expressions#custom-parameter-types
|
|
9
|
-
class _default {
|
|
10
|
-
isTypescript = false;
|
|
11
|
-
build({
|
|
12
|
-
generatedExpressions,
|
|
13
|
-
functionName,
|
|
14
|
-
stepParameterNames
|
|
15
|
-
}) {
|
|
16
|
-
// Always take only first generatedExpression
|
|
17
|
-
// Other expressions are for int/float combinations
|
|
18
|
-
const generatedExpression = generatedExpressions[0];
|
|
19
|
-
const expressionParameters = generatedExpression.parameterNames.map((name, i) => {
|
|
20
|
-
const argName = `arg${i === 0 ? '' : i}`;
|
|
21
|
-
const type = name.startsWith('string') ? 'string' : 'number';
|
|
22
|
-
return this.isTypescript ? `${argName}: ${type}` : argName;
|
|
23
|
-
});
|
|
24
|
-
const stepParameters = stepParameterNames.map(argName => {
|
|
25
|
-
const type = argName === 'dataTable' ? 'DataTable' : 'string';
|
|
26
|
-
return this.isTypescript ? `${argName}: ${type}` : argName;
|
|
27
|
-
});
|
|
28
|
-
const allParameterNames = ['{}', ...expressionParameters, ...stepParameters];
|
|
29
|
-
const functionSignature = `${functionName}('${this.escapeSpecialCharacters(generatedExpression)}', async (${allParameterNames.join(', ')}) => {`;
|
|
30
|
-
return [functionSignature, ` // ...`, '});'].join('\n');
|
|
31
|
-
}
|
|
32
|
-
escapeSpecialCharacters(generatedExpression) {
|
|
33
|
-
let source = generatedExpression.source;
|
|
34
|
-
// double up any backslashes because we're in a javascript string
|
|
35
|
-
source = source.replace(/\\/g, '\\\\');
|
|
36
|
-
// escape any single quotes because that's our quote delimiter
|
|
37
|
-
source = source.replace(/'/g, "\\'");
|
|
38
|
-
return source;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.default = _default;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class _default {
|
|
8
|
-
build({
|
|
9
|
-
generatedExpressions,
|
|
10
|
-
functionName
|
|
11
|
-
}) {
|
|
12
|
-
// Always take only first generatedExpression
|
|
13
|
-
// Other expressions are for int/float combinations
|
|
14
|
-
const generatedExpression = generatedExpressions[0];
|
|
15
|
-
return `@${functionName}('${this.escapeSpecialCharacters(generatedExpression)}')`;
|
|
16
|
-
}
|
|
17
|
-
escapeSpecialCharacters(generatedExpression) {
|
|
18
|
-
let source = generatedExpression.source;
|
|
19
|
-
// double up any backslashes because we're in a javascript string
|
|
20
|
-
source = source.replace(/\\/g, '\\\\');
|
|
21
|
-
// escape any single quotes because that's our quote delimiter
|
|
22
|
-
source = source.replace(/'/g, "\\'");
|
|
23
|
-
return source;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.default = _default;
|
|
@@ -1,18 +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.default = void 0;
|
|
8
|
-
var _snippetSyntax = _interopRequireDefault(require("./snippetSyntax"));
|
|
9
|
-
/**
|
|
10
|
-
* Playwright-style snippet syntax for typescript.
|
|
11
|
-
* Important to use separate file as it's simplest way to distinguish between js/ts
|
|
12
|
-
* without hooking into cucumber machinery.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
class _default extends _snippetSyntax.default {
|
|
16
|
-
isTypescript = true;
|
|
17
|
-
}
|
|
18
|
-
exports.default = _default;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createBdd = createBdd;
|
|
7
|
-
exports.extractFixtureNames = extractFixtureNames;
|
|
8
|
-
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
9
|
-
var _utils = require("../utils");
|
|
10
|
-
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
-
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
12
|
-
var _defineStep = require("./defineStep");
|
|
13
|
-
/**
|
|
14
|
-
* Stuff related to writing steps in Playwright-style.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function createBdd(customTest) {
|
|
18
|
-
const hasCustomTest = isCustomTest(customTest);
|
|
19
|
-
const Given = defineStepCtor('Given', hasCustomTest);
|
|
20
|
-
const When = defineStepCtor('When', hasCustomTest);
|
|
21
|
-
const Then = defineStepCtor('Then', hasCustomTest);
|
|
22
|
-
const Step = defineStepCtor('Unknown', hasCustomTest);
|
|
23
|
-
return {
|
|
24
|
-
Given,
|
|
25
|
-
When,
|
|
26
|
-
Then,
|
|
27
|
-
Step
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function defineStepCtor(keyword, hasCustomTest) {
|
|
31
|
-
return (pattern, fn) => {
|
|
32
|
-
(0, _defineStep.defineStep)({
|
|
33
|
-
keyword,
|
|
34
|
-
pattern,
|
|
35
|
-
fn,
|
|
36
|
-
hasCustomTest
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function extractFixtureNames(fn) {
|
|
41
|
-
return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
|
|
42
|
-
}
|
|
43
|
-
function isCustomTest(customTest) {
|
|
44
|
-
const isCustomTest = Boolean(customTest && customTest !== _bddFixtures.test);
|
|
45
|
-
if (isCustomTest && customTest && !(0, _testTypeImpl.isParentChildTest)(_bddFixtures.test, customTest)) {
|
|
46
|
-
(0, _utils.exitWithMessage)(`createBdd() should use test extended from "playwright-bdd"`);
|
|
47
|
-
}
|
|
48
|
-
return isCustomTest;
|
|
49
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Fixture = Fixture;
|
|
7
|
-
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
8
|
-
exports.createStepDecorator = createStepDecorator;
|
|
9
|
-
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
10
|
-
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
-
var _defineStep = require("./defineStep");
|
|
12
|
-
var _buildStepDefinition = require("../cucumber/buildStepDefinition");
|
|
13
|
-
/* eslint-disable no-unused-vars */
|
|
14
|
-
/**
|
|
15
|
-
* Define steps via decorators.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const pomGraph = new Map();
|
|
19
|
-
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
20
|
-
const decoratedSteps = new Set();
|
|
21
|
-
function Fixture(fixtureName) {
|
|
22
|
-
// context parameter is required for decorator by TS even though it's not used
|
|
23
|
-
return (Ctor, _context) => {
|
|
24
|
-
createPomNode(Ctor, fixtureName);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function createStepDecorator(keyword) {
|
|
28
|
-
return pattern => {
|
|
29
|
-
// context parameter is required for decorator by TS even though it's not used
|
|
30
|
-
return (method, _context) => {
|
|
31
|
-
method[decoratedStepSymbol] = {
|
|
32
|
-
keyword,
|
|
33
|
-
pattern,
|
|
34
|
-
fn: method,
|
|
35
|
-
hasCustomTest: true,
|
|
36
|
-
isDecorator: true
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function appendDecoratorSteps(supportCodeLibrary) {
|
|
42
|
-
decoratedSteps.forEach(stepConfig => {
|
|
43
|
-
const {
|
|
44
|
-
keyword,
|
|
45
|
-
pattern,
|
|
46
|
-
fn
|
|
47
|
-
} = stepConfig;
|
|
48
|
-
stepConfig.fn = (fixturesArg, ...args) => {
|
|
49
|
-
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
50
|
-
return fn.call(fixture, ...args);
|
|
51
|
-
};
|
|
52
|
-
const code = (0, _defineStep.buildCucumberStepFn)(stepConfig);
|
|
53
|
-
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
54
|
-
keyword,
|
|
55
|
-
pattern,
|
|
56
|
-
code,
|
|
57
|
-
line: 0,
|
|
58
|
-
// not used in playwright-bdd
|
|
59
|
-
options: {},
|
|
60
|
-
// not used in playwright-bdd
|
|
61
|
-
uri: '' // not used in playwright-bdd
|
|
62
|
-
}, supportCodeLibrary);
|
|
63
|
-
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
64
|
-
});
|
|
65
|
-
decoratedSteps.clear();
|
|
66
|
-
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function getPomNodeByFixtureName(fixtureName) {
|
|
70
|
-
for (const pomNode of pomGraph.values()) {
|
|
71
|
-
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function createPomNode(Ctor, fixtureName) {
|
|
75
|
-
const pomNode = {
|
|
76
|
-
fixtureName,
|
|
77
|
-
children: new Set()
|
|
78
|
-
};
|
|
79
|
-
pomGraph.set(Ctor, pomNode);
|
|
80
|
-
getDecoratedSteps(Ctor).forEach(stepConfig => {
|
|
81
|
-
stepConfig.pomNode = pomNode;
|
|
82
|
-
decoratedSteps.add(stepConfig);
|
|
83
|
-
});
|
|
84
|
-
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
85
|
-
if (!parentCtor) return;
|
|
86
|
-
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
87
|
-
parentPomNode === null || parentPomNode === void 0 || parentPomNode.children.add(pomNode);
|
|
88
|
-
return pomNode;
|
|
89
|
-
}
|
|
90
|
-
function getDecoratedSteps(Ctor) {
|
|
91
|
-
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return [];
|
|
92
|
-
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
93
|
-
return Object.keys(propertyDescriptors)
|
|
94
|
-
// filter out getters / setters
|
|
95
|
-
.filter(methodName => typeof propertyDescriptors[methodName].value === 'function').map(methodName => {
|
|
96
|
-
return propertyDescriptors[methodName].value[decoratedStepSymbol];
|
|
97
|
-
}).filter(Boolean);
|
|
98
|
-
}
|
|
99
|
-
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
100
|
-
// there should be exatcly one suitable fixture in fixturesArg
|
|
101
|
-
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
102
|
-
if (fixtureNames.length === 0) {
|
|
103
|
-
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
104
|
-
}
|
|
105
|
-
if (fixtureNames.length > 1) {
|
|
106
|
-
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
107
|
-
}
|
|
108
|
-
return fixturesArg[fixtureNames[0]];
|
|
109
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Fixture = Fixture;
|
|
7
|
-
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
8
|
-
var _steps = require("./steps");
|
|
9
|
-
/**
|
|
10
|
-
* POM classes marked with @Fixture
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Graph of POM class inheritance.
|
|
15
|
-
* Allows to guess correct fixture by step text.
|
|
16
|
-
*/
|
|
17
|
-
const pomGraph = new Map();
|
|
18
|
-
/**
|
|
19
|
-
* @Fixture decorator.
|
|
20
|
-
*/
|
|
21
|
-
function Fixture(fixtureName) {
|
|
22
|
-
// context parameter is required for decorator by TS even though it's not used
|
|
23
|
-
// eslint-disable-next-line no-unused-vars
|
|
24
|
-
return (Ctor, _context) => {
|
|
25
|
-
createPomNode(Ctor, fixtureName);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function createPomNode(Ctor, fixtureName) {
|
|
29
|
-
const pomNode = {
|
|
30
|
-
fixtureName,
|
|
31
|
-
children: new Set()
|
|
32
|
-
};
|
|
33
|
-
pomGraph.set(Ctor, pomNode);
|
|
34
|
-
(0, _steps.linkStepsWithPomNode)(Ctor, pomNode);
|
|
35
|
-
linkParentWithPomNode(Ctor, pomNode);
|
|
36
|
-
return pomNode;
|
|
37
|
-
}
|
|
38
|
-
function linkParentWithPomNode(Ctor, pomNode) {
|
|
39
|
-
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
40
|
-
if (!parentCtor) return;
|
|
41
|
-
// if parentCtor is not in pomGraph, add it as well
|
|
42
|
-
// Case: parent class is not marked with @Fixture, but has decorator steps (base class)
|
|
43
|
-
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
44
|
-
parentPomNode.children.add(pomNode);
|
|
45
|
-
}
|
|
46
|
-
function getPomNodeByFixtureName(fixtureName) {
|
|
47
|
-
for (const pomNode of pomGraph.values()) {
|
|
48
|
-
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
7
|
-
exports.createStepDecorator = createStepDecorator;
|
|
8
|
-
exports.linkStepsWithPomNode = linkStepsWithPomNode;
|
|
9
|
-
var _bddFixtures = require("../../run/bddFixtures");
|
|
10
|
-
var _buildStepDefinition = require("../../cucumber/buildStepDefinition");
|
|
11
|
-
var _defineStep = require("../defineStep");
|
|
12
|
-
/**
|
|
13
|
-
* Define steps via decorators.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// initially we sotre step data inside method,
|
|
17
|
-
// and then extract it in @Fixture decorator call
|
|
18
|
-
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
19
|
-
// global list of all decorator steps
|
|
20
|
-
const decoratedSteps = new Set();
|
|
21
|
-
/**
|
|
22
|
-
* Creates @Given, @When, @Then decorators.
|
|
23
|
-
*/
|
|
24
|
-
function createStepDecorator(keyword) {
|
|
25
|
-
return pattern => {
|
|
26
|
-
// context parameter is required for decorator by TS even though it's not used
|
|
27
|
-
// eslint-disable-next-line no-unused-vars
|
|
28
|
-
return (method, _context) => {
|
|
29
|
-
saveStepConfigToMethod(method, {
|
|
30
|
-
keyword,
|
|
31
|
-
pattern,
|
|
32
|
-
fn: method,
|
|
33
|
-
hasCustomTest: true
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function linkStepsWithPomNode(Ctor, pomNode) {
|
|
39
|
-
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return;
|
|
40
|
-
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
41
|
-
return Object.values(propertyDescriptors).forEach(descriptor => {
|
|
42
|
-
const stepConfig = getStepConfigFromMethod(descriptor);
|
|
43
|
-
if (!stepConfig) return;
|
|
44
|
-
stepConfig.pomNode = pomNode;
|
|
45
|
-
decoratedSteps.add(stepConfig);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
50
|
-
*/
|
|
51
|
-
function appendDecoratorSteps(supportCodeLibrary) {
|
|
52
|
-
decoratedSteps.forEach(stepConfig => {
|
|
53
|
-
const {
|
|
54
|
-
keyword,
|
|
55
|
-
pattern,
|
|
56
|
-
fn
|
|
57
|
-
} = stepConfig;
|
|
58
|
-
stepConfig.fn = (fixturesArg, ...args) => {
|
|
59
|
-
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
60
|
-
return fn.call(fixture, ...args);
|
|
61
|
-
};
|
|
62
|
-
const code = (0, _defineStep.buildCucumberStepCode)(stepConfig);
|
|
63
|
-
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
64
|
-
keyword,
|
|
65
|
-
pattern,
|
|
66
|
-
code,
|
|
67
|
-
line: 0,
|
|
68
|
-
options: {},
|
|
69
|
-
uri: '' // not used in playwright-bdd
|
|
70
|
-
}, supportCodeLibrary);
|
|
71
|
-
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
72
|
-
});
|
|
73
|
-
decoratedSteps.clear();
|
|
74
|
-
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
78
|
-
// there should be exatcly one suitable fixture in fixturesArg
|
|
79
|
-
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
80
|
-
if (fixtureNames.length === 0) {
|
|
81
|
-
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
82
|
-
}
|
|
83
|
-
if (fixtureNames.length > 1) {
|
|
84
|
-
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
85
|
-
}
|
|
86
|
-
return fixturesArg[fixtureNames[0]];
|
|
87
|
-
}
|
|
88
|
-
function saveStepConfigToMethod(method, stepConfig) {
|
|
89
|
-
method[decoratedStepSymbol] = stepConfig;
|
|
90
|
-
}
|
|
91
|
-
function getStepConfigFromMethod(descriptor) {
|
|
92
|
-
// filter out getters / setters
|
|
93
|
-
return typeof descriptor.value === 'function' ? descriptor.value[decoratedStepSymbol] : undefined;
|
|
94
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.buildCucumberStepCode = buildCucumberStepCode;
|
|
7
|
-
exports.defineStep = defineStep;
|
|
8
|
-
exports.getStepCode = getStepCode;
|
|
9
|
-
var _cucumber = require("@cucumber/cucumber");
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
/**
|
|
12
|
-
* Defines step by config.
|
|
13
|
-
* Calls cucumber's Given(), When(), Then() under the hood.
|
|
14
|
-
*/
|
|
15
|
-
function defineStep(stepConfig) {
|
|
16
|
-
const {
|
|
17
|
-
keyword,
|
|
18
|
-
pattern
|
|
19
|
-
} = stepConfig;
|
|
20
|
-
const cucumberDefineStepFn = getCucumberDefineStepFn(keyword);
|
|
21
|
-
const code = buildCucumberStepCode(stepConfig);
|
|
22
|
-
try {
|
|
23
|
-
cucumberDefineStepFn(pattern, code);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
// todo: detect that this is import from test file
|
|
26
|
-
// and skip/delay registering cucumber steps until cucumber is loaded
|
|
27
|
-
const isMissingCucumber = /Cucumber that isn't running/i.test(e.message);
|
|
28
|
-
if (isMissingCucumber) {
|
|
29
|
-
(0, _utils.exitWithMessage)(`Option "importTestFrom" should point to separate file without step definitions`, `(e.g. without calls of Given, When, Then)`);
|
|
30
|
-
} else {
|
|
31
|
-
throw e;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function buildCucumberStepCode(stepConfig) {
|
|
36
|
-
const code = function (...args) {
|
|
37
|
-
const fixturesArg = Object.assign({}, this.customFixtures, {
|
|
38
|
-
$testInfo: this.testInfo,
|
|
39
|
-
$test: this.test,
|
|
40
|
-
$tags: this.tags
|
|
41
|
-
});
|
|
42
|
-
return stepConfig.fn.call(this, fixturesArg, ...args);
|
|
43
|
-
};
|
|
44
|
-
code.stepConfig = stepConfig;
|
|
45
|
-
return code;
|
|
46
|
-
}
|
|
47
|
-
function getStepCode(stepDefinition) {
|
|
48
|
-
return stepDefinition.code;
|
|
49
|
-
}
|
|
50
|
-
function getCucumberDefineStepFn(keyword) {
|
|
51
|
-
switch (keyword) {
|
|
52
|
-
case 'Given':
|
|
53
|
-
return _cucumber.Given;
|
|
54
|
-
case 'When':
|
|
55
|
-
return _cucumber.When;
|
|
56
|
-
case 'Then':
|
|
57
|
-
return _cucumber.Then;
|
|
58
|
-
default:
|
|
59
|
-
return _cucumber.defineStep;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getStepConfig = getStepConfig;
|
|
7
|
-
exports.isDecorator = isDecorator;
|
|
8
|
-
exports.isPlaywrightStyle = isPlaywrightStyle;
|
|
9
|
-
/**
|
|
10
|
-
* Playwright-bdd's step config.
|
|
11
|
-
*/
|
|
12
|
-
function getStepConfig(step) {
|
|
13
|
-
return step.code.stepConfig;
|
|
14
|
-
}
|
|
15
|
-
function isDecorator(stepConfig) {
|
|
16
|
-
return Boolean(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.pomNode);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Cucumber-style steps don't have stepConfig
|
|
20
|
-
* b/c they created directly via cucumber's Given, When, Then.
|
|
21
|
-
*/
|
|
22
|
-
function isPlaywrightStyle(stepConfig) {
|
|
23
|
-
return Boolean(stepConfig);
|
|
24
|
-
}
|
|
@@ -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.exitWithMessage = exitWithMessage;
|
|
8
|
-
exports.getPackageVersion = getPackageVersion;
|
|
9
|
-
exports.getSymbolByName = getSymbolByName;
|
|
10
|
-
exports.removeDuplicates = removeDuplicates;
|
|
11
|
-
exports.resolvePackageRoot = resolvePackageRoot;
|
|
12
|
-
exports.template = template;
|
|
13
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
14
|
-
var _path = _interopRequireDefault(require("path"));
|
|
15
|
-
var _logger = require("./logger");
|
|
16
|
-
function exitWithMessage(...messages) {
|
|
17
|
-
_logger.logger.error('ERROR:', ...messages.filter(Boolean));
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
// See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
21
|
-
function getSymbolByName(target, name) {
|
|
22
|
-
const ownKeys = Reflect.ownKeys(target);
|
|
23
|
-
const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
|
|
24
|
-
if (!symbol) {
|
|
25
|
-
throw new Error(`Symbol "${name}" not found in target. ownKeys: ${ownKeys}`);
|
|
26
|
-
}
|
|
27
|
-
return symbol;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Inserts params into template.
|
|
31
|
-
* Params defined as <param>.
|
|
32
|
-
*/
|
|
33
|
-
function template(t, params = {}) {
|
|
34
|
-
return t.replace(/<(.+?)>/g, (match, key) => {
|
|
35
|
-
return params[key] !== undefined ? String(params[key]) : match;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function removeDuplicates(arr) {
|
|
39
|
-
return [...new Set(arr)];
|
|
40
|
-
}
|
|
41
|
-
function resolvePackageRoot(packageName) {
|
|
42
|
-
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
43
|
-
return _path.default.dirname(packageJsonPath);
|
|
44
|
-
}
|
|
45
|
-
function getPackageVersion(packageName) {
|
|
46
|
-
const packageRoot = resolvePackageRoot(packageName);
|
|
47
|
-
const packageJsonPath = _path.default.join(packageRoot, 'package.json');
|
|
48
|
-
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
49
|
-
return packageJson.version || '';
|
|
50
|
-
}
|