@zohodesk/testinglibrary 0.1.9 → 0.1.12-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 +4 -2
- package/.claude/settings.local.json +14 -0
- package/.gitlab-ci.yml +206 -0
- package/README.md +264 -1
- package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
- package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +21 -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 +85 -0
- package/build/core/dataGenerator/DataGenerator.js +161 -0
- package/build/core/dataGenerator/DataGeneratorError.js +60 -0
- package/build/core/dataGenerator/DataGeneratorHelper.js +121 -0
- package/build/core/dataGenerator/authenticator/Authenticator.js +37 -0
- package/build/core/dataGenerator/authenticator/CookieAuthenticator.js +48 -0
- package/build/core/dataGenerator/authenticator/JWTauthenticator.js +59 -0
- package/build/core/dataGenerator/authenticator/OAuthAuthenticator.js +26 -0
- package/build/core/dataGenerator/authenticator/OrgOAuthAuthenticator.js +26 -0
- package/build/core/dataGenerator/authenticator/cookieAuthConfig.js +11 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +2 -7
- package/build/core/jest/setup/index.js +1 -7
- package/build/core/playwright/builtInFixtures/actorContext.js +78 -0
- package/build/core/playwright/builtInFixtures/caseTimeout.js +20 -0
- package/build/core/playwright/builtInFixtures/context.js +34 -16
- package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
- package/build/core/playwright/builtInFixtures/i18N.js +8 -0
- package/build/core/playwright/builtInFixtures/index.js +7 -1
- package/build/core/playwright/builtInFixtures/page.js +22 -66
- package/build/core/playwright/clear-caches.js +17 -5
- package/build/core/playwright/codegen.js +4 -21
- package/build/core/playwright/configuration/Configuration.js +25 -0
- package/build/core/playwright/configuration/ConfigurationHelper.js +45 -0
- package/build/core/playwright/configuration/UserArgs.js +12 -0
- package/build/core/playwright/constants/configConstants.js +17 -0
- package/build/core/playwright/constants/failureTagConstants.js +17 -0
- package/build/core/playwright/constants/fileMutexConfig.js +9 -0
- package/build/core/playwright/constants/reporterConstants.js +20 -0
- package/build/core/playwright/constants/retryConstants.js +8 -0
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/env-initializer.js +28 -9
- 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 +4 -1
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +27 -23
- package/build/core/playwright/helpers/auth/getUsers.js +92 -45
- package/build/core/playwright/helpers/auth/index.js +30 -5
- package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +62 -0
- package/build/core/playwright/helpers/auth/loginSteps.js +40 -22
- package/build/core/playwright/helpers/browserTimeoutFactor.js +16 -0
- package/build/core/playwright/helpers/caseTimeoutResolver.js +37 -0
- package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
- package/build/core/playwright/helpers/configFileNameProvider.js +26 -5
- package/build/core/playwright/helpers/configPathResolver.js +38 -0
- package/build/core/playwright/helpers/contextFailureHandler.js +81 -0
- package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
- package/build/core/playwright/helpers/failureTagClassifier.js +197 -0
- package/build/core/playwright/helpers/fileMutex.js +71 -0
- package/build/core/playwright/helpers/logCollector.js +147 -0
- package/build/core/playwright/helpers/parseUserArgs.js +2 -3
- package/build/core/playwright/helpers/runtimeLogAnnotator.js +140 -0
- package/build/core/playwright/helpers/runtimeLogPath.js +61 -0
- package/build/core/playwright/helpers/runtimeLogReader.js +54 -0
- package/build/core/playwright/helpers/thirdPartyLib.js +13 -0
- package/build/core/playwright/index.js +8 -76
- package/build/core/playwright/patterns/casePatterns.js +9 -0
- package/build/core/playwright/patterns/codePatterns.js +9 -0
- package/build/core/playwright/patterns/environmentPatterns.js +15 -0
- package/build/core/playwright/patterns/index.js +33 -0
- package/build/core/playwright/patterns/logCollectorIgnorePatterns.js +15 -0
- package/build/core/playwright/patterns/toolPatterns.js +26 -0
- package/build/core/playwright/readConfigFile.js +49 -16
- package/build/core/playwright/reporter/PlaywrightReporter.js +58 -0
- package/build/core/playwright/reporter/Reporter.js +65 -0
- package/build/core/playwright/reporter/ShardReporter.js +58 -0
- package/build/core/playwright/reporter/UnitReporter.js +27 -0
- package/build/core/playwright/reporter/helpers/mergeAbortedTests.js +78 -0
- 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 +93 -0
- package/build/core/playwright/setup/Project.js +35 -0
- package/build/core/playwright/setup/ProjectConfiguration.js +66 -0
- package/build/core/playwright/setup/config-creator.js +58 -40
- package/build/core/playwright/setup/config-utils.js +68 -37
- package/build/core/playwright/setup/custom-reporter.js +137 -14
- package/build/core/playwright/setup/merge-config.js +32 -0
- package/build/core/playwright/setup/qc-custom-reporter.js +342 -0
- package/build/core/playwright/spawnInheritChild.js +71 -0
- package/build/core/playwright/tagProcessor.js +69 -0
- package/build/core/playwright/test-runner.js +44 -98
- package/build/core/playwright/types.js +4 -1
- 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 +17 -19
- package/build/index.js +28 -6
- package/build/lib/cli.js +42 -7
- package/build/setup-folder-structure/helper.js +2 -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/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 -2
- package/build/setup-folder-structure/setupProject.js +23 -5
- package/build/test/core/dataGenerator/__tests__/DataGenerator.test.js +311 -0
- package/build/test/core/dataGenerator/__tests__/DataGeneratorHelper.test.js +204 -0
- package/build/test/core/dataGenerator/__tests__/DataGeneratorResolution.test.js +126 -0
- package/build/test/core/dataGenerator/authenticator/__tests__/Authenticator.test.js +88 -0
- package/build/test/core/dataGenerator/authenticator/__tests__/JWTauthenticator.test.js +136 -0
- package/build/test/core/dataGenerator/authenticator/__tests__/OAuthAuthenticator.test.js +39 -0
- package/build/test/core/dataGenerator/authenticator/__tests__/OrgOAuthAuthenticator.test.js +39 -0
- package/build/test/core/playwright/__tests__/spawnInheritChild.test.js +148 -0
- package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
- package/build/test/core/playwright/__tests__/validateFeature.test.js +72 -0
- package/build/test/core/playwright/buildInFixtures/__tests__/caseTimeout.test.js +96 -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 +75 -0
- package/build/test/core/playwright/helpers/__tests__/configPathResolver.test.js +55 -0
- package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
- package/build/test/core/playwright/helpers/__tests__/failureTagClassifier.test.js +604 -0
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
- package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +83 -0
- package/build/test/core/playwright/helpers/__tests__/logCollector.test.js +163 -0
- package/build/test/core/playwright/helpers/__tests__/runtimeLogReader.test.js +112 -0
- package/build/test/core/playwright/helpers/auth/__tests__/checkAuthCookies.test.js +92 -0
- package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +19 -0
- package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +30 -0
- package/build/utils/cliArgsToObject.js +3 -0
- package/build/utils/commonUtils.js +20 -0
- package/build/utils/fileUtils.js +43 -1
- package/build/utils/logger.js +1 -30
- package/changelog.md +23 -0
- package/docs/CODE-REVIEW-AGENT.md +399 -0
- package/docs/code-review-instructions.md +157 -0
- package/jest.config.js +29 -11
- package/npm-shrinkwrap.json +14994 -4793
- package/package.json +39 -28
- package/playwright.config.js +13 -57
- package/unit_reports/unit-report.html +277 -0
- package/build/bdd-framework/cli/commands/env.js +0 -42
- package/build/bdd-framework/cli/commands/export.js +0 -47
- 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 -123
- package/build/bdd-framework/gen/i18n.js +0 -39
- package/build/bdd-framework/gen/index.js +0 -185
- package/build/bdd-framework/gen/testFile.js +0 -465
- package/build/bdd-framework/gen/testMeta.js +0 -60
- package/build/bdd-framework/gen/testNode.js +0 -60
- 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 -61
- package/build/bdd-framework/playwright/transform.js +0 -88
- package/build/bdd-framework/playwright/types.js +0 -5
- package/build/bdd-framework/playwright/utils.js +0 -34
- package/build/bdd-framework/reporter/cucumber/base.js +0 -57
- 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 -35
- 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 -64
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -196
- 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 -126
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -102
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -50
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -88
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwUtils.js +0 -51
- 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 -68
- package/build/bdd-framework/run/bddDataAttachment.js +0 -46
- package/build/bdd-framework/run/bddFixtures.js +0 -191
- package/build/bdd-framework/run/bddWorld.js +0 -79
- package/build/bdd-framework/run/bddWorldInternal.js +0 -15
- 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/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/core/playwright/report-generator.js +0 -42
- package/build/core/playwright/tag-processor.js +0 -68
- package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
- package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TestMetaBuilder = void 0;
|
|
7
|
-
exports.getTestMeta = getTestMeta;
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
/**
|
|
10
|
-
* Class to build and print testMeta object containing meta info about each test.
|
|
11
|
-
* Tests are identified by special key constructed from title path.
|
|
12
|
-
*
|
|
13
|
-
* Example:
|
|
14
|
-
* const testMeta = {
|
|
15
|
-
* "Simple scenario": { pickleLocation: "3:10", tags: ["@foo"] },
|
|
16
|
-
* "Scenario with examples|Example #1": { pickleLocation: "8:26", tags: [] },
|
|
17
|
-
* "Rule 1|Scenario with examples|Example #1": { pickleLocation: "9:42", tags: [] },
|
|
18
|
-
* };
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const TEST_KEY_SEPARATOR = '|';
|
|
22
|
-
class TestMetaBuilder {
|
|
23
|
-
tests = [];
|
|
24
|
-
get testCount() {
|
|
25
|
-
return this.tests.length;
|
|
26
|
-
}
|
|
27
|
-
registerTest(node, pickle) {
|
|
28
|
-
const testMeta = {
|
|
29
|
-
pickleLocation: (0, _utils.stringifyLocation)(pickle.location),
|
|
30
|
-
tags: node.tags.length ? node.tags : undefined
|
|
31
|
-
};
|
|
32
|
-
this.tests.push({
|
|
33
|
-
node,
|
|
34
|
-
testMeta
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getObjectLines() {
|
|
38
|
-
// build object line by line to have each test on a separate line,
|
|
39
|
-
// but value should be in one line.
|
|
40
|
-
return this.tests.map(test => {
|
|
41
|
-
const testKey = this.getTestKey(test.node);
|
|
42
|
-
return `${JSON.stringify(testKey)}: ${JSON.stringify(test.testMeta)},`;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
getTestKey(node) {
|
|
46
|
-
// .slice(1) -> b/c we remove top describe title (it's same for all tests)
|
|
47
|
-
return node.titlePath.slice(1).join(TEST_KEY_SEPARATOR);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.TestMetaBuilder = TestMetaBuilder;
|
|
51
|
-
function getTestMeta(testMetaMap, testInfo) {
|
|
52
|
-
// .slice(2) -> b/c we remove filename and top describe title
|
|
53
|
-
const key = testInfo.titlePath.slice(2).join(TEST_KEY_SEPARATOR);
|
|
54
|
-
const testMeta = testMetaMap[key];
|
|
55
|
-
if (!testMeta) {
|
|
56
|
-
// throw new Error(`Can't find testMeta for key "${key}"`);
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
return testMeta;
|
|
60
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TestNode = void 0;
|
|
7
|
-
var _utils = require("../utils");
|
|
8
|
-
/**
|
|
9
|
-
* Universal TestNode class representing test or suite in a test file.
|
|
10
|
-
* Holds parent-child links.
|
|
11
|
-
* Allows to inherit tags and titles path.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
|
|
15
|
-
class TestNode {
|
|
16
|
-
title;
|
|
17
|
-
titlePath;
|
|
18
|
-
ownTags;
|
|
19
|
-
tags;
|
|
20
|
-
flags = {};
|
|
21
|
-
constructor(gherkinNode, parent) {
|
|
22
|
-
this.title = gherkinNode.name;
|
|
23
|
-
this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
|
|
24
|
-
this.ownTags = (0, _utils.removeDuplicates)(getTagNames(gherkinNode.tags));
|
|
25
|
-
this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
|
|
26
|
-
this.initFlags();
|
|
27
|
-
}
|
|
28
|
-
isSkipped() {
|
|
29
|
-
return this.flags.skip || this.flags.fixme;
|
|
30
|
-
}
|
|
31
|
-
initFlags() {
|
|
32
|
-
this.ownTags.forEach(tag => {
|
|
33
|
-
if (isSpecialTag(tag)) {
|
|
34
|
-
this.setFlag(tag);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line complexity
|
|
39
|
-
setFlag(tag) {
|
|
40
|
-
// in case of several special tags, @only takes precendence
|
|
41
|
-
if (tag === '@only') {
|
|
42
|
-
this.flags = {
|
|
43
|
-
only: true
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (tag === '@skip' && !this.flags.only) {
|
|
47
|
-
this.flags.skip = true;
|
|
48
|
-
}
|
|
49
|
-
if (tag === '@fixme' && !this.flags.only) {
|
|
50
|
-
this.flags.fixme = true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.TestNode = TestNode;
|
|
55
|
-
function getTagNames(tags) {
|
|
56
|
-
return tags.map(tag => tag.name);
|
|
57
|
-
}
|
|
58
|
-
function isSpecialTag(tag) {
|
|
59
|
-
return SPECIAL_TAGS.includes(tag);
|
|
60
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TestPoms = void 0;
|
|
7
|
-
exports.buildFixtureTag = buildFixtureTag;
|
|
8
|
-
var _class = require("../stepDefinitions/decorators/class");
|
|
9
|
-
var _exit = require("../utils/exit");
|
|
10
|
-
/**
|
|
11
|
-
* Track PomNodes used in the particular test.
|
|
12
|
-
* To select correct fixture for decorator steps.
|
|
13
|
-
*
|
|
14
|
-
* Idea: try to use the deepest child fixture for parent steps.
|
|
15
|
-
*
|
|
16
|
-
* Example inheritance tree:
|
|
17
|
-
* A
|
|
18
|
-
* / \
|
|
19
|
-
* B C
|
|
20
|
-
* / \ \
|
|
21
|
-
* D E F
|
|
22
|
-
*
|
|
23
|
-
* If test uses steps from classes A and D:
|
|
24
|
-
* -> resolved fixture will be D, even for steps from A.
|
|
25
|
-
*
|
|
26
|
-
* If test uses steps from classes A, D and C:
|
|
27
|
-
* -> error, b/c A has 2 possible fixtures.
|
|
28
|
-
*
|
|
29
|
-
* If test uses steps from classes A and C, but @fixture tag is D:
|
|
30
|
-
* -> error, b/c A has 2 possible fixtures.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
const FIXTURE_TAG_PREFIX = '@fixture:';
|
|
34
|
-
class TestPoms {
|
|
35
|
-
title;
|
|
36
|
-
// map of poms used in test
|
|
37
|
-
usedPoms = new Map();
|
|
38
|
-
constructor(title) {
|
|
39
|
-
this.title = title;
|
|
40
|
-
}
|
|
41
|
-
addByStep(pomNode) {
|
|
42
|
-
this.addUsedPom(pomNode, {
|
|
43
|
-
byTag: false
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
addByFixtureName(fixtureName) {
|
|
47
|
-
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
48
|
-
this.addUsedPom(pomNode, {
|
|
49
|
-
byTag: false
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
addByTag(tag) {
|
|
53
|
-
const fixtureName = extractFixtureName(tag);
|
|
54
|
-
if (fixtureName) {
|
|
55
|
-
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
56
|
-
this.addUsedPom(pomNode, {
|
|
57
|
-
byTag: true
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Resolve all used pomNodes to fixtures.
|
|
63
|
-
* This is needed to handle @fixture: tagged pomNodes
|
|
64
|
-
* that does not have steps in the test, but should be considered.
|
|
65
|
-
*/
|
|
66
|
-
resolveFixtures() {
|
|
67
|
-
this.usedPoms.forEach((_, pomNode) => {
|
|
68
|
-
this.getResolvedFixtures(pomNode);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns fixtures suitable for particular pomNode (actually for step)
|
|
73
|
-
*/
|
|
74
|
-
getResolvedFixtures(pomNode) {
|
|
75
|
-
const usedPom = this.usedPoms.get(pomNode);
|
|
76
|
-
if (usedPom !== null && usedPom !== void 0 && usedPom.fixtures) {
|
|
77
|
-
return usedPom.fixtures;
|
|
78
|
-
}
|
|
79
|
-
// Recursively resolve children fixtures, used in test.
|
|
80
|
-
let childFixtures = [...pomNode.children].map(child => this.getResolvedFixtures(child)).flat();
|
|
81
|
-
if (!usedPom) {
|
|
82
|
-
return childFixtures;
|
|
83
|
-
}
|
|
84
|
-
if (childFixtures.length) {
|
|
85
|
-
this.verifyChildFixtures(pomNode, usedPom, childFixtures);
|
|
86
|
-
usedPom.fixtures = childFixtures;
|
|
87
|
-
} else {
|
|
88
|
-
usedPom.fixtures = [{
|
|
89
|
-
name: pomNode.fixtureName,
|
|
90
|
-
byTag: usedPom.byTag
|
|
91
|
-
}];
|
|
92
|
-
}
|
|
93
|
-
return usedPom.fixtures;
|
|
94
|
-
}
|
|
95
|
-
addUsedPom(pomNode, {
|
|
96
|
-
byTag
|
|
97
|
-
}) {
|
|
98
|
-
if (!pomNode) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const usedPom = this.usedPoms.get(pomNode);
|
|
102
|
-
if (usedPom) {
|
|
103
|
-
if (byTag && !usedPom.byTag) {
|
|
104
|
-
usedPom.byTag = true;
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
this.usedPoms.set(pomNode, {
|
|
108
|
-
byTag
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* For scenarios with @fixture:xxx tags verify that there are no steps from fixtures,
|
|
114
|
-
* deeper than xxx.
|
|
115
|
-
* @fixture:xxx tag provides maximum fixture that can be used in the scenario.
|
|
116
|
-
*/
|
|
117
|
-
verifyChildFixtures(pomNode, usedPom, childFixtures) {
|
|
118
|
-
if (!usedPom.byTag) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const childFixturesBySteps = childFixtures.filter(f => !f.byTag);
|
|
122
|
-
if (childFixturesBySteps.length) {
|
|
123
|
-
(0, _exit.exit)(`Scenario "${this.title}" contains ${childFixturesBySteps.length} step(s)`, `not compatible with required fixture "${pomNode.fixtureName}"`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.TestPoms = TestPoms;
|
|
128
|
-
function extractFixtureName(tag) {
|
|
129
|
-
return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
|
|
130
|
-
}
|
|
131
|
-
function buildFixtureTag(fixtureName) {
|
|
132
|
-
return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
|
|
133
|
-
}
|
|
@@ -1,130 +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.getScenarioHooksFixtures = getScenarioHooksFixtures;
|
|
8
|
-
exports.hasScenarioHooks = hasScenarioHooks;
|
|
9
|
-
exports.runScenarioHooks = runScenarioHooks;
|
|
10
|
-
exports.scenarioHookFactory = scenarioHookFactory;
|
|
11
|
-
var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
|
|
12
|
-
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
13
|
-
var _utils = require("../utils");
|
|
14
|
-
var _getLocationInFile = require("../playwright/getLocationInFile");
|
|
15
|
-
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
16
|
-
/**
|
|
17
|
-
* Scenario level hooks: Before / After.
|
|
18
|
-
*
|
|
19
|
-
* before(async ({ page }) => {})
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const scenarioHooks = [];
|
|
23
|
-
let scenarioHooksFixtures;
|
|
24
|
-
/**
|
|
25
|
-
* Returns Before() / After() functions.
|
|
26
|
-
*/
|
|
27
|
-
function scenarioHookFactory(type) {
|
|
28
|
-
return (...args) => {
|
|
29
|
-
addHook({
|
|
30
|
-
type,
|
|
31
|
-
options: getOptionsFromArgs(args),
|
|
32
|
-
fn: getFnFromArgs(args),
|
|
33
|
-
// offset = 3 b/c this call is 3 steps below the user's code
|
|
34
|
-
location: (0, _getLocationInFile.getLocationByOffset)(3)
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function hasScenarioHooks() {
|
|
39
|
-
return scenarioHooks.length > 0;
|
|
40
|
-
}
|
|
41
|
-
// eslint-disable-next-line complexity, max-statements
|
|
42
|
-
async function runScenarioHooks(type, fixtures) {
|
|
43
|
-
let error;
|
|
44
|
-
for (const hook of scenarioHooks) {
|
|
45
|
-
if (hook.type !== type) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (hook.tagsExpression && !hook.tagsExpression.evaluate(fixtures.$tags)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const hookFn = wrapHookFn(hook, fixtures);
|
|
53
|
-
await (0, _testTypeImpl.runStepWithCustomLocation)(fixtures.$bddWorld.test, hook.options.name || '', hook.location, hookFn);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
if (type === 'before') {
|
|
56
|
-
throw e;
|
|
57
|
-
}
|
|
58
|
-
if (!error) {
|
|
59
|
-
error = e;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (error) {
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function getScenarioHooksFixtures() {
|
|
68
|
-
if (!scenarioHooksFixtures) {
|
|
69
|
-
const fixturesFakeObj = {
|
|
70
|
-
$bddWorld: null,
|
|
71
|
-
$tags: null,
|
|
72
|
-
$testInfo: null
|
|
73
|
-
};
|
|
74
|
-
const set = new Set();
|
|
75
|
-
scenarioHooks.forEach(hook => {
|
|
76
|
-
(0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
|
|
77
|
-
});
|
|
78
|
-
scenarioHooksFixtures = [...set];
|
|
79
|
-
}
|
|
80
|
-
return scenarioHooksFixtures;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Wraps hook fn with timeout and waiting Cucumber attachments to fulfill.
|
|
84
|
-
*/
|
|
85
|
-
function wrapHookFn(hook, fixtures) {
|
|
86
|
-
const {
|
|
87
|
-
timeout
|
|
88
|
-
} = hook.options;
|
|
89
|
-
const {
|
|
90
|
-
$bddWorld
|
|
91
|
-
} = fixtures;
|
|
92
|
-
return async () => {
|
|
93
|
-
await (0, _utils.callWithTimeout)(() => hook.fn.call($bddWorld, fixtures), timeout, getTimeoutMessage(hook));
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function getOptionsFromArgs(args) {
|
|
97
|
-
if (typeof args[0] === 'string') {
|
|
98
|
-
return {
|
|
99
|
-
tags: args[0]
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
if (typeof args[0] === 'object') {
|
|
103
|
-
return args[0];
|
|
104
|
-
}
|
|
105
|
-
return {};
|
|
106
|
-
}
|
|
107
|
-
function getFnFromArgs(args) {
|
|
108
|
-
return args.length === 1 ? args[0] : args[1];
|
|
109
|
-
}
|
|
110
|
-
function setTagsExpression(hook) {
|
|
111
|
-
if (hook.options.tags) {
|
|
112
|
-
hook.tagsExpression = (0, _tagExpressions.default)(hook.options.tags);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function addHook(hook) {
|
|
116
|
-
setTagsExpression(hook);
|
|
117
|
-
if (hook.type === 'before') {
|
|
118
|
-
scenarioHooks.push(hook);
|
|
119
|
-
} else {
|
|
120
|
-
// 'after' hooks run in reverse order
|
|
121
|
-
scenarioHooks.unshift(hook);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function getTimeoutMessage(hook) {
|
|
125
|
-
const {
|
|
126
|
-
timeout,
|
|
127
|
-
name: hookName
|
|
128
|
-
} = hook.options;
|
|
129
|
-
return `${hook.type} hook ${hookName ? `"${hookName}" ` : ''}timeout (${timeout} ms)`;
|
|
130
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getWorkerHooksFixtures = getWorkerHooksFixtures;
|
|
7
|
-
exports.runWorkerHooks = runWorkerHooks;
|
|
8
|
-
exports.workerHookFactory = workerHookFactory;
|
|
9
|
-
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
/**
|
|
12
|
-
* Worker-level hooks: BeforeAll / AfterAll.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const workerHooks = [];
|
|
16
|
-
let workerHooksFixtures;
|
|
17
|
-
/**
|
|
18
|
-
* Returns BeforeAll() / AfterAll() functions.
|
|
19
|
-
*/
|
|
20
|
-
function workerHookFactory(type) {
|
|
21
|
-
return (...args) => {
|
|
22
|
-
addHook({
|
|
23
|
-
type,
|
|
24
|
-
options: getOptionsFromArgs(args),
|
|
25
|
-
fn: getFnFromArgs(args)
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line complexity
|
|
30
|
-
async function runWorkerHooks(type, fixtures) {
|
|
31
|
-
let error;
|
|
32
|
-
for (const hook of workerHooks) {
|
|
33
|
-
if (hook.type !== type) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const {
|
|
37
|
-
timeout
|
|
38
|
-
} = hook.options;
|
|
39
|
-
try {
|
|
40
|
-
await (0, _utils.callWithTimeout)(() => hook.fn(fixtures), timeout, getTimeoutMessage(hook));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
if (type === 'beforeAll') {
|
|
43
|
-
throw e;
|
|
44
|
-
}
|
|
45
|
-
if (!error) {
|
|
46
|
-
error = e;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (error) {
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function getWorkerHooksFixtures() {
|
|
55
|
-
if (!workerHooksFixtures) {
|
|
56
|
-
const fixturesFakeObj = {
|
|
57
|
-
$workerInfo: null
|
|
58
|
-
};
|
|
59
|
-
const set = new Set();
|
|
60
|
-
workerHooks.forEach(hook => {
|
|
61
|
-
(0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
|
|
62
|
-
});
|
|
63
|
-
workerHooksFixtures = [...set];
|
|
64
|
-
}
|
|
65
|
-
return workerHooksFixtures;
|
|
66
|
-
}
|
|
67
|
-
function getOptionsFromArgs(args) {
|
|
68
|
-
if (typeof args[0] === 'object') {
|
|
69
|
-
return args[0];
|
|
70
|
-
}
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
function getFnFromArgs(args) {
|
|
74
|
-
return args.length === 1 ? args[0] : args[1];
|
|
75
|
-
}
|
|
76
|
-
function addHook(hook) {
|
|
77
|
-
if (hook.type === 'beforeAll') {
|
|
78
|
-
workerHooks.push(hook);
|
|
79
|
-
} else {
|
|
80
|
-
// 'afterAll' hooks run in reverse order
|
|
81
|
-
workerHooks.unshift(hook);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function getTimeoutMessage(hook) {
|
|
85
|
-
const {
|
|
86
|
-
timeout
|
|
87
|
-
} = hook.options;
|
|
88
|
-
return `${hook.type} hook timeout (${timeout} ms)`;
|
|
89
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "BDDInputConfig", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _config.BDDInputConfig;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "BddWorld", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _bddWorld.BddWorld;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "BddWorldOptions", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _bddWorld.BddWorldOptions;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "createBdd", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _createBdd.createBdd;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "cucumberReporter", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _helper.cucumberReporter;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "defineBddConfig", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _config.defineBddConfig;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "test", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _bddFixtures.test;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
var _config = require("./config");
|
|
49
|
-
var _createBdd = require("./stepDefinitions/createBdd");
|
|
50
|
-
var _bddFixtures = require("./run/bddFixtures");
|
|
51
|
-
var _bddWorld = require("./run/bddWorld");
|
|
52
|
-
var _helper = require("./reporter/cucumber/helper");
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fixtureParameterNames = fixtureParameterNames;
|
|
7
|
-
/**
|
|
8
|
-
* Extracted from playwright.
|
|
9
|
-
* https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
|
|
10
|
-
*/
|
|
11
|
-
/* eslint-disable max-statements, complexity, max-len, max-depth */
|
|
12
|
-
const signatureSymbol = Symbol('signature');
|
|
13
|
-
function fixtureParameterNames(fn) {
|
|
14
|
-
if (typeof fn !== 'function') {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
if (!fn[signatureSymbol]) {
|
|
18
|
-
fn[signatureSymbol] = innerFixtureParameterNames(fn);
|
|
19
|
-
}
|
|
20
|
-
return fn[signatureSymbol];
|
|
21
|
-
}
|
|
22
|
-
function innerFixtureParameterNames(fn) {
|
|
23
|
-
const text = filterOutComments(fn.toString());
|
|
24
|
-
const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
|
|
25
|
-
if (!match) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const trimmedParams = match[1].trim();
|
|
29
|
-
if (!trimmedParams) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const [firstParam] = splitByComma(trimmedParams);
|
|
33
|
-
if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
|
|
34
|
-
throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
|
|
35
|
-
}
|
|
36
|
-
const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
|
|
37
|
-
const colon = prop.indexOf(':');
|
|
38
|
-
return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
|
|
39
|
-
});
|
|
40
|
-
const restProperty = props.find(prop => prop.startsWith('...'));
|
|
41
|
-
if (restProperty) {
|
|
42
|
-
throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
|
|
43
|
-
}
|
|
44
|
-
return props;
|
|
45
|
-
}
|
|
46
|
-
function filterOutComments(s) {
|
|
47
|
-
const result = [];
|
|
48
|
-
let commentState = 'none';
|
|
49
|
-
for (let i = 0; i < s.length; ++i) {
|
|
50
|
-
if (commentState === 'singleline') {
|
|
51
|
-
if (s[i] === '\n') {
|
|
52
|
-
commentState = 'none';
|
|
53
|
-
}
|
|
54
|
-
} else if (commentState === 'multiline') {
|
|
55
|
-
if (s[i - 1] === '*' && s[i] === '/') {
|
|
56
|
-
commentState = 'none';
|
|
57
|
-
}
|
|
58
|
-
} else if (commentState === 'none') {
|
|
59
|
-
if (s[i] === '/' && s[i + 1] === '/') {
|
|
60
|
-
commentState = 'singleline';
|
|
61
|
-
} else if (s[i] === '/' && s[i + 1] === '*') {
|
|
62
|
-
commentState = 'multiline';
|
|
63
|
-
i += 2;
|
|
64
|
-
} else {
|
|
65
|
-
result.push(s[i]);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return result.join('');
|
|
70
|
-
}
|
|
71
|
-
function splitByComma(s) {
|
|
72
|
-
const result = [];
|
|
73
|
-
const stack = [];
|
|
74
|
-
let start = 0;
|
|
75
|
-
for (let i = 0; i < s.length; i++) {
|
|
76
|
-
if (s[i] === '{' || s[i] === '[') {
|
|
77
|
-
stack.push(s[i] === '{' ? '}' : ']');
|
|
78
|
-
} else if (s[i] === stack[stack.length - 1]) {
|
|
79
|
-
stack.pop();
|
|
80
|
-
} else if (!stack.length && s[i] === ',') {
|
|
81
|
-
const token = s.substring(start, i).trim();
|
|
82
|
-
if (token) {
|
|
83
|
-
result.push(token);
|
|
84
|
-
}
|
|
85
|
-
start = i + 1;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const lastToken = s.substring(start).trim();
|
|
89
|
-
if (lastToken) {
|
|
90
|
-
result.push(lastToken);
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
@@ -1,79 +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.getLocationByOffset = getLocationByOffset;
|
|
8
|
-
exports.getLocationInFile = getLocationInFile;
|
|
9
|
-
var _url = _interopRequireDefault(require("url"));
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
/**
|
|
12
|
-
* Finds first frame in the callstack that matches provided file.
|
|
13
|
-
* Constructs location object from that frame.
|
|
14
|
-
*
|
|
15
|
-
* Example:
|
|
16
|
-
* Calling getLocationInFile('file-3.js');
|
|
17
|
-
* Call stack:
|
|
18
|
-
* - at <anonymous> (file-1.js:1:2)
|
|
19
|
-
* - at myFunction2 (file-2.js:3:4)
|
|
20
|
-
* - at myFunction3 (file-3.js:5:6)
|
|
21
|
-
* - at myFunction4 (file-4.js:7:8)
|
|
22
|
-
*
|
|
23
|
-
* Returned value: { file: 'file-3.js', line: 5, column: 6 }
|
|
24
|
-
*/
|
|
25
|
-
function getLocationInFile(filePath) {
|
|
26
|
-
const filePathUrl = _url.default.pathToFileURL(filePath).toString();
|
|
27
|
-
return getLocationBy(stackFrames => {
|
|
28
|
-
return stackFrames.find(frame => {
|
|
29
|
-
const frameFile = frame.getFileName();
|
|
30
|
-
return frameFile === filePath || frameFile === filePathUrl;
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function getLocationByOffset(offset) {
|
|
35
|
-
return getLocationBy(stackFrames => stackFrames[offset]);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Iterates stacktrace of the call of this function
|
|
39
|
-
* and finds frame using provided findFrame predicate.
|
|
40
|
-
* Constructs location object from the found frame.
|
|
41
|
-
*
|
|
42
|
-
* This function is based on Playwright's wrapFunctionWithLocation().
|
|
43
|
-
* See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/transform/transform.ts#L261
|
|
44
|
-
*/
|
|
45
|
-
function getLocationBy(findFrame) {
|
|
46
|
-
const {
|
|
47
|
-
sourceMapSupport
|
|
48
|
-
} = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
|
|
49
|
-
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
50
|
-
// modify prepareStackTrace to return Location object instead of string
|
|
51
|
-
Error.prepareStackTrace = (error, stackFrames) => {
|
|
52
|
-
const foundFrame = findFrame(stackFrames);
|
|
53
|
-
if (!foundFrame) {
|
|
54
|
-
return {
|
|
55
|
-
file: '',
|
|
56
|
-
line: 0,
|
|
57
|
-
column: 0
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const frame = sourceMapSupport.wrapCallSite(foundFrame);
|
|
61
|
-
const fileName = frame.getFileName();
|
|
62
|
-
// Node error stacks for modules use file:// urls instead of paths.
|
|
63
|
-
const file = fileName !== null && fileName !== void 0 && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
|
|
64
|
-
return {
|
|
65
|
-
file,
|
|
66
|
-
line: frame.getLineNumber(),
|
|
67
|
-
column: frame.getColumnNumber()
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
// commented stackTraceLImit modification, todo: check if it has perf impact
|
|
71
|
-
// const oldStackTraceLimit = Error.stackTraceLimit;
|
|
72
|
-
// Error.stackTraceLimit = level + 1;
|
|
73
|
-
const obj = {};
|
|
74
|
-
Error.captureStackTrace(obj);
|
|
75
|
-
const location = obj.stack;
|
|
76
|
-
// Error.stackTraceLimit = oldStackTraceLimit;
|
|
77
|
-
Error.prepareStackTrace = oldPrepareStackTrace;
|
|
78
|
-
return location;
|
|
79
|
-
}
|