From 99f3bfe3a32616c168f01d3d7df329f854ae7015 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 22 Jan 2019 22:35:51 +0100 Subject: [PATCH] tests optimization --- src/Engine.ts | 91 +++++++----- test/integration/defaultValues.test.ts | 68 --------- test/integration/entityTypes.test.ts | 68 --------- test/integration/githubIssues.test.ts | 90 ------------ test/integration/integration.test.ts | 72 ---------- test/integration/runTestsFromPath.test.ts | 165 ++++++++++++++++++++++ test/utils/GeneralTestUtils.ts | 6 + 7 files changed, 230 insertions(+), 330 deletions(-) delete mode 100644 test/integration/defaultValues.test.ts delete mode 100644 test/integration/entityTypes.test.ts delete mode 100644 test/integration/githubIssues.test.ts delete mode 100644 test/integration/integration.test.ts create mode 100644 test/integration/runTestsFromPath.test.ts diff --git a/src/Engine.ts b/src/Engine.ts index 8c7c879..3bf307a 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -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[] ) { diff --git a/test/integration/defaultValues.test.ts b/test/integration/defaultValues.test.ts deleted file mode 100644 index 6e4f06c..0000000 --- a/test/integration/defaultValues.test.ts +++ /dev/null @@ -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; - }); - } - } - } -}) diff --git a/test/integration/entityTypes.test.ts b/test/integration/entityTypes.test.ts deleted file mode 100644 index 4bf1134..0000000 --- a/test/integration/entityTypes.test.ts +++ /dev/null @@ -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; - }); - } - } - } -}) diff --git a/test/integration/githubIssues.test.ts b/test/integration/githubIssues.test.ts deleted file mode 100644 index dee14ae..0000000 --- a/test/integration/githubIssues.test.ts +++ /dev/null @@ -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; - }); - - } - }) - } -}) diff --git a/test/integration/integration.test.ts b/test/integration/integration.test.ts deleted file mode 100644 index 4710217..0000000 --- a/test/integration/integration.test.ts +++ /dev/null @@ -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; - }); - - } - }) - } -}) diff --git a/test/integration/runTestsFromPath.test.ts b/test/integration/runTestsFromPath.test.ts new file mode 100644 index 0000000..b3ae9d0 --- /dev/null +++ b/test/integration/runTestsFromPath.test.ts @@ -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 }; +} + diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 75ebb03..491add2 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -61,6 +61,7 @@ export async function createMSSQLModels(filesOrgPath: string): Promise