diff --git a/packages/case-core-plugin-http/src/index.ts b/packages/case-core-plugin-http/src/index.ts index 5ed48a72..480e78df 100644 --- a/packages/case-core-plugin-http/src/index.ts +++ b/packages/case-core-plugin-http/src/index.ts @@ -17,7 +17,10 @@ import { MOCK_HTTP_SERVER, URL_ENCODED_STRING_TYPE, } from '@contract-case/case-core-plugin-http-dsl'; -import { ContractCasePlugin } from '@contract-case/case-plugin-base'; +import { + CORE_PLUGIN_PREFIX, + ContractCasePlugin, +} from '@contract-case/case-plugin-base'; import { HttpBasicAuthMatcher, HttpRequestMatcher, @@ -39,7 +42,10 @@ const CoreHttpPlugin: ContractCasePlugin< AllHttpMockDescriptors, AllHttpMockSetupInfo > = { - name: `_CaseCore: Http / Rest Plugin`, + // Note: If using this code as an example for your own plugin, + // DO NOT start your plugin name with the core plugin prefix + // or ContractCase will not log debug information / load failures appropriately + name: `${CORE_PLUGIN_PREFIX} Http / Rest Plugin`, version: pluginVersion, matcherExecutors: { [HTTP_BASIC_AUTH_TYPE]: HttpBasicAuthMatcher, diff --git a/packages/case-core/src/diffmatch/plugins/loadPlugin.ts b/packages/case-core/src/diffmatch/plugins/loadPlugin.ts index 8ac63be9..f39a4483 100644 --- a/packages/case-core/src/diffmatch/plugins/loadPlugin.ts +++ b/packages/case-core/src/diffmatch/plugins/loadPlugin.ts @@ -6,6 +6,7 @@ import { IsCaseNodeForType, LogContext, MockExecutorFn, + CORE_PLUGIN_PREFIX, } from '@contract-case/case-plugin-base'; import { caseVersion } from '../../entities/caseVersion'; @@ -28,7 +29,7 @@ export const loadPlugin = < if (loadedPluginVersions[plugin.name] != null) { if (plugin.version !== loadedPluginVersions[plugin.name]) { if ( - plugin.name.startsWith(`_CaseCore:`) && + plugin.name.startsWith(CORE_PLUGIN_PREFIX) && plugin.version !== caseVersion ) { throw new CaseCoreError( @@ -40,15 +41,15 @@ export const loadPlugin = < ); } context.logger.deepMaintainerDebug( - `Plugin '${plugin.name}' at version '${plugin.version}' has been previously loaded, skipping load of mock executors`, + `Plugin '${plugin.name}' at version '${plugin.version}' has been previously loaded, skipping`, ); return; } - if (plugin.name.startsWith(`_CaseCore:`)) { + if (plugin.name.startsWith(CORE_PLUGIN_PREFIX)) { context.logger.deepMaintainerDebug(`Loading core plugin '${plugin.name}'`); } else { context.logger.debug( - `Loading mock definitions for plugin '${plugin.name}' version ${plugin.version}`, + `Loading plugin '${plugin.name}' version ${plugin.version}`, ); } @@ -77,8 +78,8 @@ export const loadPlugin = < unknown, '_case:MockHttpServer' >; - typeToPluginName[mockType] = plugin.name; - loadedPluginVersions[plugin.name] = plugin.version; }); + + loadedPluginVersions[plugin.name] = plugin.version; }; diff --git a/packages/case-plugin-base/src/corePlugins.ts b/packages/case-plugin-base/src/corePlugins.ts new file mode 100644 index 00000000..e6371068 --- /dev/null +++ b/packages/case-plugin-base/src/corePlugins.ts @@ -0,0 +1,12 @@ +/** + * DO NOT USE THIS IN YOUR OWN PLUGINS + * + * The prefix for ContractCase core plugin names. Plugin names with + * this prefix are treated as always loaded, log less debug information, + * and any errors in loading are treated as core crashes rather than user + * configuration errors. + * + * Other than the way logs and load failures are treated, there's no special + * treatment given to core plugins, + */ +export const CORE_PLUGIN_PREFIX = '_CaseCore:' as const; diff --git a/packages/case-plugin-base/src/index.ts b/packages/case-plugin-base/src/index.ts index 8e635b0a..0a20eb0b 100644 --- a/packages/case-plugin-base/src/index.ts +++ b/packages/case-plugin-base/src/index.ts @@ -6,6 +6,7 @@ export * from './context'; // export * from './core'; +export * from './corePlugins'; export * from './errors'; export * from './logger'; export * from './matchers';