diff --git a/packages/astro/package.json b/packages/astro/package.json index 32a9d68f5ec31..a0296ecc2b347 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -121,7 +121,7 @@ "test:e2e:match": "playwright test -g", "test:e2e:chrome": "playwright test", "test:e2e:firefox": "playwright test --config playwright.firefox.config.js", - "test:node": "astro-scripts test \"test/**/*.test.js\"" + "test:node": "astro-scripts test \"test/content-layer.test.js\" --timeout 30000 --only" }, "dependencies": { "@astrojs/compiler": "^2.8.1", @@ -243,4 +243,4 @@ "publishConfig": { "provenance": true } -} +} \ No newline at end of file diff --git a/packages/astro/src/content/loaders/glob.ts b/packages/astro/src/content/loaders/glob.ts index cd20973480c9c..e6b4086578d4b 100644 --- a/packages/astro/src/content/loaders/glob.ts +++ b/packages/astro/src/content/loaders/glob.ts @@ -73,6 +73,7 @@ export function glob(globOptions: GlobOptions): Loader { logger.warn(`No entry type found for ${entry}`); return; } + console.log({ entry, base }); const fileUrl = new URL(entry, base); const { body, data } = await entryType.getEntryInfo({ contents: await fs.readFile(fileUrl, 'utf-8'), @@ -81,7 +82,10 @@ export function glob(globOptions: GlobOptions): Loader { const id = generateId({ entry, base, data }); + console.log({ fileUrl }); + const filePath = fileURLToPath(fileUrl); + console.log({ filePath }); const parsedData = await parseData({ id, @@ -111,6 +115,9 @@ export function glob(globOptions: GlobOptions): Loader { if (!baseDir.pathname.endsWith('/')) { baseDir.pathname = `${baseDir.pathname}/`; } + console.log('basedir', baseDir); + console.log('globOptions', globOptions.base); + console.log('settings', settings.config.root); const files = await fastGlob(globOptions.pattern, { cwd: fileURLToPath(baseDir), @@ -131,11 +138,19 @@ export function glob(globOptions: GlobOptions): Loader { files.map((entry) => limit(async () => { const entryType = configForFile(entry); - await syncData(entry, baseDir, options, entryType); + try { + await syncData(entry, baseDir, options, entryType); + } catch (err) { + logger.error(`Failed to load ${entry}: ${err}`); + } }) ) ); + if (!watcher) { + return; + } + const matcher: RegExp = micromatch.makeRe(globOptions.pattern); const matchesGlob = (entry: string) => !entry.startsWith('../') && matcher.test(entry); @@ -152,11 +167,11 @@ export function glob(globOptions: GlobOptions): Loader { await syncData(entry, baseUrl, options, entryType); logger.info(`Reloaded data from ${green(entry)}`); } - watcher?.on('change', onChange); + watcher.on('change', onChange); - watcher?.on('add', onChange); + watcher.on('add', onChange); - watcher?.on('unlink', async (deletedPath) => { + watcher.on('unlink', async (deletedPath) => { const entry = relative(basePath, deletedPath); if (!matchesGlob(entry)) { return; diff --git a/packages/astro/test/content-layer.test.js b/packages/astro/test/content-layer.test.js index 4e1f2d7c3a668..18f8558401e72 100644 --- a/packages/astro/test/content-layer.test.js +++ b/packages/astro/test/content-layer.test.js @@ -4,7 +4,7 @@ import { loadFixture } from './test-utils.js'; import { sep } from 'node:path'; import { sep as posixSep } from 'node:path/posix'; -describe('Content Layer', () => { +describe.only('Content Layer', () => { /** @type {import("./test-utils.js").Fixture} */ let fixture; @@ -12,7 +12,7 @@ describe('Content Layer', () => { fixture = await loadFixture({ root: './fixtures/content-layer/' }); }); - describe('Build', () => { + describe.only('Build', () => { let json; before(async () => { fixture = await loadFixture({ root: './fixtures/content-layer/' }); @@ -21,7 +21,7 @@ describe('Content Layer', () => { json = JSON.parse(rawJson); }); - it('Returns custom loader collection', async () => { + it.only('Returns custom loader collection', async () => { assert.ok(json.hasOwnProperty('customLoader')); assert.ok(Array.isArray(json.customLoader)); diff --git a/packages/astro/test/fixtures/content-layer/src/content/config.ts b/packages/astro/test/fixtures/content-layer/src/content/config.ts index 7b5bd16a9abfd..6eb3682a922f3 100644 --- a/packages/astro/test/fixtures/content-layer/src/content/config.ts +++ b/packages/astro/test/fixtures/content-layer/src/content/config.ts @@ -69,8 +69,13 @@ const cats = defineCollection({ }), }); +console.log('import.meta.url', import.meta.url); +console.log('url', new URL('../../content-outside-src', import.meta.url).href ); +console.log('fileURLToPath', fileURLToPath(new URL('../../content-outside-src', import.meta.url))); + // Absolute paths should also work -const absoluteRoot = fileURLToPath(new URL('../../content-outside-src', import.meta.url)) +const absoluteRoot = fileURLToPath(new URL('../../content-outside-src', import.meta.url)); +console.log('absoluteRoot', absoluteRoot); const spacecraft = defineCollection({ type: 'experimental_data', diff --git a/scripts/cmd/test.js b/scripts/cmd/test.js index 04f02f73afc00..d0d64a883c60a 100644 --- a/scripts/cmd/test.js +++ b/scripts/cmd/test.js @@ -7,7 +7,7 @@ import arg from 'arg'; import glob from 'tiny-glob'; const isCI = !!process.env.CI; -const defaultTimeout = isCI ? 1400000 : 600000; +const defaultTimeout = 600000 //isCI ? 600000 : 600000; export default async function test() { const args = arg({