@zohodesk/testinglibrary 0.1.8-stb-bdd-v26 → 0.1.9
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 +21 -18
- package/.eslintrc.js +31 -31
- package/.prettierrc +5 -5
- package/README.md +17 -17
- package/bin/cli.js +2 -2
- package/build/bdd-framework/cli/commands/env.js +42 -0
- package/build/bdd-framework/cli/commands/export.js +47 -0
- package/build/bdd-framework/cli/commands/test.js +64 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +19 -0
- package/build/bdd-framework/cli/worker.js +13 -0
- package/build/bdd-framework/config/configDir.js +35 -0
- package/build/bdd-framework/config/enrichReporterData.js +23 -0
- package/build/bdd-framework/config/env.js +50 -0
- package/build/bdd-framework/config/index.js +94 -0
- package/build/bdd-framework/config/lang.js +14 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
- package/build/bdd-framework/cucumber/createTestStep.js +43 -0
- package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +126 -0
- package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +72 -0
- package/build/bdd-framework/cucumber/formatter/PickleParser.js +25 -0
- package/build/bdd-framework/cucumber/formatter/durationHelpers.js +13 -0
- package/build/bdd-framework/cucumber/formatter/getColorFns.js +57 -0
- package/build/bdd-framework/cucumber/formatter/index.js +16 -0
- package/build/bdd-framework/cucumber/formatter/locationHelpers.js +16 -0
- package/build/bdd-framework/cucumber/loadConfig.js +17 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +70 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
- package/build/bdd-framework/cucumber/loadSteps.js +47 -0
- package/build/bdd-framework/cucumber/resolveFeaturePaths.js +62 -0
- package/build/bdd-framework/cucumber/stepArguments.js +21 -0
- package/build/bdd-framework/cucumber/types.js +5 -0
- package/build/bdd-framework/cucumber/valueChecker.js +23 -0
- package/build/bdd-framework/decorators.js +18 -0
- package/build/bdd-framework/gen/fixtures.js +48 -0
- package/build/bdd-framework/gen/formatter.js +123 -0
- package/build/bdd-framework/gen/i18n.js +39 -0
- package/build/bdd-framework/gen/index.js +185 -0
- package/build/bdd-framework/gen/testFile.js +465 -0
- package/build/bdd-framework/gen/testMeta.js +60 -0
- package/build/bdd-framework/gen/testNode.js +60 -0
- package/build/bdd-framework/gen/testPoms.js +133 -0
- package/build/bdd-framework/hooks/scenario.js +130 -0
- package/build/bdd-framework/hooks/worker.js +89 -0
- package/build/bdd-framework/index.js +52 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +93 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +79 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/loadUtils.js +33 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +61 -0
- package/build/bdd-framework/playwright/transform.js +88 -0
- package/build/bdd-framework/playwright/types.js +5 -0
- package/build/bdd-framework/playwright/utils.js +34 -0
- package/build/bdd-framework/reporter/cucumber/base.js +57 -0
- package/build/bdd-framework/reporter/cucumber/custom.js +73 -0
- package/build/bdd-framework/reporter/cucumber/helper.js +12 -0
- package/build/bdd-framework/reporter/cucumber/html.js +35 -0
- package/build/bdd-framework/reporter/cucumber/index.js +74 -0
- package/build/bdd-framework/reporter/cucumber/json.js +312 -0
- package/build/bdd-framework/reporter/cucumber/junit.js +205 -0
- package/build/bdd-framework/reporter/cucumber/message.js +20 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +64 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +196 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +43 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +52 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +105 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +70 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +45 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +27 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +38 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +128 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +126 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +102 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +50 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +88 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +30 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwUtils.js +51 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +35 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +5 -0
- package/build/bdd-framework/run/StepInvoker.js +68 -0
- package/build/bdd-framework/run/bddDataAttachment.js +46 -0
- package/build/bdd-framework/run/bddFixtures.js +191 -0
- package/build/bdd-framework/run/bddWorld.js +79 -0
- package/build/bdd-framework/run/bddWorldInternal.js +15 -0
- package/build/bdd-framework/snippets/index.js +132 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +43 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +66 -0
- package/build/bdd-framework/stepDefinitions/decorators/class.js +68 -0
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +99 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
- package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
- package/build/bdd-framework/utils/AutofillMap.js +20 -0
- package/build/bdd-framework/utils/exit.js +62 -0
- package/build/bdd-framework/utils/index.js +93 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +30 -0
- package/build/bdd-framework/utils/stripAnsiEscapes.js +20 -0
- package/build/core/playwright/builtInFixtures/addTags.js +1 -1
- package/build/core/playwright/builtInFixtures/context.js +18 -1
- package/build/core/playwright/builtInFixtures/i18N.js +33 -0
- package/build/core/playwright/builtInFixtures/index.js +19 -7
- package/build/core/playwright/builtInFixtures/page.js +69 -39
- package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
- package/build/core/playwright/clear-caches.js +19 -8
- package/build/core/playwright/codegen.js +4 -4
- package/build/core/playwright/constants/browserTypes.js +12 -0
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/env-initializer.js +10 -6
- package/build/core/playwright/helpers/auth/accountLogin.js +18 -0
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +47 -0
- package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
- package/build/core/playwright/helpers/auth/getUsers.js +72 -0
- package/build/core/playwright/helpers/auth/index.js +58 -0
- package/build/core/playwright/helpers/auth/loginSteps.js +36 -0
- package/build/core/playwright/helpers/configFileNameProvider.js +17 -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 +11 -0
- package/build/core/playwright/index.js +69 -15
- package/build/core/playwright/readConfigFile.js +50 -39
- package/build/core/playwright/report-generator.js +7 -7
- package/build/core/playwright/setup/config-creator.js +15 -16
- package/build/core/playwright/setup/config-utils.js +60 -26
- package/build/core/playwright/setup/custom-reporter.js +3 -2
- package/build/core/playwright/tag-processor.js +12 -23
- package/build/core/playwright/test-runner.js +49 -63
- package/build/core/playwright/types.js +43 -0
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +16 -2
- package/build/index.d.ts +79 -12
- package/build/index.js +51 -9
- package/build/lib/cli.js +12 -3
- package/build/lib/post-install.js +18 -10
- package/build/parser/sample.feature +34 -34
- package/build/parser/sample.spec.js +18 -18
- package/build/setup-folder-structure/helper.js +3 -0
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +24 -24
- package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
- package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
- package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
- package/build/setup-folder-structure/samples/git-ignore.sample.js +36 -36
- package/build/setup-folder-structure/samples/uat-config-sample.js +44 -44
- package/build/utils/cliArgsToObject.js +30 -26
- package/build/utils/fileUtils.js +4 -19
- package/build/utils/getFilePath.js +1 -2
- package/build/utils/rootPath.js +16 -9
- package/changelog.md +144 -131
- package/jest.config.js +63 -63
- package/npm-shrinkwrap.json +6475 -5994
- package/package.json +57 -56
- package/playwright.config.js +112 -112
- package/build/bdd-poc/config/pathConfig.js +0 -22
- package/build/bdd-poc/core-runner/exportMethods.js +0 -22
- package/build/bdd-poc/core-runner/main.js +0 -15
- package/build/bdd-poc/core-runner/stepDefinitions.js +0 -157
- package/build/bdd-poc/core-runner/stepRunner.js +0 -25
- package/build/bdd-poc/errors/throwError.js +0 -23
- package/build/bdd-poc/index.js +0 -26
- package/build/bdd-poc/test/cucumber/featureFileParer.js +0 -84
- package/build/bdd-poc/test/cucumber/parserCucumber.js +0 -15
- package/build/bdd-poc/test/stepGenerate/extractTestInputs.js +0 -65
- package/build/bdd-poc/test/stepGenerate/parserSteps.js +0 -81
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +0 -40
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +0 -61
- package/build/bdd-poc/test/tagsHandle.js +0 -70
- package/build/bdd-poc/test/testData.js +0 -125
- package/build/bdd-poc/test/testStructure.js +0 -92
- package/build/bdd-poc/utils/stringManipulation.js +0 -26
|
@@ -0,0 +1,99 @@
|
|
|
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)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
43
|
+
return Object.values(propertyDescriptors).forEach(descriptor => {
|
|
44
|
+
const stepConfig = getStepConfigFromMethod(descriptor);
|
|
45
|
+
if (!stepConfig) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
stepConfig.pomNode = pomNode;
|
|
49
|
+
decoratedSteps.add(stepConfig);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
54
|
+
*/
|
|
55
|
+
function appendDecoratorSteps(supportCodeLibrary) {
|
|
56
|
+
decoratedSteps.forEach(stepConfig => {
|
|
57
|
+
const {
|
|
58
|
+
keyword,
|
|
59
|
+
pattern,
|
|
60
|
+
fn
|
|
61
|
+
} = stepConfig;
|
|
62
|
+
stepConfig.fn = (fixturesArg, ...args) => {
|
|
63
|
+
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
64
|
+
return fn.call(fixture, ...args);
|
|
65
|
+
};
|
|
66
|
+
const code = (0, _defineStep.buildCucumberStepCode)(stepConfig);
|
|
67
|
+
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
68
|
+
keyword,
|
|
69
|
+
pattern,
|
|
70
|
+
code,
|
|
71
|
+
line: 0,
|
|
72
|
+
// not used in playwright-bdd
|
|
73
|
+
options: {},
|
|
74
|
+
// not used in playwright-bdd
|
|
75
|
+
uri: '' // not used in playwright-bdd
|
|
76
|
+
}, supportCodeLibrary);
|
|
77
|
+
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
78
|
+
});
|
|
79
|
+
decoratedSteps.clear();
|
|
80
|
+
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
81
|
+
}
|
|
82
|
+
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
83
|
+
// there should be exatcly one suitable fixture in fixturesArg
|
|
84
|
+
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
85
|
+
if (fixtureNames.length === 0) {
|
|
86
|
+
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
87
|
+
}
|
|
88
|
+
if (fixtureNames.length > 1) {
|
|
89
|
+
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
90
|
+
}
|
|
91
|
+
return fixturesArg[fixtureNames[0]];
|
|
92
|
+
}
|
|
93
|
+
function saveStepConfigToMethod(method, stepConfig) {
|
|
94
|
+
method[decoratedStepSymbol] = stepConfig;
|
|
95
|
+
}
|
|
96
|
+
function getStepConfigFromMethod(descriptor) {
|
|
97
|
+
// filter out getters / setters
|
|
98
|
+
return typeof descriptor.value === 'function' ? descriptor.value[decoratedStepSymbol] : undefined;
|
|
99
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 _exit = require("../utils/exit");
|
|
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, _exit.exit)(`Option "importTestFrom" should point to a 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
|
+
// build the first argument (fixtures) for step fn
|
|
38
|
+
const fixturesArg = Object.assign({}, this.$internal.currentStepFixtures, {
|
|
39
|
+
$testInfo: this.testInfo,
|
|
40
|
+
$test: this.test,
|
|
41
|
+
$tags: this.tags
|
|
42
|
+
});
|
|
43
|
+
return stepConfig.fn.call(this, fixturesArg, ...args);
|
|
44
|
+
};
|
|
45
|
+
code.stepConfig = stepConfig;
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
function getStepCode(stepDefinition) {
|
|
49
|
+
return stepDefinition.code;
|
|
50
|
+
}
|
|
51
|
+
function getCucumberDefineStepFn(keyword) {
|
|
52
|
+
switch (keyword) {
|
|
53
|
+
case 'Given':
|
|
54
|
+
return _cucumber.Given;
|
|
55
|
+
case 'When':
|
|
56
|
+
return _cucumber.When;
|
|
57
|
+
case 'Then':
|
|
58
|
+
return _cucumber.Then;
|
|
59
|
+
default:
|
|
60
|
+
return _cucumber.defineStep;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AutofillMap = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Extended Map that automatically creates item if it does not exist.
|
|
9
|
+
*/
|
|
10
|
+
class AutofillMap extends Map {
|
|
11
|
+
getOrCreate(key, createFn) {
|
|
12
|
+
let item = this.get(key);
|
|
13
|
+
if (!item) {
|
|
14
|
+
item = createFn(key);
|
|
15
|
+
this.set(key, item);
|
|
16
|
+
}
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.AutofillMap = AutofillMap;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.exit = exit;
|
|
7
|
+
exports.withExitHandler = withExitHandler;
|
|
8
|
+
var _worker_threads = require("worker_threads");
|
|
9
|
+
/**
|
|
10
|
+
* Exit utils.
|
|
11
|
+
*
|
|
12
|
+
* When calling process.exit() in worker thread used for test-file generation,
|
|
13
|
+
* logs are not flushed (https://github.com/vitalets/playwright-bdd/issues/59).
|
|
14
|
+
* That's why instead of process.exit we throw ExitError
|
|
15
|
+
* that just sets process.exitCode = 1 and allow program to exit normally.
|
|
16
|
+
* This esnured by wrapping code with withExitHandler().
|
|
17
|
+
*
|
|
18
|
+
* On the other hand, when running in the main thread, especially inside Playwright,
|
|
19
|
+
* thrown error is captured by Playwright and show with additional messages (e.g. no tests found).
|
|
20
|
+
* That's why in main thread we to call process.exit() to show only needed error.
|
|
21
|
+
*
|
|
22
|
+
* Relevant discussions:
|
|
23
|
+
* - https://github.com/nodejs/node/issues/6379
|
|
24
|
+
* - https://github.com/nodejs/node-v0.x-archive/issues/3737
|
|
25
|
+
* - https://github.com/cucumber/cucumber-js/pull/123
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
class ExitError extends Error {
|
|
29
|
+
get stack() {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function withExitHandler(fn) {
|
|
34
|
+
try {
|
|
35
|
+
return await fn();
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (e instanceof ExitError) {
|
|
38
|
+
if (e.message) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.error(e.message);
|
|
41
|
+
}
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
} else {
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function exit(...messages) {
|
|
49
|
+
messages = messages.filter(Boolean);
|
|
50
|
+
if (_worker_threads.isMainThread) {
|
|
51
|
+
// use console.error() here instead of logger.error() to have less stack
|
|
52
|
+
// for flushing messages to stderr.
|
|
53
|
+
|
|
54
|
+
if (messages.length) {
|
|
55
|
+
// eslint-disable-next-line no-console, max-depth
|
|
56
|
+
console.error('Error:', ...messages);
|
|
57
|
+
}
|
|
58
|
+
process.exit(1);
|
|
59
|
+
} else {
|
|
60
|
+
throw new ExitError(messages.join(' '));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.callWithTimeout = callWithTimeout;
|
|
8
|
+
exports.extractTemplateParams = extractTemplateParams;
|
|
9
|
+
exports.getPackageVersion = getPackageVersion;
|
|
10
|
+
exports.getSymbolByName = getSymbolByName;
|
|
11
|
+
exports.omit = omit;
|
|
12
|
+
exports.removeDuplicates = removeDuplicates;
|
|
13
|
+
exports.resolvePackageRoot = resolvePackageRoot;
|
|
14
|
+
exports.stringifyLocation = stringifyLocation;
|
|
15
|
+
exports.template = template;
|
|
16
|
+
exports.toPosixPath = toPosixPath;
|
|
17
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
18
|
+
var _path = _interopRequireDefault(require("path"));
|
|
19
|
+
var _util = require("util");
|
|
20
|
+
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
21
|
+
/**
|
|
22
|
+
* Returns Symbol by name.
|
|
23
|
+
* See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
24
|
+
*/
|
|
25
|
+
function getSymbolByName(target, name) {
|
|
26
|
+
const ownKeys = Reflect.ownKeys(target);
|
|
27
|
+
const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
|
|
28
|
+
if (!symbol) {
|
|
29
|
+
throw new Error(`Symbol "${name}" not found in target. ownKeys: ${ownKeys}`);
|
|
30
|
+
}
|
|
31
|
+
return symbol;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Inserts params into template.
|
|
35
|
+
* Params defined as <param>.
|
|
36
|
+
*/
|
|
37
|
+
function template(t, params = {}) {
|
|
38
|
+
return t.replace(/<(.+?)>/g, (match, key) => {
|
|
39
|
+
return params[key] !== undefined ? String(params[key]) : match;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extracts all template params from string.
|
|
44
|
+
* Params defined as <param>.
|
|
45
|
+
*/
|
|
46
|
+
function extractTemplateParams(t) {
|
|
47
|
+
return [...t.matchAll(/<(.+?)>/g)].map(m => m[1]);
|
|
48
|
+
}
|
|
49
|
+
function removeDuplicates(arr) {
|
|
50
|
+
return [...new Set(arr)];
|
|
51
|
+
}
|
|
52
|
+
function resolvePackageRoot(packageName) {
|
|
53
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
54
|
+
return _path.default.dirname(packageJsonPath);
|
|
55
|
+
}
|
|
56
|
+
function getPackageVersion(packageName) {
|
|
57
|
+
const packageRoot = resolvePackageRoot(packageName);
|
|
58
|
+
const packageJsonPath = _path.default.join(packageRoot, 'package.json');
|
|
59
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
60
|
+
return packageJson.version || '';
|
|
61
|
+
}
|
|
62
|
+
async function callWithTimeout(fn, timeout, timeoutMsg) {
|
|
63
|
+
if (!timeout) {
|
|
64
|
+
return fn();
|
|
65
|
+
}
|
|
66
|
+
const ac = new AbortController();
|
|
67
|
+
return Promise.race([fn(), setTimeoutPromise(timeout, null, {
|
|
68
|
+
ref: false,
|
|
69
|
+
signal: ac.signal
|
|
70
|
+
}).then(() => {
|
|
71
|
+
throw new Error(timeoutMsg || `Function timeout (${timeout} ms)`);
|
|
72
|
+
})]).finally(() => ac.abort());
|
|
73
|
+
}
|
|
74
|
+
function stringifyLocation({
|
|
75
|
+
line,
|
|
76
|
+
column
|
|
77
|
+
}) {
|
|
78
|
+
return `${line}:${column}`;
|
|
79
|
+
}
|
|
80
|
+
function omit(obj, key) {
|
|
81
|
+
const res = {
|
|
82
|
+
...obj
|
|
83
|
+
};
|
|
84
|
+
delete res[key];
|
|
85
|
+
return res;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns path with "/" separator on all platforms.
|
|
89
|
+
* See: https://stackoverflow.com/questions/53799385/how-can-i-convert-a-windows-path-to-posix-path-using-node-path
|
|
90
|
+
*/
|
|
91
|
+
function toPosixPath(somePath) {
|
|
92
|
+
return somePath.split(_path.default.sep).join(_path.default.posix.sep);
|
|
93
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.jsStringWrap = jsStringWrap;
|
|
7
|
+
/**
|
|
8
|
+
* Adopted version of https://github.com/joliss/js-string-escape
|
|
9
|
+
* - added support of backticks
|
|
10
|
+
* - added 'quotes' option to indicate which quotes to escape
|
|
11
|
+
* - wrap result string with provided quotes
|
|
12
|
+
*
|
|
13
|
+
* Considered alternative is https://github.com/mathiasbynens/jsesc,
|
|
14
|
+
* but it provides additional functionality and much slower
|
|
15
|
+
* See: https://github.com/mathiasbynens/jsesc/issues/16
|
|
16
|
+
*/
|
|
17
|
+
function jsStringWrap(str, {
|
|
18
|
+
quotes = 'single'
|
|
19
|
+
} = {}) {
|
|
20
|
+
const wrapQuote = quotes === 'single' ? "'" : quotes === 'double' ? '"' : '`';
|
|
21
|
+
// eslint-disable-next-line complexity
|
|
22
|
+
const escapedStr = ('' + str).replace(/["'`\\\n\r\u2028\u2029]/g, character => {
|
|
23
|
+
// Escape all characters not included in SingleStringCharacters and
|
|
24
|
+
// DoubleStringCharacters on
|
|
25
|
+
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
26
|
+
switch (character) {
|
|
27
|
+
case wrapQuote:
|
|
28
|
+
case '\\':
|
|
29
|
+
return '\\' + character;
|
|
30
|
+
// Four possible LineTerminator characters need to be escaped:
|
|
31
|
+
case '\n':
|
|
32
|
+
return '\\n';
|
|
33
|
+
case '\r':
|
|
34
|
+
return '\\r';
|
|
35
|
+
case '\u2028':
|
|
36
|
+
return '\\u2028';
|
|
37
|
+
case '\u2029':
|
|
38
|
+
return '\\u2029';
|
|
39
|
+
default:
|
|
40
|
+
return character;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return `${wrapQuote}${escapedStr}${wrapQuote}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logger = exports.Logger = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Simple logger
|
|
9
|
+
*/
|
|
10
|
+
class Logger {
|
|
11
|
+
options;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
log(...args) {
|
|
16
|
+
if (this.options.verbose) {
|
|
17
|
+
console.log(...args);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
warn(...args) {
|
|
21
|
+
// using log() to output warnings to stdout, not stderr
|
|
22
|
+
console.log(...args);
|
|
23
|
+
}
|
|
24
|
+
error(...args) {
|
|
25
|
+
console.error(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// default logger
|
|
29
|
+
exports.Logger = Logger;
|
|
30
|
+
const logger = exports.logger = new Logger();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stripAnsiEscapes = stripAnsiEscapes;
|
|
7
|
+
/**
|
|
8
|
+
* Copied from Playwright.
|
|
9
|
+
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/reporters/base.ts#L529
|
|
10
|
+
*
|
|
11
|
+
* Note: there is also 'strip-ansi' package, but is't ESM only.
|
|
12
|
+
* Adding it is tricky now.
|
|
13
|
+
* See: https://www.npmjs.com/package/strip-ansi
|
|
14
|
+
*/
|
|
15
|
+
const ansiRegex = new RegExp(
|
|
16
|
+
// eslint-disable-next-line max-len, no-control-regex
|
|
17
|
+
'([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))', 'g');
|
|
18
|
+
function stripAnsiEscapes(str) {
|
|
19
|
+
return str.replace(ansiRegex, '');
|
|
20
|
+
}
|
|
@@ -4,12 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _readConfigFile = require("../readConfigFile");
|
|
8
|
+
const {
|
|
9
|
+
testSetup
|
|
10
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
11
|
+
async function performDefaultContextSteps({
|
|
12
|
+
context
|
|
13
|
+
}) {
|
|
14
|
+
if (testSetup.context && typeof testSetup.context === 'function') {
|
|
15
|
+
await testSetup.context({
|
|
16
|
+
context
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
7
20
|
var _default = exports.default = {
|
|
8
21
|
context: async ({
|
|
9
22
|
context
|
|
10
23
|
}, use) => {
|
|
24
|
+
await context.addInitScript(() =>
|
|
11
25
|
// eslint-disable-next-line no-undef
|
|
12
|
-
|
|
26
|
+
window.localStorage.setItem('isDnBannerHide', true));
|
|
27
|
+
await performDefaultContextSteps({
|
|
28
|
+
context
|
|
29
|
+
});
|
|
13
30
|
await use(context);
|
|
14
31
|
}
|
|
15
32
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/* eslint-disable no-undef */
|
|
8
|
+
/* eslint-disable no-param-reassign */
|
|
9
|
+
|
|
10
|
+
// Note: We are duplicating below method from @zohodesk/i18n. We are not importing it as react package not yet availble in test environment.
|
|
11
|
+
function replaceI18NValuesWithRegex(i18nStr, values) {
|
|
12
|
+
if (typeof values !== 'undefined') {
|
|
13
|
+
if (Array.isArray(values)) {
|
|
14
|
+
for (let i = 0; i < values.length; i++) {
|
|
15
|
+
i18nStr = i18nStr.replace(new RegExp(`\\{${i}\\}`, 'g'), values[i]);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
i18nStr = i18nStr.replace(new RegExp('\\{0\\}', 'g'), values);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return i18nStr;
|
|
22
|
+
}
|
|
23
|
+
var _default = exports.default = {
|
|
24
|
+
i18N: async ({
|
|
25
|
+
page
|
|
26
|
+
}, use) => {
|
|
27
|
+
await use(async (key, values) => {
|
|
28
|
+
const i18nValue = await page.evaluate(i18nKey => window.i18n[i18nKey], key);
|
|
29
|
+
const i18nStr = replaceI18NValuesWithRegex(i18nValue, values);
|
|
30
|
+
return i18nStr;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -8,21 +8,33 @@ exports.default = void 0;
|
|
|
8
8
|
var _page = _interopRequireDefault(require("./page"));
|
|
9
9
|
var _context = _interopRequireDefault(require("./context"));
|
|
10
10
|
var _cacheLayer = _interopRequireDefault(require("./cacheLayer"));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
var _addTags = _interopRequireDefault(require("./addTags"));
|
|
12
|
+
var _i18N = _interopRequireDefault(require("./i18N"));
|
|
13
|
+
var _unauthenticatedPage = _interopRequireDefault(require("./unauthenticatedPage"));
|
|
14
|
+
function extractTagsFromTitle(text) {
|
|
15
|
+
return text.match(/@\w+/g) || [];
|
|
16
|
+
}
|
|
16
17
|
function getBuiltInFixtures(bddMode) {
|
|
17
18
|
let builtInFixtures = {
|
|
18
19
|
..._page.default,
|
|
19
20
|
..._context.default,
|
|
20
|
-
..._cacheLayer.default
|
|
21
|
+
..._cacheLayer.default,
|
|
22
|
+
..._i18N.default,
|
|
23
|
+
..._unauthenticatedPage.default
|
|
21
24
|
};
|
|
22
25
|
if (bddMode) {
|
|
23
26
|
builtInFixtures = {
|
|
24
27
|
...builtInFixtures,
|
|
25
|
-
...
|
|
28
|
+
..._addTags.default
|
|
29
|
+
};
|
|
30
|
+
} else {
|
|
31
|
+
builtInFixtures = {
|
|
32
|
+
...builtInFixtures,
|
|
33
|
+
$tags: async ({}, use, testInfo) => {
|
|
34
|
+
// Extract only the elements after the "@" symbol as tags
|
|
35
|
+
const tags = testInfo.title ? extractTagsFromTitle(testInfo.title) : [];
|
|
36
|
+
await use(tags);
|
|
37
|
+
}
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
40
|
return builtInFixtures;
|