/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
apps/dotcom/zero-cache/validateMigrationFilenames.test.ts
43 строки
1 KB
Mitja Bezenšek
test(dotcom): catch duplicate or non-contiguous zero-cache migration numbers (#9076)
09 июн 2026, 14:04
Не верифицирован
09 июн 2026, 14:04
e09b350
Код
Авторство
О чём код?
import { readdirSync } from 'fs' import { fileURLToPath } from 'url' import { describe, expect, it } from 'vitest' import { validateMigrationFilenames } from './validateMigrationFilenames' const migrationsDir = fileURLToPath(new URL('./migrations', import.meta.url)) describe('validateMigrationFilenames', () => { it('passes for the migrations checked into this package', () => { const filenames = readdirSync(migrationsDir) expect(() => validateMigrationFilenames(filenames)).not.toThrow() }) it('accepts a clean contiguous sequence', () => { expect(() => validateMigrationFilenames(['000_seed.sql', '001_a.sql', '002_b.sql']) ).not.toThrow() }) it('throws on a duplicate number', () => { expect(() => validateMigrationFilenames(['000_seed.sql', '001_a.sql', '001_b.sql'])).toThrow( /Duplicate migration number 001/ ) }) it('throws on a gap in the sequence', () => { expect(() => validateMigrationFilenames(['000_seed.sql', '002_b.sql'])).toThrow(/missing 001/) }) it('throws when the sequence does not start at 000', () => { expect(() => validateMigrationFilenames(['001_a.sql'])).toThrow(/must start at 000/) }) it('throws on a malformed filename', () => { expect(() => validateMigrationFilenames(['1_a.sql'])).toThrow(/must match/) }) it('allows explicitly grandfathered duplicate numbers', () => { expect(() => validateMigrationFilenames(['000_seed.sql', '001_a.sql', '001_b.sql'], new Set([1])) ).not.toThrow() }) })