|
| 1 | +import { describe, test, vi, expect } from 'vitest'; |
| 2 | +import { is_building_for_cloudflare_pages } from './utils.js'; |
| 3 | + |
| 4 | +describe('detects Cloudflare Pages project', () => { |
| 5 | + test('by default', () => { |
| 6 | + expect( |
| 7 | + is_building_for_cloudflare_pages(/** @type {import('wrangler').Unstable_Config} */ ({})) |
| 8 | + ).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + test('CF_PAGES environment variable', () => { |
| 12 | + vi.stubEnv('CF_PAGES', '1'); |
| 13 | + const result = is_building_for_cloudflare_pages( |
| 14 | + /** @type {import('wrangler').Unstable_Config} */ ({}) |
| 15 | + ); |
| 16 | + vi.unstubAllEnvs(); |
| 17 | + expect(result).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + test('empty Wrangler configuration file', () => { |
| 21 | + expect( |
| 22 | + is_building_for_cloudflare_pages( |
| 23 | + /** @type {import('wrangler').Unstable_Config} */ ({ |
| 24 | + configPath: 'wrangler.jsonc' |
| 25 | + }) |
| 26 | + ) |
| 27 | + ).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + test('pages_build_output_dir config key', () => { |
| 31 | + expect( |
| 32 | + is_building_for_cloudflare_pages( |
| 33 | + /** @type {import('wrangler').Unstable_Config} */ ({ |
| 34 | + configPath: 'wrangler.jsonc', |
| 35 | + pages_build_output_dir: 'dist' |
| 36 | + }) |
| 37 | + ) |
| 38 | + ).toBe(true); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +describe('detects Cloudflare Workers project', () => { |
| 43 | + test('main config key', () => { |
| 44 | + expect( |
| 45 | + is_building_for_cloudflare_pages( |
| 46 | + /** @type {import('wrangler').Unstable_Config} */ ({ |
| 47 | + configPath: 'wrangler.jsonc', |
| 48 | + main: 'dist/index.js' |
| 49 | + }) |
| 50 | + ) |
| 51 | + ).toBe(false); |
| 52 | + }); |
| 53 | + |
| 54 | + test('assets config key', () => { |
| 55 | + expect( |
| 56 | + is_building_for_cloudflare_pages( |
| 57 | + /** @type {import('wrangler').Unstable_Config} */ ({ |
| 58 | + configPath: 'wrangler.jsonc', |
| 59 | + assets: { |
| 60 | + directory: 'dist/assets', |
| 61 | + binding: 'ASSETS' |
| 62 | + } |
| 63 | + }) |
| 64 | + ) |
| 65 | + ).toBe(false); |
| 66 | + }); |
| 67 | +}); |
0 commit comments