|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; |
| 3 | +import { tmpdir } from 'node:os'; |
| 4 | +import { join } from 'node:path'; |
| 5 | +import { describe, it } from 'node:test'; |
| 6 | +import { pathToFileURL } from 'node:url'; |
| 7 | +import { getCloudflareCompatibilityDate } from '../../../dist/cli/add/cloudflare.js'; |
| 8 | + |
| 9 | +describe('astro add cloudflare', () => { |
| 10 | + it('uses the compatibility date exported by the installed adapter', async () => { |
| 11 | + const projectDir = await mkdtemp(join(tmpdir(), 'astro-add-cloudflare-')); |
| 12 | + const adapterDir = join(projectDir, 'node_modules', '@astrojs', 'cloudflare'); |
| 13 | + |
| 14 | + try { |
| 15 | + await mkdir(adapterDir, { recursive: true }); |
| 16 | + await writeFile( |
| 17 | + join(adapterDir, 'package.json'), |
| 18 | + JSON.stringify({ |
| 19 | + name: '@astrojs/cloudflare', |
| 20 | + type: 'module', |
| 21 | + exports: { './info': './info.js' }, |
| 22 | + }), |
| 23 | + ); |
| 24 | + await writeFile( |
| 25 | + join(adapterDir, 'info.js'), |
| 26 | + `export function getLocalWorkerdCompatibilityDate() { |
| 27 | + return { date: '2026-08-15', source: 'workerd' }; |
| 28 | +} |
| 29 | +`, |
| 30 | + ); |
| 31 | + |
| 32 | + const date = await getCloudflareCompatibilityDate(pathToFileURL(`${projectDir}/`)); |
| 33 | + |
| 34 | + assert.equal(date, '2026-08-15'); |
| 35 | + } finally { |
| 36 | + await rm(projectDir, { recursive: true, force: true }); |
| 37 | + } |
| 38 | + }); |
| 39 | +}); |
0 commit comments