frontend-test-utils: updated to use and report errors via error collector
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -1078,7 +1078,7 @@ describe('createExtension', () => {
|
||||
.add(multi2Ext)
|
||||
.get(outputRef),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to instantiate extension 'subject', override data provided for input 'multi' must match the length of the original inputs"`,
|
||||
`"Failed to resolve the extension tree: Failed to instantiate extension 'subject', override data provided for input 'multi' must match the length of the original inputs"`,
|
||||
);
|
||||
|
||||
// Mix forward and data override
|
||||
@@ -1101,7 +1101,7 @@ describe('createExtension', () => {
|
||||
.add(multi2Ext)
|
||||
.get(outputRef),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to instantiate extension 'subject', override data for input 'multi' may not mix forwarded inputs with data overrides"`,
|
||||
`"Failed to resolve the extension tree: Failed to instantiate extension 'subject', override data for input 'multi' may not mix forwarded inputs with data overrides"`,
|
||||
);
|
||||
|
||||
// Required input not provided
|
||||
@@ -1124,7 +1124,7 @@ describe('createExtension', () => {
|
||||
.add(multi2Ext)
|
||||
.get(outputRef),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to instantiate extension 'subject', missing required extension data value(s) 'test1'"`,
|
||||
`"Failed to resolve the extension tree: Failed to instantiate extension 'subject', missing required extension data value(s) 'test1'"`,
|
||||
);
|
||||
|
||||
// Wrong value provided
|
||||
@@ -1153,7 +1153,7 @@ describe('createExtension', () => {
|
||||
.add(multi2Ext)
|
||||
.get(outputRef),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to instantiate extension 'subject', extension data 'test2' was provided but not declared"`,
|
||||
`"Failed to resolve the extension tree: Failed to instantiate extension 'subject', extension data 'test2' was provided but not declared"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,6 +35,8 @@ import { resolveAppNodeSpecs } from '../../../frontend-app-api/src/tree/resolveA
|
||||
import { instantiateAppNodeTree } from '../../../frontend-app-api/src/tree/instantiateAppNodeTree';
|
||||
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
|
||||
import { readAppExtensionsConfig } from '../../../frontend-app-api/src/tree/readAppExtensionsConfig';
|
||||
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
|
||||
import { createErrorCollector } from '../../../frontend-app-api/src/wiring/createErrorCollector';
|
||||
import { TestApiRegistry } from '@backstage/test-utils';
|
||||
import { OpaqueExtensionDefinition } from '@internal/frontend';
|
||||
|
||||
@@ -191,16 +193,29 @@ export class ExtensionTester<UOutput extends ExtensionDataRef> {
|
||||
);
|
||||
}
|
||||
|
||||
const collector = createErrorCollector();
|
||||
|
||||
const tree = resolveAppTree(
|
||||
subject.id,
|
||||
resolveAppNodeSpecs({
|
||||
features: [],
|
||||
builtinExtensions: this.#extensions.map(_ => _.extension),
|
||||
parameters: readAppExtensionsConfig(this.#getConfig()),
|
||||
collector,
|
||||
}),
|
||||
collector,
|
||||
);
|
||||
|
||||
instantiateAppNodeTree(tree.root, TestApiRegistry.from());
|
||||
instantiateAppNodeTree(tree.root, TestApiRegistry.from(), collector);
|
||||
|
||||
const errors = collector.collectErrors();
|
||||
if (errors) {
|
||||
throw new Error(
|
||||
`Failed to resolve the extension tree: ${errors
|
||||
.map(e => e.message)
|
||||
.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.#tree = tree;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user