summaryrefslogtreecommitdiff
path: root/packages/astro/test/content-layer.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/test/content-layer.test.js')
-rw-r--r--packages/astro/test/content-layer.test.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/packages/astro/test/content-layer.test.js b/packages/astro/test/content-layer.test.js
index 0590e7e59..75d702a94 100644
--- a/packages/astro/test/content-layer.test.js
+++ b/packages/astro/test/content-layer.test.js
@@ -196,7 +196,11 @@ describe('Content Layer', () => {
let devServer;
let json;
before(async () => {
- devServer = await fixture.startDevServer();
+ devServer = await fixture.startDevServer({ force: true });
+ // Vite may not have noticed the saved data store yet. Wait a little just in case.
+ await fixture.onNextDataStoreChange(1000).catch(() => {
+ // Ignore timeout, because it may have saved before we get here.
+ })
const rawJsonResponse = await fixture.fetch('/collections.json');
const rawJson = await rawJsonResponse.text();
json = devalue.parse(rawJson);
@@ -275,6 +279,22 @@ describe('Content Layer', () => {
});
});
+ it('reloads data when an integration triggers a content refresh', async () => {
+ const rawJsonResponse = await fixture.fetch('/collections.json');
+ const initialJson = devalue.parse(await rawJsonResponse.text());
+ assert.equal(initialJson.increment.data.lastValue, 1);
+
+ const refreshResponse = await fixture.fetch('/_refresh', {
+ method: 'POST',
+ body: JSON.stringify({}),
+ });
+ const refreshData = await refreshResponse.json();
+ assert.equal(refreshData.message, 'Content refreshed successfully');
+ const updatedJsonResponse = await fixture.fetch('/collections.json');
+ const updated = devalue.parse(await updatedJsonResponse.text());
+ assert.equal(updated.increment.data.lastValue, 2);
+ });
+
it('updates collection when data file is changed', async () => {
const rawJsonResponse = await fixture.fetch('/collections.json');
const initialJson = devalue.parse(await rawJsonResponse.text());
@@ -286,9 +306,7 @@ describe('Content Layer', () => {
return JSON.stringify(data, null, 2);
});
- // Writes are debounced to 500ms
- await new Promise((r) => setTimeout(r, 700));
-
+ await fixture.onNextDataStoreChange();
const updatedJsonResponse = await fixture.fetch('/collections.json');
const updated = devalue.parse(await updatedJsonResponse.text());
assert.ok(updated.fileLoader[0].data.temperament.includes('Bouncy'));