mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
Merge pull request #16947 from storybookjs/16877-await-init-before-cache
Core: Ensure we have a full story index before caching
This commit is contained in:
commit
addfdbf91b
@ -281,7 +281,7 @@ describe('StoryStore', () => {
|
||||
const store = new StoryStore();
|
||||
store.setProjectAnnotations(projectAnnotations);
|
||||
store.initialize({ storyIndex, importFn, cache: false });
|
||||
await store.cacheAllCSFFiles(false);
|
||||
await store.cacheAllCSFFiles();
|
||||
|
||||
await store.loadStory({ storyId: 'component-one--a' });
|
||||
expect(importFn).toHaveBeenCalledWith(storyIndex.stories['component-one--a'].importPath);
|
||||
@ -943,4 +943,20 @@ describe('StoryStore', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('cacheAllCsfFiles', () => {
|
||||
describe('if the store is not yet initialized', () => {
|
||||
it('waits for initialization', async () => {
|
||||
const store = new StoryStore();
|
||||
|
||||
importFn.mockClear();
|
||||
const cachePromise = store.cacheAllCSFFiles();
|
||||
|
||||
store.setProjectAnnotations(projectAnnotations);
|
||||
store.initialize({ storyIndex, importFn, cache: false });
|
||||
|
||||
await expect(cachePromise).resolves.toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ export class StoryStore<TFramework extends AnyFramework> {
|
||||
|
||||
prepareStoryWithCache: typeof prepareStory;
|
||||
|
||||
initializationPromise: Promise<void>;
|
||||
initializationPromise: SynchronousPromise<void>;
|
||||
|
||||
resolveInitializationPromise: () => void;
|
||||
|
||||
@ -175,9 +175,11 @@ export class StoryStore<TFramework extends AnyFramework> {
|
||||
}
|
||||
|
||||
cacheAllCSFFiles(): PromiseLike<void> {
|
||||
return this.loadAllCSFFiles().then((csfFiles) => {
|
||||
return this.initializationPromise.then(() =>
|
||||
this.loadAllCSFFiles().then((csfFiles) => {
|
||||
this.cachedCSFFiles = csfFiles;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Load the CSF file for a story and prepare the story from it and the project annotations.
|
||||
|
Loading…
x
Reference in New Issue
Block a user