integration test step 2 - not completed yet
This commit is contained in:
parent
7b163dbd41
commit
c567ee0546
@ -32,16 +32,17 @@
|
||||
"devDependencies": {
|
||||
"@types/chai": "^3.5.2",
|
||||
"@types/chai-as-promised": "0.0.30",
|
||||
"@types/fs-extra": "^3.0.0",
|
||||
"@types/mocha": "^2.2.41",
|
||||
"@types/mock-fs": "^3.6.30",
|
||||
"@types/mssql": "^3.3.0",
|
||||
"@types/node": "^7.0.10",
|
||||
"@types/sinon": "^2.1.3",
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^6.0.0",
|
||||
"codecov": "^2.1.0",
|
||||
"fs-extra": "^3.0.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.3.0",
|
||||
"mock-fs": "^4.3.0",
|
||||
"remap-istanbul": "^0.9.5",
|
||||
"sinon": "^2.2.0",
|
||||
"sinon-chai": "^2.10.0",
|
||||
|
@ -25,9 +25,9 @@ export class Engine {
|
||||
|
||||
}
|
||||
private createModelFromMetadata(databaseModel: DatabaseModel) {
|
||||
let templatePath = path.resolve(__dirname, 'entity.mst')
|
||||
let templatePath = path.resolve(process.cwd(), 'src/entity.mst')
|
||||
let template = fs.readFileSync(templatePath, 'UTF-8');
|
||||
let resultPath = path.resolve(__dirname, '../'+this.Options.resultsPath)
|
||||
let resultPath = this.Options.resultsPath
|
||||
if (!fs.existsSync(resultPath))
|
||||
fs.mkdirSync(resultPath);
|
||||
this.createTsConfigFile(resultPath)
|
||||
|
@ -3,6 +3,7 @@ import * as Mustache from 'mustache'
|
||||
import { Engine } from './Engine'
|
||||
import * as Yargs from 'yargs'
|
||||
import { AbstractDriver } from "./drivers/AbstractDriver";
|
||||
import path = require('path')
|
||||
// var x = Mustache.render("{{a}}", { a: 'test' });
|
||||
// console.log(x);
|
||||
|
||||
@ -43,7 +44,7 @@ var argv = Yargs
|
||||
.option('o', {
|
||||
alias: 'output',
|
||||
describe: 'Where to place generated models.',
|
||||
default: './output'
|
||||
default: path.resolve(process.cwd(),'output')
|
||||
})
|
||||
.argv;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {Column, Entity,PrimaryColumn,Index} from "typeorm";
|
||||
|
||||
@Entity("sample01_post")
|
||||
@Entity()
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn("int", { generated: true })
|
||||
|
@ -1,85 +1,77 @@
|
||||
import "reflect-metadata";
|
||||
import { createConnection, ConnectionOptions, Connection } from "typeorm";
|
||||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "./../utils/test-utils"
|
||||
import fs = require('fs');
|
||||
import { setupSingleTestingConnection, closeTestingConnections, reloadTestingDatabases } from "./../utils/test-utils"
|
||||
import fs = require('fs-extra');
|
||||
import path = require('path')
|
||||
import { Post } from "./examples/sample1-simple-entity/entity/Post";
|
||||
import * as mockFS from "mock-fs";
|
||||
import { Engine } from "./../../src/Engine";
|
||||
import { AbstractDriver } from "./../../src/drivers/AbstractDriver";
|
||||
import { MssqlDriver } from "./../../src/drivers/MssqlDriver";
|
||||
import { DriverType } from "typeorm/driver/DriverOptions";
|
||||
import { expect } from "chai";
|
||||
import * as Sinon from 'sinon'
|
||||
|
||||
describe("integration tests", function () {
|
||||
let connections: Connection[];
|
||||
|
||||
describe('should ...', async () => {
|
||||
let examplesPath = path.resolve(__dirname, 'examples')
|
||||
describe("integration tests", async function () {
|
||||
let examplesPath = path.resolve(process.cwd(), 'test/integration/examples')
|
||||
let files = fs.readdirSync(examplesPath)
|
||||
// console.log(files)
|
||||
files.forEach(folder => {
|
||||
it(folder, async () => {
|
||||
connections = await createTestingConnections({
|
||||
|
||||
let dbDrivers:[DriverType]=['mssql']
|
||||
|
||||
for( let folder of files){
|
||||
// files.forEach( async folder => {
|
||||
|
||||
describe(folder, async function () {
|
||||
|
||||
for (let dbDriver of dbDrivers){
|
||||
it(dbDriver,async function() {
|
||||
let connOpt =await setupSingleTestingConnection(<any>dbDriver,{
|
||||
entities: [Post],
|
||||
schemaCreate: true,
|
||||
})
|
||||
await connections.forEach(async conn => {
|
||||
let conn = await createConnection(connOpt)
|
||||
await conn.entityManager.query(`select 'TODO'`)//depends on driver - remove tables
|
||||
if (conn.isConnected)
|
||||
await conn.close()
|
||||
|
||||
// conn.s
|
||||
console.log('aa')
|
||||
//TODO get model from db
|
||||
await conn.entityManager.query(`select 'TODO'`)//depends on driver - remove tables
|
||||
//compare models
|
||||
if (conn.isConnected)
|
||||
await conn.close()
|
||||
let q=conn.isConnected
|
||||
console.log(q)
|
||||
let driver: AbstractDriver;
|
||||
driver = new MssqlDriver();
|
||||
let standardPort = 1433;
|
||||
|
||||
let resultsPath= path.resolve(process.cwd(),`output`)
|
||||
let engine = new Engine(
|
||||
driver, {
|
||||
//TODO:get data from env
|
||||
host: 'localhost',
|
||||
port: standardPort,
|
||||
databaseName: 'test',
|
||||
user: 'sa',
|
||||
password: 'password',
|
||||
databaseType: 'mssql',
|
||||
resultsPath: resultsPath
|
||||
});
|
||||
fs.removeSync(resultsPath)
|
||||
|
||||
|
||||
let resultPath = path.resolve(__dirname, '../model')
|
||||
mockFS({ resultPath: {} })
|
||||
let result = await engine.createModelFromDatabase()
|
||||
|
||||
//TODO:Compare reslts
|
||||
let filesOrgPath=path.resolve(examplesPath,folder,'entity')
|
||||
let filesGenPath=path.resolve(resultsPath,'entities')
|
||||
|
||||
let filesOrg = fs.readdirSync(filesOrgPath).map(function(this,val){return val.toString().toLowerCase();}).filter( function(this,val,ind,arr){return val.toString().endsWith('.ts')})
|
||||
let filesGen = fs.readdirSync(filesGenPath).map(function(this,val){return val.toString().toLowerCase();}).filter( function(this,val,ind,arr){return val.toString().endsWith('.ts')})
|
||||
|
||||
expect(filesOrg).to.be.deep.equal(filesGen)
|
||||
|
||||
var driver: AbstractDriver;
|
||||
|
||||
driver = new MssqlDriver();
|
||||
let standardPort = 1433;
|
||||
|
||||
let engine = new Engine(
|
||||
driver, {
|
||||
host: 'localhost',
|
||||
port: standardPort,
|
||||
databaseName: 'test',
|
||||
user: 'sa',
|
||||
password: 'password',
|
||||
databaseType: 'mssql',
|
||||
resultsPath: `test/model`
|
||||
});
|
||||
|
||||
|
||||
let result = await engine.createModelFromDatabase()
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
// describe("sample1", async function () {
|
||||
// connections = await createTestingConnections({
|
||||
// //entities: [Post],
|
||||
// schemaCreate: false,
|
||||
// })
|
||||
// await connections.forEach( async conn => {
|
||||
// await conn.syncSchema()
|
||||
// conn.entityManager.query('TODO')//depends on
|
||||
// });
|
||||
// closeTestingConnections(connections)
|
||||
|
||||
// //foreach driver
|
||||
// //create model from db
|
||||
// //compare models
|
||||
|
||||
// })
|
||||
for(let file of filesOrg){
|
||||
|
||||
expect(fs.readFileSync(path.resolve(filesOrgPath,file)).toString()).to.be.eq(fs.readFileSync(path.resolve(filesGenPath,file)).toString())
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
})}
|
||||
})
|
Loading…
Reference in New Issue
Block a user