Skip to content

Commit

Permalink
fix(content): getContentFile stream should be finished (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
stewones authored May 26, 2024
1 parent c2925db commit e0ce74f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/content/src/lib/content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,48 @@ Test agx Content`),
flush();
}));

it('should finish the stream when content is resolved', fakeAsync(() => {
const routeParams = {};
const contentFiles = {
'/src/content/test.md': () =>
Promise.resolve(`---
slug: 'test'
---
Test Content`),
};
const { injectContent } = setup({
routeParams,
contentFiles,
customParam: {
customFilename: 'test',
},
});

let completed = false;
let content: ContentFile<TestAttributes | Record<string, never>> | null =
null;

injectContent().subscribe({
next: (c) => {
content = c;
},
complete: () => {
completed = true;
},
});

flushMicrotasks();
flush();

expect(completed).toBe(true);
expect(content).toEqual({
content: 'Test Content',
attributes: { slug: 'test' },
filename: '/src/content/test',
slug: 'test',
});
}));

function setup(
args: Partial<{
customParam:
Expand Down
2 changes: 2 additions & 0 deletions packages/content/src/lib/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ function getContentFile<
if (import.meta.env.SSR === true) {
waitFor(contentResolver).then((content) => {
observer.next(content);
observer.complete();
});
} else {
contentResolver.then((content) => {
observer.next(content);
observer.complete();
});
}
}
Expand Down

0 comments on commit e0ce74f

Please sign in to comment.