|
| 1 | +import fs from 'fs/promises' |
| 2 | +import path from 'path' |
| 3 | +import { fileURLToPath } from 'url' |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | + |
| 6 | +const dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 7 | + |
| 8 | +describe('typescript.postProcess', () => { |
| 9 | + it('should apply postProcess functions to generated types', async () => { |
| 10 | + const outputFile = path.resolve(dirname, 'payload-types.ts') |
| 11 | + const content = await fs.readFile(outputFile, 'utf-8') |
| 12 | + |
| 13 | + // Verify custom types were injected by postProcess |
| 14 | + expect(content).toContain('export type TestPluginGeneric<T> = { value: T };') |
| 15 | + expect(content).toContain('export type SecondGeneric<K, V> = { key: K; value: V };') |
| 16 | + }) |
| 17 | + |
| 18 | + it('should apply multiple postProcess functions in order', async () => { |
| 19 | + const outputFile = path.resolve(dirname, 'payload-types.ts') |
| 20 | + const content = await fs.readFile(outputFile, 'utf-8') |
| 21 | + |
| 22 | + // SecondGeneric (from second function) should appear before TestPluginGeneric |
| 23 | + // because the second function prepends to TestPluginGeneric |
| 24 | + const secondIndex = content.indexOf('SecondGeneric') |
| 25 | + const firstIndex = content.indexOf('TestPluginGeneric') |
| 26 | + const configIndex = content.indexOf('export interface Config') |
| 27 | + |
| 28 | + expect(secondIndex).toBeGreaterThan(-1) |
| 29 | + expect(firstIndex).toBeGreaterThan(-1) |
| 30 | + expect(secondIndex).toBeLessThan(firstIndex) |
| 31 | + expect(firstIndex).toBeLessThan(configIndex) |
| 32 | + }) |
| 33 | +}) |
0 commit comments