|
| 1 | +import { findMigrationDir } from './findMigrationDir' |
| 2 | +import fs from 'fs' |
| 3 | +import path from 'path' |
| 4 | + |
| 5 | +const workDir = path.resolve(import.meta.dirname, '_tmp') |
| 6 | + |
| 7 | +describe('findMigrationDir', () => { |
| 8 | + beforeEach(() => { |
| 9 | + const cwdSpy = jest.spyOn(process, 'cwd') |
| 10 | + cwdSpy.mockReturnValue(workDir) |
| 11 | + fs.mkdirSync(workDir, { recursive: true }) |
| 12 | + }) |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + fs.rmSync(workDir, { force: true, recursive: true }) |
| 16 | + }) |
| 17 | + |
| 18 | + it('should return the passed directory', () => { |
| 19 | + const dir = path.resolve(workDir, 'custom_migrations') |
| 20 | + expect(findMigrationDir(dir)).toBe(dir) |
| 21 | + }) |
| 22 | + |
| 23 | + it('should return src/migrations because that folder exists', () => { |
| 24 | + fs.mkdirSync(path.resolve(workDir, 'src/migrations'), { recursive: true }) |
| 25 | + expect(findMigrationDir()).toBe(path.resolve(workDir, 'src/migrations')) |
| 26 | + }) |
| 27 | + |
| 28 | + it('should return dist/migrations because that folder exists', () => { |
| 29 | + fs.mkdirSync(path.resolve(workDir, 'dist/migrations'), { recursive: true }) |
| 30 | + expect(findMigrationDir()).toBe(path.resolve(workDir, 'dist/migrations')) |
| 31 | + }) |
| 32 | + |
| 33 | + it('should return src/migrations because src exists', () => { |
| 34 | + fs.mkdirSync(path.resolve(workDir, 'src'), { recursive: true }) |
| 35 | + expect(findMigrationDir()).toBe(path.resolve(workDir, 'src/migrations')) |
| 36 | + }) |
| 37 | + |
| 38 | + it('should return migrations because src does not exist', () => { |
| 39 | + expect(findMigrationDir()).toBe(path.resolve(workDir, 'migrations')) |
| 40 | + }) |
| 41 | +}) |
0 commit comments