Skip to content

Commit

Permalink
debug flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 4, 2024
1 parent c4b967a commit 83804ca
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,49 @@ describe('PreviewWeb', () => {
});

it('renders docs mode through docs page', async () => {
console.time('ImportDocsRenderer');
const { DocsRenderer } = await import('@storybook/addon-docs');
console.timeEnd('ImportDocsRenderer');

console.time('SetDocsRenderer');
projectAnnotations.parameters.docs.renderer = () => new DocsRenderer() as any;
console.timeEnd('SetDocsRenderer');

console.time('SetDocumentLocation');
document.location.search = '?id=component-one--docs&viewMode=docs';
console.timeEnd('SetDocumentLocation');

console.time('NewPreviewWeb');
const preview = new PreviewWeb();
console.timeEnd('NewPreviewWeb');

console.time('CreateElement');
const docsRoot = document.createElement('div');
console.timeEnd('CreateElement');

console.time('MockPrepareForDocs');
vi.mocked(preview.view.prepareForDocs).mockReturnValue(docsRoot as any);
console.timeEnd('MockPrepareForDocs');

console.time('MockDocsContainer');
componentOneExports.default.parameters.docs.container.mockImplementationOnce(() =>
React.createElement('div', {}, 'INSIDE')
);
console.timeEnd('MockDocsContainer');

console.time('InitializePreview');
await preview.initialize({ importFn, getProjectAnnotations });
console.timeEnd('InitializePreview');

console.time('WaitForRender');
await waitForRender();
console.timeEnd('WaitForRender');

console.time('ExpectMatch');
expect(docsRoot.outerHTML).toMatchInlineSnapshot('"<div><div>INSIDE</div></div>"');
// Extended timeout to try and avoid
// Error: Event was not emitted in time: storyRendered,docsRendered,storyThrewException,storyErrored,storyMissing
console.timeEnd('ExpectMatch');

// Rest of your code...
}, 10_000);

// TODO @tmeasday please help fixing this test
Expand Down

0 comments on commit 83804ca

Please sign in to comment.