Skip to main content

TestPipeline

Home > @backstage/plugin-search-backend-node > TestPipeline

Test utility for Backstage Search collators, decorators, and indexers.

Signature:

class TestPipeline 

Example 1

An example test checking that a collator provides expected documents.

it('provides expected documents', async () => {
const testSubject = await yourCollatorFactory.getCollator();
const pipeline = TestPipeline.fromCollator(testSubject);

const { documents } = await pipeline.execute();

expect(documents).toHaveLength(2);
})

Example 2

An example test checking that a decorator behaves as expected.

it('filters private documents', async () => {
const testSubject = await yourDecoratorFactory.getDecorator();
const pipeline = TestPipeline
.fromDecorator(testSubject)
.withDocuments([{ title: 'Private', location: '/private', text: '' }]);

const { documents } = await pipeline.execute();

expect(documents).toHaveLength(0);
})

Methods

MethodModifiersDescription
execute()Execute the test pipeline so that you can make assertions about the result or behavior of the given test subject.
fromCollator(collator)staticCreate a test pipeline given a collator you want to test.
fromDecorator(decorator)staticCreate a test pipeline given a decorator you want to test.
fromIndexer(indexer)staticCreate a test pipeline given an indexer you want to test.
withCollator(collator)Add a collator to the test pipeline.
withDecorator(decorator)Add a decorator to the test pipeline.
withDocuments(documents)Provide documents for testing decorators and indexers.
withIndexer(indexer)Add an indexer to the test pipeline.
withSubject(subject)staticProvide the collator, decorator, or indexer to be tested.