UNPKG

cypress-xray-plugin

Version:

A Cypress plugin for uploading test results to Xray (test management for Jira)

166 lines (144 loc) 5.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SkippedError = exports.LoggedError = void 0; exports.errorMessage = errorMessage; exports.isLoggedError = isLoggedError; exports.isSkippedError = isSkippedError; exports.missingTestKeyInCucumberScenarioError = missingTestKeyInCucumberScenarioError; exports.missingTestKeyInTestTitleError = missingTestKeyInTestTitleError; const dedent_1 = require("./dedent"); const help_1 = require("./help"); const string_1 = require("./string"); /** * Returns an error message of any error. * * @param error - the error * @returns the error message */ function errorMessage(error) { if (error instanceof Error) { return error.message; } return (0, string_1.unknownToString)(error); } /** * An error which has been logged to a file or other log locations already. */ class LoggedError extends Error { } exports.LoggedError = LoggedError; /** * Assesses whether the given error is an instance of a {@link LoggedError | `LoggedError`}. * * @param error - the error * @returns `true` if the error is a {@link LoggedError | `LoggedError`}, otherwise `false` */ function isLoggedError(error) { return error instanceof LoggedError; } /** * An error which is thrown when a command is skipped. */ class SkippedError extends Error { } exports.SkippedError = SkippedError; /** * Assesses whether the given error is an instance of a {@link SkippedError | `SkippedError`}. * * @param error - the error * @returns `true` if the error is a {@link SkippedError | `SkippedError`}, otherwise `false` */ function isSkippedError(error) { return error instanceof SkippedError; } // ============================================================================================== // // COLLECTION OF USEFUL ERRORS // // ============================================================================================== // /** * Returns an error describing that a test issue key is missing in the tags of a Cucumber scenario. * * @param scenario - the Cucumber scenario * @param projectKey - the project key * @param isCloudClient - whether Xray cloud is being used * @returns the error */ function missingTestKeyInCucumberScenarioError(scenario, projectKey, isCloudClient) { const firstStepLine = scenario.steps.length > 0 ? `${scenario.steps[0].keyword.trim()} ${scenario.steps[0].text}` : "Given A step"; if (scenario.tags && scenario.tags.length > 0) { return new Error((0, dedent_1.dedent)(` Scenario: ${scenario.name.length > 0 ? scenario.name : "<no name>"} No test issue keys found in tags: ${scenario.tags.map((tag) => tag.name).join("\n")} If a tag contains the test issue key already, specify a global prefix to align the plugin with Xray. For example, with the following plugin configuration: { cucumber: { prefixes: { test: "TestName:" } } } The following tag will be recognized as a test issue tag by the plugin: @TestName:${projectKey}-123 ${scenario.keyword}: ${scenario.name} ${firstStepLine} ... For more information, visit: - ${help_1.HELP.plugin.guides.targetingExistingIssues} - ${help_1.HELP.plugin.configuration.cucumber.prefixes} - ${isCloudClient ? help_1.HELP.xray.importCucumberTests.cloud : help_1.HELP.xray.importCucumberTests.server} `)); } return new Error((0, dedent_1.dedent)(` Scenario: ${scenario.name.length > 0 ? scenario.name : "<no name>"} No test issue keys found in tags. You can target existing test issues by adding a corresponding tag: @${projectKey}-123 ${scenario.keyword}: ${scenario.name} ${firstStepLine} ... You can also specify a prefix to match the tagging scheme configured in your Xray instance: Plugin configuration: { cucumber: { prefixes: { test: "TestName:" } } } Feature file: @TestName:${projectKey}-123 ${scenario.keyword}: ${scenario.name} ${firstStepLine} ... For more information, visit: - ${help_1.HELP.plugin.guides.targetingExistingIssues} - ${help_1.HELP.plugin.configuration.cucumber.prefixes} - ${isCloudClient ? help_1.HELP.xray.importCucumberTests.cloud : help_1.HELP.xray.importCucumberTests.server} `)); } /** * Returns an error describing that a test issue key is missing in a test title. * * @param title - the test title * @param projectKey - the project key * @returns the error */ function missingTestKeyInTestTitleError(title, projectKey) { return new Error((0, dedent_1.dedent)(` Test: ${title} No test issue keys found in title. You can target existing test issues by adding a corresponding issue key: it("${projectKey}-123 ${title}", () => { // ... }); For more information, visit: - ${help_1.HELP.plugin.guides.targetingExistingIssues} `)); }