tests optimization
This commit is contained in:
parent
a27c336056
commit
99f3bfe3a3
@ -39,20 +39,7 @@ export async function createModelFromDatabase(
|
||||
connectionOptions: IConnectionOptions,
|
||||
generationOptions: IGenerationOptions
|
||||
) {
|
||||
function setRelationId(model: EntityInfo[]) {
|
||||
if (generationOptions.relationIds) {
|
||||
model.forEach(ent => {
|
||||
ent.Columns.forEach(col => {
|
||||
col.relations.map(rel => {
|
||||
rel.relationIdField = rel.isOwner;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
let dbModel = await driver.GetDataFromServer(connectionOptions);
|
||||
let dbModel = await dataCollectionPhase(driver, connectionOptions);
|
||||
if (dbModel.length === 0) {
|
||||
TomgUtils.LogError(
|
||||
"Tables not found in selected database. Skipping creation of typeorm model.",
|
||||
@ -60,11 +47,64 @@ export async function createModelFromDatabase(
|
||||
);
|
||||
return;
|
||||
}
|
||||
dbModel = setRelationId(dbModel);
|
||||
dbModel = ApplyNamingStrategy(generationOptions.namingStrategy, dbModel);
|
||||
createModelFromMetadata(connectionOptions, generationOptions, dbModel);
|
||||
dbModel = modelCustomizationPhase(dbModel, generationOptions);
|
||||
modelGenerationPhase(connectionOptions, generationOptions, dbModel);
|
||||
}
|
||||
function createModelFromMetadata(
|
||||
export async function dataCollectionPhase(
|
||||
driver: AbstractDriver,
|
||||
connectionOptions: IConnectionOptions
|
||||
) {
|
||||
return await driver.GetDataFromServer(connectionOptions);
|
||||
}
|
||||
|
||||
export function modelCustomizationPhase(
|
||||
dbModel: EntityInfo[],
|
||||
generationOptions: IGenerationOptions
|
||||
) {
|
||||
dbModel = setRelationId(generationOptions, dbModel);
|
||||
dbModel = applyNamingStrategy(generationOptions.namingStrategy, dbModel);
|
||||
dbModel = addImportsAndGenerationOptions(dbModel, generationOptions);
|
||||
return dbModel;
|
||||
}
|
||||
|
||||
function addImportsAndGenerationOptions(
|
||||
dbModel: EntityInfo[],
|
||||
generationOptions: IGenerationOptions
|
||||
) {
|
||||
dbModel.forEach(element => {
|
||||
element.Imports = [];
|
||||
element.Columns.forEach(column => {
|
||||
column.relations.forEach(relation => {
|
||||
if (element.tsEntityName !== relation.relatedTable) {
|
||||
element.Imports.push(relation.relatedTable);
|
||||
}
|
||||
});
|
||||
});
|
||||
element.GenerateConstructor = generationOptions.constructor;
|
||||
element.IsActiveRecord = generationOptions.activeRecord;
|
||||
element.Imports.filter((elem, index, self) => {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
});
|
||||
return dbModel;
|
||||
}
|
||||
|
||||
function setRelationId(
|
||||
generationOptions: IGenerationOptions,
|
||||
model: EntityInfo[]
|
||||
) {
|
||||
if (generationOptions.relationIds) {
|
||||
model.forEach(ent => {
|
||||
ent.Columns.forEach(col => {
|
||||
col.relations.map(rel => {
|
||||
rel.relationIdField = rel.isOwner;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
return model;
|
||||
}
|
||||
export function modelGenerationPhase(
|
||||
connectionOptions: IConnectionOptions,
|
||||
generationOptions: IGenerationOptions,
|
||||
databaseModel: EntityInfo[]
|
||||
@ -89,19 +129,6 @@ function createModelFromMetadata(
|
||||
noEscape: true
|
||||
});
|
||||
databaseModel.forEach(element => {
|
||||
element.Imports = [];
|
||||
element.Columns.forEach(column => {
|
||||
column.relations.forEach(relation => {
|
||||
if (element.tsEntityName !== relation.relatedTable) {
|
||||
element.Imports.push(relation.relatedTable);
|
||||
}
|
||||
});
|
||||
});
|
||||
element.GenerateConstructor = generationOptions.constructor;
|
||||
element.IsActiveRecord = generationOptions.activeRecord;
|
||||
element.Imports.filter((elem, index, self) => {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
let casedFileName = "";
|
||||
switch (generationOptions.convertCaseFile) {
|
||||
case "camel":
|
||||
@ -267,7 +294,7 @@ function createTypeOrmConfig(
|
||||
);
|
||||
}
|
||||
}
|
||||
function ApplyNamingStrategy(
|
||||
function applyNamingStrategy(
|
||||
namingStrategy: NamingStrategy,
|
||||
dbModel: EntityInfo[]
|
||||
) {
|
||||
|
@ -1,68 +0,0 @@
|
||||
require('dotenv').config()
|
||||
import { expect } from "chai";
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path')
|
||||
import "reflect-metadata";
|
||||
import { EntityFileToJson } from "../utils/EntityFileToJson";
|
||||
import chai = require('chai');
|
||||
import chaiSubset = require('chai-subset');
|
||||
import * as ts from "typescript";
|
||||
import { createDriver, createModelFromDatabase } from "../../src/Engine";
|
||||
import * as GTU from "../utils/GeneralTestUtils"
|
||||
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe("Column default values", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
|
||||
const dbDrivers: string[] = GTU.getEnabledDbDrivers();
|
||||
|
||||
const examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/defaultValues')
|
||||
const examplesPathTS = path.resolve(process.cwd(), 'test/integration/defaultValues')
|
||||
const files = fs.readdirSync(examplesPathTS)
|
||||
|
||||
for (const dbDriver of dbDrivers) {
|
||||
for (const folder of files) {
|
||||
if (dbDriver == folder) {
|
||||
it(dbDriver, async function () {
|
||||
|
||||
const filesOrgPathJS = path.resolve(examplesPathJS, folder, 'entity')
|
||||
const filesOrgPathTS = path.resolve(examplesPathTS, folder, 'entity')
|
||||
const resultsPath = path.resolve(process.cwd(), `output`)
|
||||
fs.removeSync(resultsPath)
|
||||
|
||||
const driver = createDriver(dbDriver);
|
||||
const connectionOptions = await GTU.createModelsInDb(dbDriver, filesOrgPathJS);
|
||||
const generationOptions = GTU.getGenerationOptions(resultsPath);
|
||||
|
||||
await createModelFromDatabase(driver,connectionOptions,generationOptions)
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities')
|
||||
|
||||
const filesOrg = fs.readdirSync(filesOrgPathTS).filter((val) => val.toString().endsWith('.ts'))
|
||||
const filesGen = fs.readdirSync(filesGenPath).filter((val) => val.toString().endsWith('.ts'))
|
||||
|
||||
expect(filesOrg, 'Errors detected in model comparision').to.be.deep.equal(filesGen)
|
||||
|
||||
for (const file of filesOrg) {
|
||||
const entftj = new EntityFileToJson();
|
||||
const jsonEntityOrg = entftj.convert(fs.readFileSync(path.resolve(filesOrgPathTS, file)))
|
||||
const jsonEntityGen = entftj.convert(fs.readFileSync(path.resolve(filesGenPath, file)))
|
||||
expect(jsonEntityGen, `Error in file ${file}`).to.containSubset(jsonEntityOrg)
|
||||
}
|
||||
const currentDirectoryFiles = fs.readdirSync(filesGenPath).
|
||||
filter(fileName => fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts").map(v => path.resolve(filesGenPath, v))
|
||||
const compileErrors = GTU.compileTsFiles(currentDirectoryFiles, {
|
||||
experimentalDecorators: true,
|
||||
sourceMap: false,
|
||||
emitDecoratorMetadata: true,
|
||||
target: ts.ScriptTarget.ES2016,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
expect(compileErrors, 'Errors detected while compiling generated model').to.be.false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
@ -1,68 +0,0 @@
|
||||
require('dotenv').config()
|
||||
import { expect } from "chai";
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path')
|
||||
import "reflect-metadata";
|
||||
import { EntityFileToJson } from "../utils/EntityFileToJson";
|
||||
import chai = require('chai');
|
||||
import chaiSubset = require('chai-subset');
|
||||
import * as ts from "typescript";
|
||||
import { createDriver, createModelFromDatabase } from "../../src/Engine";
|
||||
import * as GTU from "../utils/GeneralTestUtils"
|
||||
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe("Platform specyfic types", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
|
||||
const dbDrivers: string[] = GTU.getEnabledDbDrivers();
|
||||
|
||||
const examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/entityTypes')
|
||||
const examplesPathTS = path.resolve(process.cwd(), 'test/integration/entityTypes')
|
||||
const files = fs.readdirSync(examplesPathTS)
|
||||
|
||||
for (const dbDriver of dbDrivers) {
|
||||
for (const folder of files) {
|
||||
if (dbDriver == folder) {
|
||||
it(dbDriver, async function () {
|
||||
|
||||
const filesOrgPathJS = path.resolve(examplesPathJS, folder, 'entity')
|
||||
const filesOrgPathTS = path.resolve(examplesPathTS, folder, 'entity')
|
||||
const resultsPath = path.resolve(process.cwd(), `output`)
|
||||
fs.removeSync(resultsPath)
|
||||
|
||||
const driver = createDriver(dbDriver);
|
||||
const connectionOptions = await GTU.createModelsInDb(dbDriver, filesOrgPathJS);
|
||||
const generationOptions = GTU.getGenerationOptions(resultsPath);
|
||||
|
||||
await createModelFromDatabase(driver,connectionOptions,generationOptions)
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities')
|
||||
|
||||
const filesOrg = fs.readdirSync(filesOrgPathTS).filter((val) => val.toString().endsWith('.ts'))
|
||||
const filesGen = fs.readdirSync(filesGenPath).filter((val) => val.toString().endsWith('.ts'))
|
||||
|
||||
expect(filesOrg, 'Errors detected in model comparision').to.be.deep.equal(filesGen)
|
||||
|
||||
for (const file of filesOrg) {
|
||||
const entftj = new EntityFileToJson();
|
||||
const jsonEntityOrg = entftj.convert(fs.readFileSync(path.resolve(filesOrgPathTS, file)))
|
||||
const jsonEntityGen = entftj.convert(fs.readFileSync(path.resolve(filesGenPath, file)))
|
||||
expect(jsonEntityGen, `Error in file ${file}`).to.containSubset(jsonEntityOrg)
|
||||
}
|
||||
const currentDirectoryFiles = fs.readdirSync(filesGenPath).
|
||||
filter(fileName => fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts").map(v => path.resolve(filesGenPath, v))
|
||||
const compileErrors = GTU.compileTsFiles(currentDirectoryFiles, {
|
||||
experimentalDecorators: true,
|
||||
sourceMap: false,
|
||||
emitDecoratorMetadata: true,
|
||||
target: ts.ScriptTarget.ES2016,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
expect(compileErrors, 'Errors detected while compiling generated model').to.be.false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
@ -1,90 +0,0 @@
|
||||
require('dotenv').config()
|
||||
import { expect } from "chai";
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path')
|
||||
import "reflect-metadata";
|
||||
import { createModelFromDatabase, createDriver } from "../../src/Engine";
|
||||
import { EntityFileToJson } from "../utils/EntityFileToJson";
|
||||
import chai = require('chai');
|
||||
import chaiSubset = require('chai-subset');
|
||||
import * as ts from "typescript";
|
||||
import * as GTU from "../utils/GeneralTestUtils"
|
||||
|
||||
chai.use(chaiSubset);
|
||||
|
||||
|
||||
describe("GitHub issues", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
|
||||
const dbDrivers: string[] = GTU.getEnabledDbDrivers();
|
||||
|
||||
const examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/github-issues')
|
||||
const examplesPathTS = path.resolve(process.cwd(), 'test/integration/github-issues')
|
||||
const files = fs.readdirSync(examplesPathTS)
|
||||
|
||||
for (const folder of files) {
|
||||
|
||||
describe(`#${folder}`, async function () {
|
||||
for (const dbDriver of dbDrivers) {
|
||||
|
||||
switch (folder) {
|
||||
case '39':
|
||||
if (dbDriver == 'mysql' || dbDriver == 'mariadb' || dbDriver == 'oracle' || dbDriver == 'sqlite') {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
it(dbDriver, async function () {
|
||||
|
||||
const filesOrgPathJS = path.resolve(examplesPathJS, folder, 'entity')
|
||||
const filesOrgPathTS = path.resolve(examplesPathTS, folder, 'entity')
|
||||
const resultsPath = path.resolve(process.cwd(), `output`)
|
||||
fs.removeSync(resultsPath)
|
||||
|
||||
const driver = createDriver(dbDriver);
|
||||
const connectionOptions = await GTU.createModelsInDb(dbDriver, filesOrgPathJS);
|
||||
const generationOptions = GTU.getGenerationOptions(resultsPath);
|
||||
|
||||
switch (folder) {
|
||||
case '65':
|
||||
generationOptions.relationIds = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await createModelFromDatabase(driver,connectionOptions,generationOptions)
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities')
|
||||
|
||||
const filesOrg = fs.readdirSync(filesOrgPathTS).filter((val) => val.toString().endsWith('.ts'))
|
||||
const filesGen = fs.readdirSync(filesGenPath).filter((val) => val.toString().endsWith('.ts'))
|
||||
|
||||
expect(filesOrg, 'Errors detected in model comparision').to.be.deep.equal(filesGen)
|
||||
|
||||
for (const file of filesOrg) {
|
||||
const entftj = new EntityFileToJson();
|
||||
const jsonEntityOrg = entftj.convert(fs.readFileSync(path.resolve(filesOrgPathTS, file)))
|
||||
const jsonEntityGen = entftj.convert(fs.readFileSync(path.resolve(filesGenPath, file)))
|
||||
expect(jsonEntityGen, `Error in file ${file}`).to.containSubset(jsonEntityOrg)
|
||||
}
|
||||
const currentDirectoryFiles = fs.readdirSync(filesGenPath).
|
||||
filter(fileName => fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts").map(v => path.resolve(filesGenPath, v))
|
||||
const compileErrors = GTU.compileTsFiles(currentDirectoryFiles, {
|
||||
experimentalDecorators: true,
|
||||
sourceMap: false,
|
||||
emitDecoratorMetadata: true,
|
||||
target: ts.ScriptTarget.ES2016,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
expect(compileErrors, 'Errors detected while compiling generated model').to.be.false;
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
@ -1,72 +0,0 @@
|
||||
require('dotenv').config()
|
||||
import { expect } from "chai";
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path')
|
||||
import "reflect-metadata";
|
||||
import { createModelFromDatabase, createDriver } from "../../src/Engine";
|
||||
import { EntityFileToJson } from "../utils/EntityFileToJson";
|
||||
import chai = require('chai');
|
||||
import chaiSubset = require('chai-subset');
|
||||
import * as ts from "typescript";
|
||||
import * as GTU from "../utils/GeneralTestUtils"
|
||||
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe("TypeOrm examples", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
|
||||
const dbDrivers: string[] = GTU.getEnabledDbDrivers();
|
||||
|
||||
const examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/examples')
|
||||
const examplesPathTS = path.resolve(process.cwd(), 'test/integration/examples')
|
||||
const files = fs.readdirSync(examplesPathTS)
|
||||
|
||||
for (const folder of files) {
|
||||
describe(folder, async function () {
|
||||
for (const dbDriver of dbDrivers) {
|
||||
it(dbDriver, async function () {
|
||||
const filesOrgPathJS = path.resolve(examplesPathJS, folder, 'entity')
|
||||
const filesOrgPathTS = path.resolve(examplesPathTS, folder, 'entity')
|
||||
const resultsPath = path.resolve(process.cwd(), `output`)
|
||||
fs.removeSync(resultsPath)
|
||||
|
||||
const driver=createDriver(dbDriver);
|
||||
const connectionOptions = await GTU.createModelsInDb(dbDriver, filesOrgPathJS);
|
||||
const generationOptions = GTU.getGenerationOptions(resultsPath);
|
||||
|
||||
if (folder == 'sample18-lazy-relations') {
|
||||
generationOptions.lazy = true;
|
||||
}
|
||||
|
||||
await createModelFromDatabase(driver,connectionOptions,generationOptions)
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities')
|
||||
|
||||
const filesOrg = fs.readdirSync(filesOrgPathTS).filter((val) => val.toString().endsWith('.ts'))
|
||||
const filesGen = fs.readdirSync(filesGenPath).filter((val) => val.toString().endsWith('.ts'))
|
||||
|
||||
expect(filesOrg, 'Errors detected in model comparision').to.be.deep.equal(filesGen)
|
||||
|
||||
for (const file of filesOrg) {
|
||||
const entftj = new EntityFileToJson();
|
||||
const jsonEntityOrg = entftj.convert(fs.readFileSync(path.resolve(filesOrgPathTS, file)))
|
||||
const jsonEntityGen = entftj.convert(fs.readFileSync(path.resolve(filesGenPath, file)))
|
||||
expect(jsonEntityGen, `Error in file ${file}`).to.containSubset(jsonEntityOrg)
|
||||
}
|
||||
const currentDirectoryFiles = fs.readdirSync(filesGenPath).
|
||||
filter(fileName => fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts").map(v => path.resolve(filesGenPath, v))
|
||||
const compileErrors = GTU.compileTsFiles(currentDirectoryFiles, {
|
||||
experimentalDecorators: true,
|
||||
sourceMap: false,
|
||||
emitDecoratorMetadata: true,
|
||||
target: ts.ScriptTarget.ES2016,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
expect(compileErrors, 'Errors detected while compiling generated model').to.be.false;
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
165
test/integration/runTestsFromPath.test.ts
Normal file
165
test/integration/runTestsFromPath.test.ts
Normal file
@ -0,0 +1,165 @@
|
||||
require('dotenv').config()
|
||||
import "reflect-metadata";
|
||||
import { expect } from "chai";
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path');
|
||||
import { EntityFileToJson } from "../utils/EntityFileToJson";
|
||||
import { createDriver, createModelFromDatabase, dataCollectionPhase, modelCustomizationPhase, modelGenerationPhase } from "../../src/Engine";
|
||||
import * as ts from "typescript";
|
||||
import * as GTU from "../utils/GeneralTestUtils"
|
||||
import chaiSubset = require('chai-subset');
|
||||
import chai = require('chai');
|
||||
|
||||
chai.use(chaiSubset);
|
||||
|
||||
describe("Column default values", async function () {
|
||||
const testPartialPath = 'test/integration/defaultValues'
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
runTestsFromPath(testPartialPath, true);
|
||||
})
|
||||
describe("Platform specyfic types", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
const testPartialPath = 'test/integration/entityTypes'
|
||||
runTestsFromPath(testPartialPath, true);
|
||||
})
|
||||
describe("GitHub issues", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
const testPartialPath = 'test/integration/github-issues'
|
||||
runTestsFromPath(testPartialPath, false);
|
||||
})
|
||||
describe("TypeOrm examples", async function () {
|
||||
this.timeout(30000)
|
||||
this.slow(5000)// compiling created models takes time
|
||||
const testPartialPath = 'test/integration/examples'
|
||||
runTestsFromPath(testPartialPath, false);
|
||||
})
|
||||
|
||||
export function runTestsFromPath(testPartialPath: string, isDbSpecific: boolean) {
|
||||
const resultsPath = path.resolve(process.cwd(), `output`)
|
||||
if (!fs.existsSync(resultsPath)) {
|
||||
fs.mkdirSync(resultsPath);
|
||||
}
|
||||
const dbDrivers: string[] = GTU.getEnabledDbDrivers();
|
||||
for (const dbDriver of dbDrivers) {
|
||||
const newDirPath = path.resolve(resultsPath, dbDriver)
|
||||
if (!fs.existsSync(newDirPath)) {
|
||||
fs.mkdirSync(newDirPath);
|
||||
}
|
||||
}
|
||||
const files = fs.readdirSync(path.resolve(process.cwd(), testPartialPath));
|
||||
if (isDbSpecific) {
|
||||
for (const dbDriver of dbDrivers) {
|
||||
for (const folder of files) {
|
||||
if (dbDriver == folder) {
|
||||
runTest(dbDriver, testPartialPath, folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const folder of files) {
|
||||
runTestForMultipleDrivers(folder, dbDrivers, testPartialPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
function runTestForMultipleDrivers(testName: string, dbDrivers: string[], testPartialPath: string) {
|
||||
it(testName, async function () {
|
||||
const driversToRun = selectDriversForSpecyficTest();
|
||||
const modelGenerationPromises = driversToRun.map(async (dbDriver) => {
|
||||
const { generationOptions, driver, connectionOptions, resultsPath, filesOrgPathTS } = await prepareTestRuns(testPartialPath, testName, dbDriver);
|
||||
let dbModel = await dataCollectionPhase(driver, connectionOptions);
|
||||
dbModel = modelCustomizationPhase(dbModel, generationOptions);
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities');
|
||||
modelGenerationPhase(connectionOptions, generationOptions, dbModel);
|
||||
compareGeneratedFiles(filesOrgPathTS, filesGenPath);
|
||||
compileGeneratedModel(filesGenPath);
|
||||
return { dbModel, generationOptions, connectionOptions, resultsPath, filesOrgPathTS, dbDriver };
|
||||
})
|
||||
///TODO: Find first generated result and compile, compare only it
|
||||
// Then when all db drivers finished compare only generated dbModels to the first one
|
||||
|
||||
|
||||
//const firstResult = await Promise.race(modelGenerationPromises);
|
||||
const generatedData = await Promise.all(modelGenerationPromises)
|
||||
// for (const iterator of generatedData) {
|
||||
|
||||
// const filesGenPath = path.resolve(iterator.resultsPath, 'entities');
|
||||
// modelGenerationPhase(iterator.connectionOptions, iterator.generationOptions, iterator.dbModel);
|
||||
// // compareGeneratedFiles(iterator.filesOrgPathTS, filesGenPath);
|
||||
// // compileGeneratedModel(filesGenPath);
|
||||
// }
|
||||
// //expect(generatedData[1].dbModel).to.be.deep.eq(generatedData[2].dbModel, `Gennerated models differ for ${generatedData[1].dbDriver} and ${generatedData[2].dbDriver} `)
|
||||
// for (const driverResult of generatedData) {
|
||||
// expect(firstResult.dbModel).to.be.deep.eq(driverResult.dbModel, `Gennerated models differ for ${firstResult.dbDriver} and ${driverResult.dbDriver} `)
|
||||
// }
|
||||
});
|
||||
|
||||
function selectDriversForSpecyficTest() {
|
||||
switch (testName) {
|
||||
case '39':
|
||||
return dbDrivers.filter(dbDriver => !['mysql', 'mariadb', 'oracle', 'sqlite'].includes(dbDriver))
|
||||
default:
|
||||
return dbDrivers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runTest(dbDriver: string, testPartialPath: string, testName: string) {
|
||||
it(dbDriver, async function () {
|
||||
const { generationOptions, driver, connectionOptions, resultsPath, filesOrgPathTS } = await prepareTestRuns(testPartialPath, testName, dbDriver);
|
||||
await createModelFromDatabase(driver, connectionOptions, generationOptions);
|
||||
const filesGenPath = path.resolve(resultsPath, 'entities');
|
||||
compareGeneratedFiles(filesOrgPathTS, filesGenPath);
|
||||
compileGeneratedModel(filesGenPath);
|
||||
});
|
||||
}
|
||||
|
||||
function compareGeneratedFiles(filesOrgPathTS: string, filesGenPath: string) {
|
||||
const filesOrg = fs.readdirSync(filesOrgPathTS).filter((val) => val.toString().endsWith('.ts'));
|
||||
const filesGen = fs.readdirSync(filesGenPath).filter((val) => val.toString().endsWith('.ts'));
|
||||
expect(filesOrg, 'Errors detected in model comparision').to.be.deep.equal(filesGen);
|
||||
for (const file of filesOrg) {
|
||||
const entftj = new EntityFileToJson();
|
||||
const jsonEntityOrg = entftj.convert(fs.readFileSync(path.resolve(filesOrgPathTS, file)));
|
||||
const jsonEntityGen = entftj.convert(fs.readFileSync(path.resolve(filesGenPath, file)));
|
||||
expect(jsonEntityGen, `Error in file ${file}`).to.containSubset(jsonEntityOrg);
|
||||
}
|
||||
}
|
||||
|
||||
function compileGeneratedModel(filesGenPath: string) {
|
||||
const currentDirectoryFiles = fs.readdirSync(filesGenPath).
|
||||
filter(fileName => fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts").map(v => path.resolve(filesGenPath, v));
|
||||
const compileErrors = GTU.compileTsFiles(currentDirectoryFiles, {
|
||||
experimentalDecorators: true,
|
||||
sourceMap: false,
|
||||
emitDecoratorMetadata: true,
|
||||
target: ts.ScriptTarget.ES2016,
|
||||
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
});
|
||||
expect(compileErrors, 'Errors detected while compiling generated model').to.be.false;
|
||||
}
|
||||
|
||||
async function prepareTestRuns(testPartialPath: string, testName: string, dbDriver: string) {
|
||||
const filesOrgPathJS = path.resolve(process.cwd(), 'dist', testPartialPath, testName, 'entity');
|
||||
const filesOrgPathTS = path.resolve(process.cwd(), testPartialPath, testName, 'entity');
|
||||
const resultsPath = path.resolve(process.cwd(), `output`, dbDriver);
|
||||
fs.removeSync(resultsPath);
|
||||
const driver = createDriver(dbDriver);
|
||||
const connectionOptions = await GTU.createModelsInDb(dbDriver, filesOrgPathJS);
|
||||
const generationOptions = GTU.getGenerationOptions(resultsPath);
|
||||
switch (testName) {
|
||||
case '65':
|
||||
generationOptions.relationIds = true;
|
||||
break;
|
||||
case 'sample18-lazy-relations':
|
||||
generationOptions.lazy = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return { generationOptions, driver, connectionOptions, resultsPath, filesOrgPathTS };
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ export async function createMSSQLModels(filesOrgPath: string): Promise<IConnecti
|
||||
dropSchema: true,
|
||||
synchronize: false,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'mssql'
|
||||
}
|
||||
|
||||
const schemas = 'dbo,sch1,sch2'
|
||||
@ -110,6 +111,7 @@ export async function createPostgresModels(filesOrgPath: string): Promise<IConne
|
||||
dropSchema: true,
|
||||
synchronize: false,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'postgres'
|
||||
}
|
||||
|
||||
const schemas = 'public,sch1,sch2'
|
||||
@ -154,6 +156,7 @@ export async function createSQLiteModels(filesOrgPath: string): Promise<IConnect
|
||||
dropSchema: true,
|
||||
synchronize: false,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'sqlite'
|
||||
}
|
||||
|
||||
let conn = await createConnection(connOpt)
|
||||
@ -197,6 +200,7 @@ export async function createMysqlModels(filesOrgPath: string): Promise<IConnecti
|
||||
dropSchema: true,
|
||||
synchronize: true,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'mysql'
|
||||
}
|
||||
const conn = await createConnection(connOpt)
|
||||
|
||||
@ -237,6 +241,7 @@ export async function createMariaDBModels(filesOrgPath: string): Promise<IConnec
|
||||
dropSchema: true,
|
||||
synchronize: true,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'mariadb'
|
||||
}
|
||||
const conn = await createConnection(connOpt)
|
||||
|
||||
@ -281,6 +286,7 @@ export async function createOracleDBModels(filesOrgPath: string): Promise<IConne
|
||||
port: Number(process.env.ORACLE_Port),
|
||||
synchronize: true,
|
||||
entities: [path.resolve(filesOrgPath, '*.js')],
|
||||
name: 'oracle',
|
||||
}
|
||||
const conn = await createConnection(connOpt)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user