Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions web/__tests__/unit/data-dir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Unit tests for lib/data/data-dir.ts — content corpus root resolver.
* Covers both env-driven branches (override + subdir/default) so the path stays
* non-constant-foldable for the Vercel/nft tracer. REF: P2 fix · D-P2-STACK-CANON.
*/
import { describe, it, expect, afterEach } from 'vitest'
import { join } from 'path'
import { dataDir } from '@/lib/data/data-dir'

const ORIG_ENV = { ...process.env }

afterEach(() => {
process.env = { ...ORIG_ENV }
})

describe('dataDir()', () => {
it('returns CONTENT_DATA_DIR verbatim when the override is set', () => {
process.env.CONTENT_DATA_DIR = '/mnt/content'
expect(dataDir()).toBe('/mnt/content')
})

it('joins cwd with CONTENT_DATA_SUBDIR when no override is set', () => {
delete process.env.CONTENT_DATA_DIR
process.env.CONTENT_DATA_SUBDIR = 'corpus'
expect(dataDir()).toBe(join(process.cwd(), 'corpus'))
})

it('defaults to cwd/data when neither env var is set', () => {
delete process.env.CONTENT_DATA_DIR
delete process.env.CONTENT_DATA_SUBDIR
expect(dataDir()).toBe(join(process.cwd(), 'data'))
})
})
5 changes: 5 additions & 0 deletions web/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export default defineConfig({
'lib/cross-refs/quran-hadith.ts',
'lib/data/books.ts',
'lib/data/people.ts',
// Server-only runtime HTTP reader for on-demand SSR pages — fetches content
// over HTTP from the static /content-data assets; needs a live origin and is
// covered by E2E/integration, not vitest+jsdom (same as the fs readers above).
// TODO(P2-E5): restore thresholds once integration test harness is wired in CI.
'lib/data/runtime-data.ts',
// Transitional Next.js compatibility shim — removed once all islands are migrated.
'lib/compat/**',
],
Expand Down
Loading