@contract-case/case-plugin-base
Version:
Plugin framework for writing plugins for the ContractCase test framework
37 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPluginConfig = void 0;
const errors_1 = require("../errors");
/**
* Gets the plugin configuration (the mockConfig object keyed by your plugin
* short name) for the given plugin. This function validates the context and
* throws {@link CaseConfigurationError} if the mockConfig object is not set
* or the key is missing. You don't need to catch this exception, you can let
* it bubble up to the framework for it to be rendered to the user.
*
* This function doesn't know the expected shape of your configuration object;
* it's up to you to then validate the object has the appropriate fields set
* to valid values.
* @public
*
* @param context - the current {@link MatchContext}
* @param pluginShortName - the short name for the currently executing plugin
* @returns the value of `mockConfig[pluginShortName]`
* @throws CaseConfigurationError if the expected configuration keys are not
* set, or are set but not defined.
*/
const getPluginConfig = (context, description) => {
if (!context['_case:currentRun:context:mockConfig']) {
throw new errors_1.CaseConfigurationError(`The plugin '${description.humanReadableName}' requires the mockConfig configuration property to be set with a key of '${description.shortName}'. Please check your configuration.`, context);
}
if (!(description.shortName in context['_case:currentRun:context:mockConfig'])) {
throw new errors_1.CaseConfigurationError(`The plugin '${description.humanReadableName}' requires the mockConfig configuration property to have a key '${description.shortName}'. Please check your configuration.`, context);
}
const pluginConfig = context['_case:currentRun:context:mockConfig'][description.shortName];
if (pluginConfig == null) {
throw new errors_1.CaseConfigurationError(`The mockConfig configuration key '${description.shortName}' was set, but had no content (${description.humanReadableName}). Please check your configuration.`, context);
}
return pluginConfig;
};
exports.getPluginConfig = getPluginConfig;
//# sourceMappingURL=pluginConfig.js.map