Compare commits

...

1 Commits

Author SHA1 Message Date
Elliot DeNolf
90fc7b0df3 test: add snapshot test for TS type generation 2024-08-05 14:54:53 -04:00
3 changed files with 1546 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,12 @@ import type { IndexDirection, IndexOptions } from 'mongoose'
import type { PaginatedDocs, Payload } from 'payload'
import { reload } from '@payloadcms/next/utilities'
import fs from 'fs/promises'
import { fileURLToPath } from 'node:url'
import path from 'path'
import { generateTypes } from 'payload/node'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
import type { GroupField, RichTextField } from './payload-types.js'
@@ -1695,4 +1701,19 @@ describe('Fields', () => {
expect(result.docs).toHaveLength(1)
})
})
describe('TypeScript generated types', () => {
/**
* Check that the generated types have not unintentionally changed.
*
* If they must change:
*
* AFTER REVIEWING THE CHANGES, update the snapshot with `pnpm test:int fields --updateSnapshot`
*/
it('should not unintentionally change the generated types', async () => {
await generateTypes(payload.config)
const payloadTypes = await fs.readFile(path.resolve(dirname, './payload-types.ts'), 'utf-8')
expect(payloadTypes).toMatchSnapshot()
})
})
})

View File

@@ -74,6 +74,7 @@ export interface Config {
export interface UserAuthOperations {
forgotPassword: {
email: string;
password: string;
};
login: {
email: string;
@@ -85,6 +86,7 @@ export interface UserAuthOperations {
};
unlock: {
email: string;
password: string;
};
}
/**
@@ -279,7 +281,7 @@ export interface User {
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
password: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
@@ -594,6 +596,19 @@ export interface BlockField {
blockType: 'text';
}[]
| null;
blocksWithLocalizedArray?:
| {
array?:
| {
text?: string | null;
id?: string | null;
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'localizedArray';
}[]
| null;
blocksWithSimilarConfigs?:
| (
| {