Skip to content

Allow disabling real-world queries during storybook testing #952

@fhennig

Description

@fhennig

I've just ran into an issue where the mock data was silently skipped, which caused confusion on my end.

Maybe we could have an env var that we set during testing to prevent the mock worker from forwarding unmatched requests to the real worker

self.onmessage = async function (event: MessageEvent<MutationOverTimeQuery>) {
    await workerFunction(async () => {
        const query = mockQueries.find((mockQuery) => JSON.stringify(mockQuery.query) === JSON.stringify(event.data));

        if (query !== undefined) {
            return query.response;
        }

        // add something like:
		// if (env.MOCK_ONLY) throw new Error(...)

        return await getMutationOverTimeWorkerFunction(event);
    });
};

I think we need to have it with an env var, because we sometimes still want to have the mock worker fall back, because the story book is also used for user demos. Otherwise we wouldn't need to switch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions