@applitools/eyes-storybook
Version:
71 lines (54 loc) • 2.39 kB
JavaScript
;
const chalk = require('chalk');
const {MissingApiKeyError} = require('@applitools/core');
const {EyesError} = require('@applitools/eyes');
class AbortedByUserError extends EyesError {
reason = 'abortedByUser';
}
class InvalidConfigFileError extends EyesError {
reason = 'invalidConfigFile';
constructor(error) {
super();
const documentationUrl = 'https://applitools.com/tutorials/sdks/storybook/config#properties';
this.message =
`Your configuration file is invalid. Please review our documentation for valid configuration settings: ${documentationUrl}.
Additionally, you can generate a new configuration by running 'npx eyes-setup'.
\n\nError details: ${error.message}`.trim();
}
}
const missingAppNameAndPackageJsonFailMsg = `
${chalk.red(
`App name is not defined. Normally we would take it by default from the package.json file located at the root of your project (${process.cwd()}), but the package.json file wasn't found.`,
)}
${chalk.green(`To set an "appName", do one of the following:
Option 1: specify "appName" in the eyes.json file that should be placed in the current working directory.
Option 2: set an environment variable APPLITOOLS_APP_NAME.
Option 3: have a package.json file in the current working directory that has a "name" property. We'll take it from there.`)}
`;
const missingAppNameInPackageJsonFailMsg = `
${chalk.red(
`App name is not defined. Normally we would take it by default from the package.json file located at the root of your project (${process.cwd()}), but the package.json file doesn't have a "name" property.`,
)}
${chalk.green(
`To fix, add a "name" property to your package.json file located at ${process.cwd()}\n`,
)}
`;
function refineErrorMessage({prefix, error}) {
const message = error && error.message ? error.message : error;
return `${prefix} ${message.replace('Evaluation failed: ', '')}`;
}
function deprecationWarning({deprecatedThing, newThing, isDead}) {
const msg = isDead
? `Notice: ${deprecatedThing} is no longer supported.`
: `Notice: ${deprecatedThing} has been renamed. Please use ${newThing} instead.\n`;
chalk.yellow(msg);
}
module.exports = {
missingAppNameAndPackageJsonFailMsg,
missingAppNameInPackageJsonFailMsg,
refineErrorMessage,
deprecationWarning,
MissingApiKeyError,
AbortedByUserError,
InvalidConfigFileError,
};