From 79e9ae0fab1622f51a2cfa81036f85abde5c9a58 Mon Sep 17 00:00:00 2001 From: kononnable Date: Mon, 7 Sep 2020 00:12:48 +0200 Subject: [PATCH] add tests --- test/integration/runTestsFromPath.test.ts | 66 +++++++++++++++++++---- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/test/integration/runTestsFromPath.test.ts b/test/integration/runTestsFromPath.test.ts index c7f048d..1357cca 100644 --- a/test/integration/runTestsFromPath.test.ts +++ b/test/integration/runTestsFromPath.test.ts @@ -38,22 +38,55 @@ describe("TypeOrm examples", async () => { const testPartialPath = "test/integration/examples"; await runTestsFromPath(testPartialPath, false); }); +describe("Filtering tables", async () => { + const testPartialPath = "test/integration/examples"; + it("skipTables",async ()=>{ + const dbDrivers: string[] = GTU.getEnabledDbDrivers(); + const modelGenerationPromises = dbDrivers.map(async dbDriver => { + const { + generationOptions, + driver, + connectionOptions + } = await prepareTestRuns(testPartialPath, "sample2-one-to-one", dbDriver); + const dbModel = await dataCollectionPhase( + driver, + {...connectionOptions, + skipTables:["Post"]}, + generationOptions + ); + expect(dbModel.length).to.equal(6); + expect(dbModel.find(x=>x.sqlName==="Post")).to.be.undefined; + }); + await Promise.all(modelGenerationPromises); + }); + it("onlyTables",async ()=>{ + const dbDrivers: string[] = GTU.getEnabledDbDrivers(); + const modelGenerationPromises = dbDrivers.map(async dbDriver => { + const { + generationOptions, + driver, + connectionOptions + } = await prepareTestRuns(testPartialPath, "sample2-one-to-one", dbDriver); + const dbModel = await dataCollectionPhase( + driver, + {...connectionOptions, + onlyTables:["Post"]}, + generationOptions + ); + expect(dbModel.length).to.equal(1); + expect(dbModel.find(x=>x.sqlName==="Post")).to.not.be.undefined; + }); + await Promise.all(modelGenerationPromises); + }) + +}); async 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(); - dbDrivers.forEach(dbDriver => { - const newDirPath = path.resolve(resultsPath, dbDriver); - if (!fs.existsSync(newDirPath)) { - fs.mkdirSync(newDirPath); - } - }); + createOutputDirs(dbDrivers); const files = fs.readdirSync(path.resolve(process.cwd(), testPartialPath)); if (isDbSpecific) { await runTest(dbDrivers, testPartialPath, files); @@ -64,6 +97,19 @@ async function runTestsFromPath( } } +function createOutputDirs(dbDrivers: string[]) { + const resultsPath = path.resolve(process.cwd(), `output`); + if (!fs.existsSync(resultsPath)) { + fs.mkdirSync(resultsPath); + } + dbDrivers.forEach(dbDriver => { + const newDirPath = path.resolve(resultsPath, dbDriver); + if (!fs.existsSync(newDirPath)) { + fs.mkdirSync(newDirPath); + } + }); +} + function runTestForMultipleDrivers( testName: string, dbDrivers: string[],