-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19071 from storybookjs/tom/sb-699-sb19015-70-vite…
…-storybook-crashes-when Ensure if a docs render is torndown during preparation, it throws
- Loading branch information
Showing
9 changed files
with
326 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
code/lib/preview-web/src/render/StandaloneDocsRender.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { jest, describe, it, expect } from '@jest/globals'; | ||
import { Channel } from '@storybook/channels'; | ||
import { AnyFramework } from '@storybook/csf'; | ||
import { StoryStore } from '@storybook/store'; | ||
import type { StandaloneDocsIndexEntry } from '@storybook/store'; | ||
import { PREPARE_ABORTED } from './Render'; | ||
|
||
import { StandaloneDocsRender } from './StandaloneDocsRender'; | ||
|
||
const entry = { | ||
type: 'docs', | ||
id: 'introduction--docs', | ||
name: 'Docs', | ||
title: 'Introduction', | ||
importPath: './Introduction.mdx', | ||
storiesImports: [], | ||
standalone: true, | ||
} as StandaloneDocsIndexEntry; | ||
|
||
const createGate = (): [Promise<any | undefined>, (_?: any) => void] => { | ||
let openGate = (_?: any) => {}; | ||
const gate = new Promise<any | undefined>((resolve) => { | ||
openGate = resolve; | ||
}); | ||
return [gate, openGate]; | ||
}; | ||
|
||
describe('StandaloneDocsRender', () => { | ||
it('throws PREPARE_ABORTED if torndown during prepare', async () => { | ||
const [importGate, openImportGate] = createGate(); | ||
const mockStore = { | ||
loadEntry: jest.fn(async () => { | ||
await importGate; | ||
return {}; | ||
}), | ||
}; | ||
|
||
const render = new StandaloneDocsRender( | ||
new Channel(), | ||
mockStore as unknown as StoryStore<AnyFramework>, | ||
entry | ||
); | ||
|
||
const preparePromise = render.prepare(); | ||
|
||
render.teardown(); | ||
|
||
openImportGate(); | ||
|
||
await expect(preparePromise).rejects.toThrowError(PREPARE_ABORTED); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.