Skip to content

contentful testing

The helpers this package ships for your tests, by the path you import them from. How the test layers fit together is in the testing guide.

@evolve-framework/contentful/testing

A test context, a mocked Contentful API and a test executor.

createTestContextValueCreate a test context value for testing purposes
import { createTestContextValue } from "@evolve-framework/contentful/testing";
function createTestContextValue(): ContextValue

Returns ContextValue

createTestExecutorCreate a GraphQL executor for testing purposes.
import { createTestExecutor } from "@evolve-framework/contentful/testing";

See https://the-guild.dev/graphql/yoga-server/docs/features/testing for more information on how to use it

function createTestExecutor(): DisposableAsyncExecutor

Returns DisposableAsyncExecutor

setTestRoutesRoute pages for a test context, as the route index would: page entries with a slug per locale and a parent, or a path per entry id in en-GB for short.
import { setTestRoutes } from "@evolve-framework/contentful/testing";
function setTestRoutes(
context: ContextValue,
pages: Record<string, string> | RouteSource[],
): void
OptionTypeDescription
loaders{ catalogPageById: DataLoader<string, (BaseEntry & { sys: { contentType: { sys: { id: "catalog_page"; }; }; }; fields: { title?: string | undefined; description…
storeContext?StoreContext

Returns void

mswServer
import { mswServer } from "@evolve-framework/contentful/testing";
const mswServer: SetupServer

Commands

For data in a shared environment, the package also adds these commands:

  • evolve eject: Eject built-in blocks into your project so you own them
  • evolve field-tabs: Put every content type's fields on the Content, SEO and Settings tabs
  • evolve tf-export: Export the built-in content blocks' Terraform to disk