@zohodesk/testinglibrary 2.9.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -1
- package/README.md +27 -1
- package/build/core/playwright/fixtures.js +24 -0
- package/build/core/playwright/helpers/fileMutex.js +10 -12
- package/build/core/playwright/index.js +10 -23
- package/build/core/playwright/setup/config-creator.js +3 -3
- package/build/core/playwright/setup/config-utils.js +8 -25
- package/build/core/playwright/tagProcessor.js +18 -28
- package/build/core/playwright/test-runner.js +1 -1
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +1 -1
- package/build/setup-folder-structure/samples/actors-index.js +2 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
- 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/settings.json +7 -0
- package/build/setup-folder-structure/setupProject.js +18 -5
- package/nobdd/uat/conf/nobdd/uat.config.js +1 -2
- package/nobdd/uat.config.js +1 -2
- package/package.json +7 -7
- package/build/bdd-framework/cli/commands/env.js +0 -42
- package/build/bdd-framework/cli/commands/export.js +0 -62
- package/build/bdd-framework/cli/commands/test.js +0 -64
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -19
- package/build/bdd-framework/cli/worker.js +0 -13
- package/build/bdd-framework/config/configDir.js +0 -35
- package/build/bdd-framework/config/enrichReporterData.js +0 -23
- package/build/bdd-framework/config/env.js +0 -50
- package/build/bdd-framework/config/index.js +0 -94
- package/build/bdd-framework/config/lang.js +0 -14
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
- package/build/bdd-framework/cucumber/createTestStep.js +0 -43
- package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
- package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
- package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
- package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
- package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
- package/build/bdd-framework/cucumber/formatter/index.js +0 -16
- package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
- package/build/bdd-framework/cucumber/loadConfig.js +0 -17
- package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
- package/build/bdd-framework/cucumber/loadSteps.js +0 -47
- package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
- package/build/bdd-framework/cucumber/stepArguments.js +0 -21
- package/build/bdd-framework/cucumber/types.js +0 -5
- package/build/bdd-framework/cucumber/valueChecker.js +0 -23
- package/build/bdd-framework/decorators.js +0 -18
- package/build/bdd-framework/gen/fixtures.js +0 -48
- package/build/bdd-framework/gen/formatter.js +0 -167
- package/build/bdd-framework/gen/i18n.js +0 -39
- package/build/bdd-framework/gen/index.js +0 -197
- package/build/bdd-framework/gen/specialTags.js +0 -70
- package/build/bdd-framework/gen/testFile.js +0 -470
- package/build/bdd-framework/gen/testMeta.js +0 -60
- package/build/bdd-framework/gen/testNode.js +0 -35
- package/build/bdd-framework/gen/testPoms.js +0 -133
- package/build/bdd-framework/hooks/scenario.js +0 -130
- package/build/bdd-framework/hooks/worker.js +0 -89
- package/build/bdd-framework/index.js +0 -52
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/loadUtils.js +0 -33
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
- package/build/bdd-framework/playwright/transform.js +0 -88
- package/build/bdd-framework/playwright/types.js +0 -12
- package/build/bdd-framework/playwright/utils.js +0 -56
- package/build/bdd-framework/reporter/cucumber/base.js +0 -52
- package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
- package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
- package/build/bdd-framework/reporter/cucumber/html.js +0 -40
- package/build/bdd-framework/reporter/cucumber/index.js +0 -74
- package/build/bdd-framework/reporter/cucumber/json.js +0 -312
- package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
- package/build/bdd-framework/reporter/cucumber/message.js +0 -20
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
- package/build/bdd-framework/run/StepInvoker.js +0 -69
- package/build/bdd-framework/run/bddData/index.js +0 -59
- package/build/bdd-framework/run/bddData/types.js +0 -5
- package/build/bdd-framework/run/bddFixtures.js +0 -192
- package/build/bdd-framework/run/bddWorld.js +0 -79
- package/build/bdd-framework/run/bddWorldInternal.js +0 -11
- package/build/bdd-framework/snippets/index.js +0 -132
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
- 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 -66
- package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
- package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
- package/build/bdd-framework/steps/createBdd.js +0 -78
- package/build/bdd-framework/steps/decorators/class.js +0 -68
- package/build/bdd-framework/steps/decorators/steps.js +0 -98
- package/build/bdd-framework/steps/defineStep.js +0 -62
- package/build/bdd-framework/steps/stepConfig.js +0 -24
- package/build/bdd-framework/utils/AutofillMap.js +0 -20
- package/build/bdd-framework/utils/exit.js +0 -62
- package/build/bdd-framework/utils/index.js +0 -93
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -30
- package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
- package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
- package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
- package/nobdd/src/App.js +0 -7
- package/npm-shrinkwrap.json +0 -6475
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Formatter = void 0;
|
|
7
|
-
var _jsStringWrap = require("../utils/jsStringWrap");
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
var _utils2 = require("../playwright/utils");
|
|
10
|
-
/**
|
|
11
|
-
* Helper to format Playwright test file.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const supportsTags = _utils2.playwrightVersion >= '1.42.0';
|
|
15
|
-
class Formatter {
|
|
16
|
-
config;
|
|
17
|
-
constructor(config) {
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
fileHeader(featureUri, importTestFrom) {
|
|
21
|
-
// always use "/" for imports, see #91
|
|
22
|
-
const importTestFromFile = (0, _utils.toPosixPath)((importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.file) || '@zohodesk/testinglibrary');
|
|
23
|
-
let varName = (importTestFrom === null || importTestFrom === void 0 ? void 0 : importTestFrom.varName) || 'test';
|
|
24
|
-
if (varName !== 'test') {
|
|
25
|
-
varName = `${varName} as test`;
|
|
26
|
-
}
|
|
27
|
-
return [`/** Generated from: ${featureUri} */`,
|
|
28
|
-
// prettier-ignore
|
|
29
|
-
// this.quoted() is not possible for 'import from' as backticks not parsed
|
|
30
|
-
`import { ${varName} } from ${JSON.stringify(importTestFromFile)};`, ''];
|
|
31
|
-
}
|
|
32
|
-
describe(node, children) {
|
|
33
|
-
const firstLine = `test.${this.getFunction('describe', node)}(${this.quoted(node.title)}, () => {`;
|
|
34
|
-
if (!children.length) {
|
|
35
|
-
return [`${firstLine}});`, ''];
|
|
36
|
-
}
|
|
37
|
-
return [firstLine,
|
|
38
|
-
// prettier-ignore
|
|
39
|
-
...this.describeConfigure(node).map(indent), '', ...children.map(indent), `});`, ''];
|
|
40
|
-
}
|
|
41
|
-
beforeEach(fixtures, children) {
|
|
42
|
-
const fixturesStr = [...fixtures].join(', ');
|
|
43
|
-
// prettier-ignore
|
|
44
|
-
return [`test.beforeEach(async ({ ${fixturesStr} }) => {`, ...children.map(indent), `});`, ''];
|
|
45
|
-
}
|
|
46
|
-
test(node, fixtures, children) {
|
|
47
|
-
const fixturesStr = [...fixtures].join(', ');
|
|
48
|
-
const title = this.quoted(node.title);
|
|
49
|
-
const tags = this.testTags(node);
|
|
50
|
-
const firstLine = `${this.getFunction('test', node)}(${title}, ${tags}async ({ ${fixturesStr} }) => {`;
|
|
51
|
-
if (!children.length) {
|
|
52
|
-
return [`${firstLine}});`, ''];
|
|
53
|
-
}
|
|
54
|
-
const lines = [firstLine,
|
|
55
|
-
// prettier-ignore
|
|
56
|
-
...children.map(indent), `});`, ''];
|
|
57
|
-
// wrap test into anonymous describe in case of retries / timeout tags
|
|
58
|
-
const specialTagsConfigure = this.describeConfigure(node);
|
|
59
|
-
return specialTagsConfigure.length ? ['test.describe(() => {',
|
|
60
|
-
// prettier-ignore
|
|
61
|
-
...specialTagsConfigure.map(indent), '', ...lines.map(indent), `});`, ''] : lines;
|
|
62
|
-
}
|
|
63
|
-
// eslint-disable-next-line max-params
|
|
64
|
-
step(keyword, text, argument, fixtureNames = []) {
|
|
65
|
-
const fixtures = fixtureNames.length ? `{ ${fixtureNames.join(', ')} }` : '';
|
|
66
|
-
const argumentArg = argument ? JSON.stringify(argument) : fixtures ? 'null' : '';
|
|
67
|
-
const textArg = this.quoted(text);
|
|
68
|
-
const args = [textArg, argumentArg, fixtures].filter(arg => arg !== '').join(', ');
|
|
69
|
-
return `await ${keyword}(${args});`;
|
|
70
|
-
}
|
|
71
|
-
missingStep(keyword, text) {
|
|
72
|
-
return `// missing step: ${keyword}(${this.quoted(text)});`;
|
|
73
|
-
}
|
|
74
|
-
technicalSection(testMetaBuilder, featureUri, fixtures) {
|
|
75
|
-
return ['// == technical section ==',
|
|
76
|
-
// prettier-ignore
|
|
77
|
-
'', 'test.use({', ...['$test: ({}, use) => use(test),', '$testMetaMap: ({}, use) => use(testMetaMap),', `$uri: ({}, use) => use(${this.quoted(featureUri)}),`, ...fixtures].map(indent), '});', '', 'const testMetaMap = {', ...testMetaBuilder.getObjectLines().map(indent), '};'];
|
|
78
|
-
}
|
|
79
|
-
bddWorldFixtures() {
|
|
80
|
-
const fixturesObj = {
|
|
81
|
-
page: null,
|
|
82
|
-
context: null,
|
|
83
|
-
browser: null,
|
|
84
|
-
browserName: null,
|
|
85
|
-
request: null
|
|
86
|
-
};
|
|
87
|
-
const fixtures = Object.keys(fixturesObj).join(', ');
|
|
88
|
-
return [`$bddWorldFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
|
|
89
|
-
}
|
|
90
|
-
scenarioHookFixtures(fixtureNames) {
|
|
91
|
-
if (!fixtureNames.length) {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
const fixtures = fixtureNames.join(', ');
|
|
95
|
-
return [`$scenarioHookFixtures: ({ ${fixtures} }, use) => use({ ${fixtures} }),`];
|
|
96
|
-
}
|
|
97
|
-
workerHookFixtures(fixtureNames) {
|
|
98
|
-
if (!fixtureNames.length) {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
const fixtures = fixtureNames.join(', ');
|
|
102
|
-
const scope = this.quoted('worker');
|
|
103
|
-
return [`$workerHookFixtures: [({ ${fixtures} }, use) => use({ ${fixtures} }), { scope: ${scope} }],`];
|
|
104
|
-
}
|
|
105
|
-
langFixture(lang) {
|
|
106
|
-
return [`$lang: ({}, use) => use(${this.quoted(lang)}),`];
|
|
107
|
-
}
|
|
108
|
-
// eslint-disable-next-line complexity
|
|
109
|
-
getFunction(baseFn, node) {
|
|
110
|
-
if (node.specialTags.only) {
|
|
111
|
-
return `${baseFn}.only`;
|
|
112
|
-
}
|
|
113
|
-
// describe.fail is not supported
|
|
114
|
-
if (baseFn === 'test' && node.specialTags.fail) {
|
|
115
|
-
return `${baseFn}.fail`;
|
|
116
|
-
}
|
|
117
|
-
if (node.specialTags.skip) {
|
|
118
|
-
return `${baseFn}.skip`;
|
|
119
|
-
}
|
|
120
|
-
if (node.specialTags.fixme) {
|
|
121
|
-
return `${baseFn}.fixme`;
|
|
122
|
-
}
|
|
123
|
-
return baseFn;
|
|
124
|
-
}
|
|
125
|
-
describeConfigure(node) {
|
|
126
|
-
const options = {};
|
|
127
|
-
const {
|
|
128
|
-
retries,
|
|
129
|
-
timeout,
|
|
130
|
-
mode
|
|
131
|
-
} = node.specialTags;
|
|
132
|
-
if (retries !== undefined) {
|
|
133
|
-
options.retries = retries;
|
|
134
|
-
}
|
|
135
|
-
if (timeout !== undefined) {
|
|
136
|
-
options.timeout = timeout;
|
|
137
|
-
}
|
|
138
|
-
if (mode !== undefined) {
|
|
139
|
-
options.mode = mode;
|
|
140
|
-
}
|
|
141
|
-
return Object.keys(options).length ? [`test.describe.configure(${JSON.stringify(options)});`] : [];
|
|
142
|
-
}
|
|
143
|
-
testTags(node) {
|
|
144
|
-
return supportsTags && node.tags.length ? `{ tag: [${node.tags.map(tag => this.quoted(tag)).join(', ')}] }, ` : '';
|
|
145
|
-
}
|
|
146
|
-
testTimeout(node) {
|
|
147
|
-
const {
|
|
148
|
-
timeout
|
|
149
|
-
} = node.specialTags;
|
|
150
|
-
return timeout !== undefined ? [`test.setTimeout(${timeout});`] : [];
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Apply this function only to string literals (mostly titles here).
|
|
154
|
-
* Objects and arrays are handled with JSON.strinigfy,
|
|
155
|
-
* b/c object keys can't be in backticks.
|
|
156
|
-
* See: https://stackoverflow.com/questions/33194138/template-string-as-object-property-name
|
|
157
|
-
*/
|
|
158
|
-
quoted(str) {
|
|
159
|
-
return (0, _jsStringWrap.jsStringWrap)(str, {
|
|
160
|
-
quotes: this.config.quotes
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.Formatter = Formatter;
|
|
165
|
-
function indent(value) {
|
|
166
|
-
return value ? `${' '}${value}` : value;
|
|
167
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getKeywordsMap = getKeywordsMap;
|
|
7
|
-
var _gherkin = require("@cucumber/gherkin");
|
|
8
|
-
/**
|
|
9
|
-
* Get i18n keywords.
|
|
10
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
function getKeywordsMap(language) {
|
|
14
|
-
const origMap = _gherkin.dialects[language];
|
|
15
|
-
if (!origMap) {
|
|
16
|
-
throw new Error(`Language not found: ${language}`);
|
|
17
|
-
}
|
|
18
|
-
const targetMap = new Map();
|
|
19
|
-
const enKeywords = Object.keys(origMap);
|
|
20
|
-
enKeywords.forEach(enKeyword => handleKeyword(enKeyword, origMap, targetMap));
|
|
21
|
-
return targetMap;
|
|
22
|
-
}
|
|
23
|
-
function handleKeyword(enKeyword, origMap, targetMap) {
|
|
24
|
-
const nativeKeywords = origMap[enKeyword];
|
|
25
|
-
// Array.isArray converts to any[]
|
|
26
|
-
if (typeof nativeKeywords === 'string') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
nativeKeywords.forEach(nativeKeyword => {
|
|
30
|
-
nativeKeyword = nativeKeyword.trim();
|
|
31
|
-
if (!nativeKeyword || nativeKeyword === '*') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function capitalizeFirstLetter(s) {
|
|
38
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
39
|
-
}
|
|
@@ -1,197 +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.TestFilesGenerator = void 0;
|
|
8
|
-
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
11
|
-
var _testFile = require("./testFile");
|
|
12
|
-
var _loadConfig = require("../cucumber/loadConfig");
|
|
13
|
-
var _loadFeatures = require("../cucumber/loadFeatures");
|
|
14
|
-
var _loadSteps = require("../cucumber/loadSteps");
|
|
15
|
-
var _config = require("../config");
|
|
16
|
-
var _snippets = require("../snippets");
|
|
17
|
-
var _steps = require("../steps/decorators/steps");
|
|
18
|
-
var _transform = require("../playwright/transform");
|
|
19
|
-
var _configDir = require("../config/configDir");
|
|
20
|
-
var _logger = require("../utils/logger");
|
|
21
|
-
var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
|
|
22
|
-
var _exit = require("../utils/exit");
|
|
23
|
-
var _createBdd = require("../steps/createBdd");
|
|
24
|
-
var _resolveFeaturePaths = require("../cucumber/resolveFeaturePaths");
|
|
25
|
-
/**
|
|
26
|
-
* Generate playwright test files from Gherkin documents.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
class TestFilesGenerator {
|
|
30
|
-
config;
|
|
31
|
-
// all these props are exist
|
|
32
|
-
runConfiguration;
|
|
33
|
-
featuresLoader = new _loadFeatures.FeaturesLoader();
|
|
34
|
-
supportCodeLibrary;
|
|
35
|
-
files = [];
|
|
36
|
-
tagsExpression;
|
|
37
|
-
logger;
|
|
38
|
-
constructor(config) {
|
|
39
|
-
this.config = config;
|
|
40
|
-
this.logger = new _logger.Logger({
|
|
41
|
-
verbose: config.verbose
|
|
42
|
-
});
|
|
43
|
-
if (config.tags) {
|
|
44
|
-
this.tagsExpression = (0, _tagExpressions.default)(config.tags);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async generate() {
|
|
48
|
-
await (0, _exit.withExitHandler)(async () => {
|
|
49
|
-
await this.loadCucumberConfig();
|
|
50
|
-
await Promise.all([this.loadFeatures(), this.loadSteps()]);
|
|
51
|
-
this.buildFiles();
|
|
52
|
-
await this.checkUndefinedSteps();
|
|
53
|
-
this.checkImportTestFrom();
|
|
54
|
-
await this.clearOutputDir();
|
|
55
|
-
await this.saveFiles();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async extractSteps() {
|
|
59
|
-
await this.loadCucumberConfig();
|
|
60
|
-
await this.loadSteps();
|
|
61
|
-
return this.supportCodeLibrary.stepDefinitions;
|
|
62
|
-
}
|
|
63
|
-
// todo: combine with extractSteps
|
|
64
|
-
async extractUnusedSteps() {
|
|
65
|
-
await this.loadCucumberConfig();
|
|
66
|
-
await Promise.all([this.loadFeatures(), this.loadSteps()]);
|
|
67
|
-
this.buildFiles();
|
|
68
|
-
return this.supportCodeLibrary.stepDefinitions.filter(stepDefinition => {
|
|
69
|
-
const isUsed = this.files.some(file => file.usedStepDefinitions.has(stepDefinition));
|
|
70
|
-
return !isUsed;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async loadCucumberConfig() {
|
|
74
|
-
const environment = {
|
|
75
|
-
cwd: (0, _configDir.getPlaywrightConfigDir)()
|
|
76
|
-
};
|
|
77
|
-
const {
|
|
78
|
-
runConfiguration
|
|
79
|
-
} = await (0, _loadConfig.loadConfig)({
|
|
80
|
-
provided: (0, _config.extractCucumberConfig)(this.config)
|
|
81
|
-
}, environment);
|
|
82
|
-
this.runConfiguration = runConfiguration;
|
|
83
|
-
this.warnForTsNodeRegister();
|
|
84
|
-
}
|
|
85
|
-
async loadFeatures() {
|
|
86
|
-
const cwd = (0, _configDir.getPlaywrightConfigDir)();
|
|
87
|
-
const {
|
|
88
|
-
defaultDialect
|
|
89
|
-
} = this.runConfiguration.sources;
|
|
90
|
-
const {
|
|
91
|
-
featurePaths
|
|
92
|
-
} = await (0, _resolveFeaturePaths.resovleFeaturePaths)(this.runConfiguration, {
|
|
93
|
-
cwd
|
|
94
|
-
});
|
|
95
|
-
this.logger.log(`Loading features from paths (${featurePaths.length}):`);
|
|
96
|
-
featurePaths.forEach(featurePath => this.logger.log(featurePath));
|
|
97
|
-
if (featurePaths.length) {
|
|
98
|
-
await this.featuresLoader.load(featurePaths, {
|
|
99
|
-
relativeTo: cwd,
|
|
100
|
-
defaultDialect
|
|
101
|
-
});
|
|
102
|
-
this.handleParseErrors();
|
|
103
|
-
}
|
|
104
|
-
this.logger.log(`Loaded features: ${this.featuresLoader.getDocumentsCount()}`);
|
|
105
|
-
}
|
|
106
|
-
async loadSteps() {
|
|
107
|
-
const {
|
|
108
|
-
requirePaths,
|
|
109
|
-
importPaths
|
|
110
|
-
} = this.runConfiguration.support;
|
|
111
|
-
this.logger.log(`Loading steps from: ${requirePaths.concat(importPaths).join(', ')}`);
|
|
112
|
-
const environment = {
|
|
113
|
-
cwd: (0, _configDir.getPlaywrightConfigDir)()
|
|
114
|
-
};
|
|
115
|
-
this.supportCodeLibrary = await (0, _loadSteps.loadSteps)(this.runConfiguration, environment);
|
|
116
|
-
await this.loadDecoratorSteps();
|
|
117
|
-
this.logger.log(`Loaded steps: ${this.supportCodeLibrary.stepDefinitions.length}`);
|
|
118
|
-
}
|
|
119
|
-
async loadDecoratorSteps() {
|
|
120
|
-
const {
|
|
121
|
-
importTestFrom
|
|
122
|
-
} = this.config;
|
|
123
|
-
if (importTestFrom) {
|
|
124
|
-
// require importTestFrom for case when it is not required by step definitions
|
|
125
|
-
// possible re-require but it's not a problem as it is cached by Node.js
|
|
126
|
-
await (0, _transform.requireTransform)().requireOrImport(importTestFrom.file);
|
|
127
|
-
(0, _steps.appendDecoratorSteps)(this.supportCodeLibrary);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
buildFiles() {
|
|
131
|
-
this.files = this.featuresLoader.getDocumentsWithPickles().map(gherkinDocument => {
|
|
132
|
-
return new _testFile.TestFile({
|
|
133
|
-
gherkinDocument,
|
|
134
|
-
supportCodeLibrary: this.supportCodeLibrary,
|
|
135
|
-
// doc.uri is always relative to cwd (coming after cucumber handling)
|
|
136
|
-
// see: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts#L51
|
|
137
|
-
outputPath: this.getSpecPathByFeaturePath(gherkinDocument.uri),
|
|
138
|
-
config: this.config,
|
|
139
|
-
tagsExpression: this.tagsExpression
|
|
140
|
-
}).build();
|
|
141
|
-
}).filter(file => file.testCount > 0);
|
|
142
|
-
}
|
|
143
|
-
getSpecPathByFeaturePath(relFeaturePath) {
|
|
144
|
-
const configDir = (0, _configDir.getPlaywrightConfigDir)();
|
|
145
|
-
const absFeaturePath = _path.default.resolve(configDir, relFeaturePath);
|
|
146
|
-
const relOutputPath = _path.default.relative(this.config.featuresRoot, absFeaturePath);
|
|
147
|
-
if (relOutputPath.startsWith('..')) {
|
|
148
|
-
(0, _exit.exit)(`All feature files should be located underneath featuresRoot.`, `Please change featuresRoot or paths in configuration.\n`, `featureFile: ${absFeaturePath}\n`, `featuresRoot: ${this.config.featuresRoot}\n`);
|
|
149
|
-
}
|
|
150
|
-
const absOutputPath = _path.default.resolve(this.config.outputDir, relOutputPath);
|
|
151
|
-
return `${absOutputPath}.spec.js`;
|
|
152
|
-
}
|
|
153
|
-
async checkUndefinedSteps() {
|
|
154
|
-
const undefinedSteps = this.files.reduce((sum, file) => sum + file.undefinedSteps.length, 0);
|
|
155
|
-
if (undefinedSteps > 0) {
|
|
156
|
-
const snippets = new _snippets.Snippets(this.files, this.runConfiguration, this.supportCodeLibrary);
|
|
157
|
-
await snippets.print();
|
|
158
|
-
(0, _exit.exit)();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
checkImportTestFrom() {
|
|
162
|
-
if (_createBdd.hasCustomTest && !this.config.importTestFrom) {
|
|
163
|
-
(0, _exit.exit)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async saveFiles() {
|
|
167
|
-
this.files.forEach(file => {
|
|
168
|
-
file.save();
|
|
169
|
-
this.logger.log(`Generated: ${_path.default.relative(process.cwd(), file.outputPath)}`);
|
|
170
|
-
});
|
|
171
|
-
this.logger.log(`Generated files: ${this.files.length}`);
|
|
172
|
-
}
|
|
173
|
-
async clearOutputDir() {
|
|
174
|
-
const pattern = `${_fastGlob.default.convertPathToPattern(this.config.outputDir)}/**/*.spec.js`;
|
|
175
|
-
const testFiles = await (0, _fastGlob.default)(pattern);
|
|
176
|
-
this.logger.log(`Clearing output dir: ${testFiles.length} file(s)`);
|
|
177
|
-
const tasks = testFiles.map(testFile => _promises.default.rm(testFile));
|
|
178
|
-
await Promise.all(tasks);
|
|
179
|
-
}
|
|
180
|
-
warnForTsNodeRegister() {
|
|
181
|
-
if ((0, _loadSteps.hasTsNodeRegister)(this.runConfiguration)) {
|
|
182
|
-
this.logger.warn(`WARNING: usage of requireModule: ['ts-node/register'] is not recommended for playwright-bdd.`, `Remove this option from defineBddConfig() and`, `Playwright's built-in loader will be used to compile TypeScript step definitions.`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
handleParseErrors() {
|
|
186
|
-
const {
|
|
187
|
-
parseErrors
|
|
188
|
-
} = this.featuresLoader;
|
|
189
|
-
if (parseErrors.length) {
|
|
190
|
-
const message = parseErrors.map(parseError => {
|
|
191
|
-
return `Parse error in "${parseError.source.uri}" ${parseError.message}`;
|
|
192
|
-
}).join('\n');
|
|
193
|
-
(0, _exit.exit)(message);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.TestFilesGenerator = TestFilesGenerator;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SpecialTags = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Special tags.
|
|
9
|
-
*/
|
|
10
|
-
class SpecialTags {
|
|
11
|
-
ownTags;
|
|
12
|
-
allTags;
|
|
13
|
-
only;
|
|
14
|
-
skip;
|
|
15
|
-
fixme;
|
|
16
|
-
fail;
|
|
17
|
-
retries;
|
|
18
|
-
timeout;
|
|
19
|
-
mode;
|
|
20
|
-
constructor(ownTags, allTags) {
|
|
21
|
-
this.ownTags = ownTags;
|
|
22
|
-
this.allTags = allTags;
|
|
23
|
-
this.extractFlags();
|
|
24
|
-
this.extractRetries();
|
|
25
|
-
this.extractTimeout();
|
|
26
|
-
this.extractMode();
|
|
27
|
-
}
|
|
28
|
-
extractFlags() {
|
|
29
|
-
// order is important
|
|
30
|
-
const flags = ['only', 'fail', 'skip', 'fixme'];
|
|
31
|
-
for (const flag of flags) {
|
|
32
|
-
if (this.ownTags.includes(`@${flag}`)) {
|
|
33
|
-
this[flag] = true;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// describe.fail is not supported, so mark all nested tests as failed instead
|
|
38
|
-
if (this.allTags.includes(`@fail`)) {
|
|
39
|
-
this.fail = true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
extractRetries() {
|
|
43
|
-
for (const tag of this.ownTags.reverse()) {
|
|
44
|
-
const match = tag.match(/@retries:(\d+)/i);
|
|
45
|
-
if (match) {
|
|
46
|
-
this.retries = Number(match[1]);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
extractTimeout() {
|
|
52
|
-
for (const tag of this.ownTags.reverse()) {
|
|
53
|
-
const match = tag.match(/@timeout:(\d+)/i);
|
|
54
|
-
if (match) {
|
|
55
|
-
this.timeout = Number(match[1]);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
extractMode() {
|
|
61
|
-
for (const tag of this.ownTags.reverse()) {
|
|
62
|
-
const match = tag.match(/@mode:(default|parallel|serial)/i);
|
|
63
|
-
if (match) {
|
|
64
|
-
this.mode = match[1];
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.SpecialTags = SpecialTags;
|