-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support cjs extension for ormconfig (#6285)
* support cjs extension for ormconfig * fix linting errors * handle cjs extensions in class loader
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 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
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,36 @@ | ||
import {expect} from "chai"; | ||
import { writeFileSync, unlinkSync } from "fs"; | ||
import { ConnectionOptionsReader } from "../../../src/connection/ConnectionOptionsReader"; | ||
import { importClassesFromDirectories } from "../../../src/util/DirectoryExportedClassesLoader"; | ||
import { LoggerFactory } from "../../../src/logger/LoggerFactory"; | ||
|
||
describe("cli support for cjs extension", () => { | ||
it("will load a cjs file", async () => { | ||
const cjsConfigPath = [__dirname, "ormconfig.cjs"].join("/"); | ||
const databaseType = "postgres"; | ||
const config = `module.exports = {"type": "${databaseType}"};`; | ||
|
||
writeFileSync(cjsConfigPath, config); | ||
const reader = new ConnectionOptionsReader({root: __dirname }); | ||
|
||
const results = await reader.all(); | ||
expect(results).to.be.an("Array"); | ||
expect(results[0]).to.be.an("Object"); | ||
expect(results[0].type).to.equal(databaseType); | ||
|
||
|
||
unlinkSync(cjsConfigPath); | ||
}); | ||
|
||
it("loads cjs files via DirectoryExportedClassesloader", () => { | ||
const klassPath = [__dirname, "klass.cjs"].join("/"); | ||
const klass = `module.exports.Widget = class Widget {};`; | ||
writeFileSync(klassPath, klass); | ||
|
||
const classes = importClassesFromDirectories(new LoggerFactory().create(), [`${__dirname}/*.cjs`]); | ||
expect(classes).to.be.an("Array"); | ||
expect(classes.length).to.eq(1); | ||
|
||
unlinkSync(klassPath); | ||
}); | ||
}); |