Skip to content

Commit

Permalink
fix @kbn/test Config class
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed May 12, 2021
1 parent 3513b24 commit 73bd9f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ export class Config {
values: Record<string, any>,
childSchema: any
): boolean {
if (!childSchema._inner) {
if (!childSchema.$_terms.keys) {
return false;
}

// normalize child and pattern checks so we can iterate the checks in a single loop
const checks: Array<{ test: (k: string) => boolean; schema: Schema }> = [
// match children first, they have priority
...(childSchema._inner.children || []).map((child: { key: string; schema: Schema }) => ({
...(childSchema.$_terms.keys || []).map((child: { key: string; schema: Schema }) => ({
test: (k: string) => child.key === k,
schema: child.schema,
})),

// match patterns on any key that doesn't match an explicit child
...(childSchema._inner.patterns || []).map((pattern: { regex: RegExp; rule: Schema }) => ({
...(childSchema.$_terms.patterns || []).map((pattern: { regex: RegExp; rule: Schema }) => ({
test: (k: string) => pattern.regex.test(k) && has(values, k),
schema: pattern.rule,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { dirname, resolve } from 'path';

import Joi from 'joi';
import type { CustomHelpers } from 'joi';

// valid pattern for ID
// enforced camel-case identifiers for consistency
Expand Down Expand Up @@ -61,8 +62,10 @@ const dockerServerSchema = () =>
.default();

const defaultRelativeToConfigPath = (path: string) => {
const makeDefault: any = (_: any, options: any) => resolve(dirname(options.context.path), path);
makeDefault.description = `<config.js directory>/${path}`;
const makeDefault = (parent: any, helpers: CustomHelpers) => {
helpers.schema.description(`<config.js directory>/${path}`);
return resolve(dirname(helpers.prefs.context!.path), path);
};
return makeDefault;
};

Expand Down

0 comments on commit 73bd9f6

Please sign in to comment.