Skip to content

Commit 9a3a16f

Browse files
bcomnesclaude
andcommitted
Add integration test proving global.data.js output reaches template vars
global.data.js now returns a globalDataSentinel value. feeds.template.js reads it from vars and includes it as a custom extension field in feed.json. The test asserts the sentinel appears in the generated feed, which only passes when globalDataVars are correctly merged into templateGlobalVars. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ed2f43e commit 9a3a16f

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

test-cases/general-features/index.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ test.describe('general-features', () => {
103103
const jsChunkFiles = files.filter(f => f.relname.match(/chunks\/js\/chunk-.+\.js$/))
104104
assert.ok(jsChunkFiles.length > 0, 'at least one shared JS chunk was produced with a hashed name')
105105

106+
// Verify that global.data.js output reaches template vars
107+
const feedJsonPath = path.join(dest, 'feeds/feed.json')
108+
try {
109+
const feedContent = await readFile(feedJsonPath, 'utf8')
110+
const feedData = JSON.parse(feedContent)
111+
assert.strictEqual(
112+
feedData._globalDataSentinel,
113+
'data-from-global-dot-data',
114+
'feeds template received globalDataSentinel from global.data.js via vars'
115+
)
116+
} catch (err) {
117+
const error = err instanceof Error ? err : new Error('Unknown error', { cause: err })
118+
assert.fail('Failed to verify global.data.js output in template vars: ' + error.message)
119+
}
120+
106121
// Special test for global.data.js blogPostsHtml
107122
const indexPath = path.join(dest, 'index.html')
108123
try {

test-cases/general-features/src/feeds.template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import jsonfeedToAtom from 'jsonfeed-to-atom'
1212
* authorUrl: string,
1313
* authorImgUrl: string,
1414
* publishDate: string,
15-
* siteDescription: string
15+
* siteDescription: string,
16+
* globalDataSentinel: string,
1617
* }>}
1718
*/
1819
export default async function * feedsTemplate ({
@@ -23,6 +24,7 @@ export default async function * feedsTemplate ({
2324
authorUrl,
2425
authorImgUrl,
2526
siteDescription,
27+
globalDataSentinel,
2628
},
2729
pages,
2830
}) {
@@ -39,6 +41,7 @@ export default async function * feedsTemplate ({
3941
home_page_url: homePageUrl,
4042
feed_url: `${homePageUrl}/feed.json`,
4143
description: siteDescription,
44+
_globalDataSentinel: globalDataSentinel,
4245
author: {
4346
name: authorName,
4447
url: authorUrl,

test-cases/general-features/src/global.data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { html } from 'htm/preact'
66
import { render } from 'preact-render-to-string'
77

8-
/** @type {AsyncGlobalDataFunction<{ blogPostsHtml: string }>} */
8+
/** @type {AsyncGlobalDataFunction<{ blogPostsHtml: string, globalDataSentinel: string }>} */
99
export default async function ({ pages }) {
1010
const blogPosts = pages
1111
.filter(page => page.vars?.layout === 'blog' && page.vars?.publishDate)
@@ -36,5 +36,5 @@ export default async function ({ pages }) {
3636
</ul>
3737
`)
3838

39-
return { blogPostsHtml }
39+
return { blogPostsHtml, globalDataSentinel: 'data-from-global-dot-data' }
4040
}

0 commit comments

Comments
 (0)