-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add import prop @ file migration provider.
.. add FileMigrationProvider test suite. ..
- Loading branch information
1 parent
ccc2f0a
commit ca167d5
Showing
4 changed files
with
139 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { mkdir, readdir, rm, writeFile } from 'node:fs/promises' | ||
import { join } from 'node:path' | ||
import { require as tsxRequire } from 'tsx/cjs/api' | ||
import { FileMigrationProvider } from '../../..' | ||
import { expect } from './test-setup.js' | ||
|
||
describe('FileMigrationProvider', () => { | ||
;['js', 'ts', 'mjs', 'cjs', 'mts', 'cts'].forEach((extension) => { | ||
describe(`${extension} files`, () => { | ||
const migrationFolder = `${extension}-migrations` | ||
const migrationFolderPath = join(__dirname, migrationFolder) | ||
let provider: FileMigrationProvider | ||
const migrationName = '123_noop' | ||
|
||
before(async () => { | ||
await mkdir(migrationFolderPath) | ||
await writeFile( | ||
join(migrationFolderPath, `${migrationName}.${extension}`), | ||
extension.endsWith('js') | ||
? 'exports.up = () => {}' | ||
: 'export const up = () => {}', | ||
) | ||
|
||
provider = new FileMigrationProvider({ | ||
fs: { readdir }, | ||
import: | ||
extension.endsWith('ts') || extension.startsWith('m') | ||
? (module: string) => tsxRequire(module, __filename) | ||
: undefined, | ||
migrationFolder: migrationFolderPath, | ||
path: { join }, | ||
}) | ||
}) | ||
|
||
after(async () => { | ||
await rm(migrationFolderPath, { recursive: true }) | ||
}) | ||
|
||
it('should get migration files with this extension', async () => { | ||
const migrations = await provider.getMigrations() | ||
|
||
expect(migrations).to.have.property(migrationName) | ||
}) | ||
}) | ||
}) | ||
// | ||
;['zip', 'd.ts', 'd.mts', 'd.cts'].forEach((extension) => { | ||
describe(`${extension} files`, () => { | ||
const migrationFolder = `${extension}-migrations` | ||
const migrationFolderPath = join(__dirname, migrationFolder) | ||
let provider: FileMigrationProvider | ||
const migrationFileName = `123_noop.${extension}` | ||
let discarded: { fileName: string; reason: string }[] | ||
|
||
before(async () => { | ||
await mkdir(migrationFolderPath) | ||
await writeFile( | ||
join(migrationFolderPath, migrationFileName), | ||
extension.endsWith('ts') ? 'export {}' : '==asdhjgbaudg1827dg127', | ||
) | ||
discarded = [] | ||
|
||
provider = new FileMigrationProvider({ | ||
fs: { readdir }, | ||
migrationFolder: migrationFolderPath, | ||
onDiscarded: (fileName, reason) => { | ||
discarded.push({ fileName, reason }) | ||
}, | ||
path: { join }, | ||
}) | ||
}) | ||
|
||
after(async () => { | ||
await rm(migrationFolderPath, { recursive: true }) | ||
}) | ||
|
||
it('should discard files with this extension', async () => { | ||
const migrations = await provider.getMigrations() | ||
|
||
expect(migrations).to.deep.equal({}) | ||
expect(discarded).to.have.length(1) | ||
expect(discarded[0]).to.deep.equal({ | ||
fileName: migrationFileName, | ||
reason: 'Extension', | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
{"compilerOptions":{"target":"ES2022","lib":["ESNext"],"module":"CommonJS","outDir":"dist","skipLibCheck":true},"default":{"compilerOptions":{"target":"ES2022","lib":["ESNext"],"module":"CommonJS","outDir":"dist","skipLibCheck":true},"default":{"compilerOptions":{"target":"ES2022","lib":["ESNext"],"module":"CommonJS","outDir":"dist","skipLibCheck":true},"default":{"extends":"../../tsconfig-base.json","include":["src/**/*"],"compilerOptions":{"target":"ES2022","lib":["ESNext"],"module":"CommonJS","outDir":"dist","skipLibCheck":true}},"extends":"../../tsconfig-base.json","include":["src/**/*"],"exclude":["src/async-dispose.test.ts"]},"exclude":["src/async-dispose.test.ts"],"extends":"../../tsconfig-base.json","include":["src/**/*"]},"exclude":["src/async-dispose.test.ts","src/async-dispose.test.ts"],"extends":"../../tsconfig-base.json","include":["src/**/*"]} | ||
{ | ||
"extends": "../../tsconfig-base.json", | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"outDir": "dist", | ||
"moduleResolution": "NodeNext" | ||
} | ||
} |