diff --git a/.cz.json b/.cz.json deleted file mode 100644 index d32f3fc5..00000000 --- a/.cz.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "path": "node_modules/cz-conventional-changelog/" -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a1c17649..c2bc143a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,15 @@ language: node_js +env: + - CXX=g++-4.8 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 node_js: - - "iojs" - "4.0.0" + - "5.3.0" sudo: false install: - npm install diff --git a/package.json b/package.json index 2d3fdb73..83f55970 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,10 @@ "author": "adonisjs", "license": "MIT", "devDependencies": { + "adonis-fold": "^2.0.0", "chai": "^3.2.0", "co": "^4.6.0", "coveralls": "^2.11.4", - "cz-conventional-changelog": "^1.1.2", "fs-extra": "^0.26.3", "istanbul": "^0.3.20", "loadtest": "^1.2.14", @@ -25,7 +25,7 @@ "standard": "^5.4.1" }, "peerDependencies": { - "adonis-fold": "^1.0.0" + "adonis-fold": "^2.0.0" }, "dependencies": { "auto-loader": "^0.2.0", diff --git a/providers/SchemaProvider.js b/providers/SchemaProvider.js index 4d541864..86afb4b5 100644 --- a/providers/SchemaProvider.js +++ b/providers/SchemaProvider.js @@ -15,24 +15,16 @@ class SchemaProvider extends ServiceProvider { return require('../src/Schema') }) - this.app.bind('Adonis/Commands/Make', function (app) { - const Helpers = app.use('Adonis/Src/Helpers') - const Make = require('../src/Commands/Make') - return new Make(Helpers) + this.app.bind('Adonis/Commands/Make', function () { + return require('../src/Commands/Make') }) - this.app.bind('Adonis/Commands/Run', function (app) { - const Helpers = app.use('Adonis/Src/Helpers') - const Runner = app.use('Adonis/Src/Runner') - const Run = require('../src/Commands/Run') - return new Run(Helpers, Runner) + this.app.bind('Adonis/Commands/Run', function () { + return require('../src/Commands/Run') }) - this.app.bind('Adonis/Commands/Rollback', function (app) { - const Helpers = app.use('Adonis/Src/Helpers') - const Runner = app.use('Adonis/Src/Runner') - const Rollback = require('../src/Commands/Rollback') - return new Rollback(Helpers, Runner) + this.app.bind('Adonis/Commands/Rollback', function () { + return require('../src/Commands/Rollback') }) } diff --git a/src/Commands/Make.js b/src/Commands/Make.js index 68ac7777..2f24d5f9 100644 --- a/src/Commands/Make.js +++ b/src/Commands/Make.js @@ -6,6 +6,9 @@ * MIT Licensed */ +const fs = require('fs') +const Ioc = require('adonis-fold').Ioc + const migrationContent = ` 'use strict' @@ -24,57 +27,45 @@ class NewSchema extends Schema { module.exports = NewSchema ` -const fs = require('fs') - -class Make { - - constructor (Helpers) { - this.helpers = Helpers - } - - /** - * @description returns command description - * @method description - * @return {String} - * @public - */ - description () { - return 'Create a new migration file' - } - - /** - * @description command signature to define expectation for - * a given command to ace - * @method signature - * @return {String} - * @public - */ - signature () { - return '{name}' - } +let Make = exports = module.exports = {} - /** - * @description creates a new migration file - * @method handle - * @param {Object} options - * @param {Object} flags - * @return {Object} - * @public - */ - handle (options) { - return new Promise((resolve, reject) => { - const name = `${new Date().getTime()}_${options.name}.js` - const migrationPath = this.helpers.migrationsPath(name) +Make.description = 'Create a new migration file' +Make.signature = '{name}' - fs.writeFile(migrationPath, migrationContent, function (error) { - if (error) { - reject(error) - } else { - resolve(`Created ${name} migration successfully`) - } - }) +/** + * @description writes file with content to a given path + * @method writeFile + * @param {String} migrationPath + * @param {String} migrationContent + * @return {Object} + * @public + */ +Make.writeFile = function (migrationPath, migrationContent) { + return new Promise((resolve, reject) => { + fs.writeFile(migrationPath, migrationContent, function (error) { + if (error) { + return reject(error) + } + resolve() }) - } + }) } -module.exports = Make +/** + * @description creates a new migration file + * @method handle + * @param {Object} options + * @param {Object} flags + * @return {Object} + * @public + */ +Make.handle = function * (options) { + const helpers = Ioc.make('Adonis/Src/Helpers') + const Console = Ioc.use('Adonis/Src/Console') + + const name = `${new Date().getTime()}_${options.name}.js` + const migrationPath = helpers.migrationsPath(name) + + yield Make.writeFile(migrationPath, migrationContent) + Console.success(Console.icon('success') + ' created %s migration successfully', name) +} diff --git a/src/Commands/Rollback.js b/src/Commands/Rollback.js index 93761ee3..a3b9a3ab 100644 --- a/src/Commands/Rollback.js +++ b/src/Commands/Rollback.js @@ -7,52 +7,39 @@ */ const autoLoader = require('auto-loader') +const Ioc = require('adonis-fold').Ioc -class Rollback { +let Rollback = exports = module.exports = {} - constructor (Helpers, Runner) { - this.migrations = Helpers.migrationsPath() - this.runner = Runner - } +Rollback.description = 'Rollback migrations executed in last batch' +Rollback.signature = '{--force?}' - /** - * @description returns command description - * @method description - * @return {String} - * @public - */ - description () { - return 'Rollback migrations executed in last batch' +/** + * @description rollback all migrations using + * runner provider + * @method handle + * @param {Object} options + * @param {Object} flags + * @return {Object} + * @public + */ +Rollback.handle = function * (options, flags) { + const Helpers = Ioc.make('Adonis/Src/Helpers') + const Runner = Ioc.make('Adonis/Src/Runner') + const Console = Ioc.use('Adonis/Src/Console') + const migrations = Helpers.migrationsPath() + + if (process.env.NODE_ENV === 'production' && !flags.force) { + throw new Error('Cannot run migrations in production') } + const migrationsFiles = autoLoader.load(migrations) + const response = yield Runner.down(migrationsFiles) - /** - * @description command signature to define expectation for - * a given command to ace - * @method signature - * @return {String} - * @public - */ - signature () { - return '{--force?}' + if (response.status === 'completed') { + Console.success(Console.icon('success') + ' latest migrations batch has been rolled back') } - /** - * @description rollback all migrations using - * runner provider - * @method handle - * @param {Object} options - * @param {Object} flags - * @return {Object} - * @public - */ - * handle (options, flags) { - if (process.env.NODE_ENV === 'production' && !flags.force) { - throw new Error('Cannot run migrations in production') - } - const migrationsFiles = autoLoader.load(this.migrations) - return yield this.runner.down(migrationsFiles) + if (response.status === 'skipped') { + Console.info(Console.icon('info') + ' already at the last batch') } - } - -module.exports = Rollback diff --git a/src/Commands/Run.js b/src/Commands/Run.js index 41872e1b..a2420d73 100644 --- a/src/Commands/Run.js +++ b/src/Commands/Run.js @@ -7,52 +7,39 @@ */ const autoLoader = require('auto-loader') +const Ioc = require('adonis-fold').Ioc -class Run { +let Run = exports = module.exports = {} - constructor (Helpers, Runner) { - this.migrations = Helpers.migrationsPath() - this.runner = Runner - } +Run.description = 'Run latest migrations' +Run.signature = '{--force?}' - /** - * @description returns command description - * @method description - * @return {String} - * @public - */ - description () { - return 'Run latest migrations' +/** + * @description rollback all migrations using + * runner provider + * @method handle + * @param {Object} options + * @param {Object} flags + * @return {Object} + * @public + */ +Run.handle = function * (options, flags) { + const Helpers = Ioc.make('Adonis/Src/Helpers') + const Runner = Ioc.make('Adonis/Src/Runner') + const Console = Ioc.use('Adonis/Src/Console') + const migrations = Helpers.migrationsPath() + + if (process.env.NODE_ENV === 'production' && !flags.force) { + throw new Error('Cannot run migrations in production') } + const migrationsFiles = autoLoader.load(migrations) + const response = yield Runner.up(migrationsFiles) - /** - * @description command signature to define expectation for - * a given command to ace - * @method signature - * @return {String} - * @public - */ - signature () { - return '{--force?}' + if (response.status === 'completed') { + Console.success(Console.icon('success') + ' database migrated successfully') } - /** - * @description migrate all migrations using runner - * provider - * @method handle - * @param {Object} options - * @param {Object} flags - * @return {Object} - * @public - */ - * handle (options, flags) { - if (process.env.NODE_ENV === 'production' && !flags.force) { - throw new Error('Cannot run migrations in production') - } - const migrationsFiles = autoLoader.load(this.migrations) - return yield this.runner.up(migrationsFiles) + if (response.status === 'skipped') { + Console.info(Console.icon('info') + ' already the latest version') } - } - -module.exports = Run diff --git a/src/Runner/index.js b/src/Runner/index.js index 46666174..eefd441b 100644 --- a/src/Runner/index.js +++ b/src/Runner/index.js @@ -14,9 +14,10 @@ const log = new CatLog('adonis:lucid') class Runner { constructor (Config) { - const config = Config.get('database.connection') + const connection = Config.get('database.connection') + const config = Config.get(`database.${connection}`) this.knex = require('knex')(config) - this.migrationsTable = Config.get('database.migrationsTable') + this.migrationsTable = Config.get('database.migrationsTable', 'adonis_schema') this.lockTable = `${this.migrationsTable}_lock` this.migrations = [] } @@ -322,6 +323,7 @@ class Runner { return '' }) .then((response) => { + this.knex.destroy() const status = _.size(migrated) > 0 ? 'completed' : 'skipped' resolve({migrated, status}) }) @@ -347,6 +349,7 @@ class Runner { } }) .then((response) => { + this.knex.destroy() const status = _.size(migrated) > 0 ? 'completed' : 'skipped' resolve({migrated, status}) }) diff --git a/test/implementation/model-relations.spec.js b/test/implementation/model-relations.spec.js index 5c92c9b0..a72f01c9 100644 --- a/test/implementation/model-relations.spec.js +++ b/test/implementation/model-relations.spec.js @@ -5,6 +5,7 @@ const chai = require('chai') const expect = chai.expect const co = require('co') const Database = require('../../src/Database') +const manageDb = require('../unit/blueprints/manage') const blueprint = require('./blueprints/model-blueprint') const Model = require('../../src/Orm/Proxy/Model') const Ioc = require('adonis-fold').Ioc @@ -55,16 +56,23 @@ Ioc.bind('App/Model/User', function () { describe('Database Implementation', function () { before(function (done) { - blueprint - .setup(db) - .then (function () { - done() - }).catch(done) + manageDb + .make(path.join(__dirname, './storage/blog.sqlite3')) + .then(function () { + return blueprint.setup(db) + }) + .then (function () { + done() + }) + .catch(done) }) after(function (done) { blueprint .tearDown(db) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/blog.sqlite3')) + }) .then (function () { done() }).catch(done) diff --git a/test/implementation/model.spec.js b/test/implementation/model.spec.js index 1c798ade..b666b929 100644 --- a/test/implementation/model.spec.js +++ b/test/implementation/model.spec.js @@ -4,6 +4,7 @@ const path = require('path') const chai = require('chai') const expect = chai.expect const Database = require('../../src/Database') +const manageDb = require('../unit/blueprints/manage') const blueprint = require('./blueprints/model-blueprint') const Model = require('../../src/Orm/Proxy/Model') @@ -15,7 +16,7 @@ let Config = { return { client: 'sqlite3', connection: { - filename: path.join(__dirname,'./storage/blog.sqlite3') + filename: path.join(__dirname,'./storage/model.sqlite3') }, debug: false } @@ -49,19 +50,27 @@ let postId = null describe('Database Implementation', function () { before(function (done) { - blueprint - .setup(db) - .then (function () { - done() - }).catch(done) + manageDb + .make(path.join(__dirname, './storage/model.sqlite3')) + .then(function () { + return blueprint.setup(db) + }) + .then (function () { + done() + }) + .catch(done) }) after(function (done) { blueprint - .tearDown(db) - .then (function () { - done() - }).catch(done) + .tearDown(db) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/model.sqlite3')) + }) + .then (function () { + done() + }) + .catch(done) }) diff --git a/test/unit/storage/blog.sqlite3 b/test/implementation/storage/.gitkeep similarity index 100% rename from test/unit/storage/blog.sqlite3 rename to test/implementation/storage/.gitkeep diff --git a/test/implementation/storage/blog.sqlite3 b/test/implementation/storage/blog.sqlite3 deleted file mode 100644 index 3d588eb0..00000000 Binary files a/test/implementation/storage/blog.sqlite3 and /dev/null differ diff --git a/test/unit/blueprints/manage.js b/test/unit/blueprints/manage.js new file mode 100644 index 00000000..038d992a --- /dev/null +++ b/test/unit/blueprints/manage.js @@ -0,0 +1,34 @@ +'use strict' + +/** + * adonis-lucid + * Copyright(c) 2015-2015 Harminder Virk + * MIT Licensed +*/ +const fs = require('fs-extra') +module.exports = { + make: function (file) { + return new Promise(function (resolve, reject) { + fs.ensureFile(file, function (error) { + if(error) { + reject(error) + } + else { + resolve() + } + }) + }) + }, + remove: function (file) { + return new Promise(function (resolve, reject) { + fs.remove(file, function (error) { + if(error) { + reject(error) + } + else { + resolve() + } + }) + }) + } +} diff --git a/test/unit/blueprints/model-relations-blueprint.js b/test/unit/blueprints/model-relations-blueprint.js index 0f28b661..2f9835f6 100644 --- a/test/unit/blueprints/model-relations-blueprint.js +++ b/test/unit/blueprints/model-relations-blueprint.js @@ -5,7 +5,7 @@ const Q = require('q') let blueprint = exports = module.exports = {} blueprint.tearDown = function(knex) { - return Q.all([ + const tablesToRemove = [ knex.schema.dropTable('users'), knex.schema.dropTable('phones'), knex.schema.dropTable('authors'), @@ -17,12 +17,19 @@ blueprint.tearDown = function(knex) { knex.schema.dropTable('chat_operators'), knex.schema.dropTable('relation_table'), knex.schema.dropTable('cbooks') - ]) + ] + let result = Q() + tablesToRemove.forEach(function (item) { + result = result.then(function () { + return item + }) + }) + return result } blueprint.setup = function(knex) { - return Q.all([ + const setupTables = [ knex.schema.createTable('users', function (table) { table.increments() @@ -119,7 +126,14 @@ blueprint.setup = function(knex) { table.string('relation_user_id').references('co_id').inTable('chat_operators').onDelete('CASCADE') }) - ]) + ] + let result = Q() + setupTables.forEach(function (item) { + result = result.then(function () { + return item + }) + }) + return result } blueprint.seed = function(knex){ @@ -235,7 +249,7 @@ blueprint.seed = function(knex){ ] - return Q.all([ + const seeds = [ knex.table('users').insert(users), knex.table('phones').insert(phones), knex.table('authors').insert(authors), @@ -247,5 +261,12 @@ blueprint.seed = function(knex){ knex.table('chat_operators').insert(operators), knex.table('cbooks').insert(cbooks), knex.table('relation_table').insert(relational_values) - ]) + ] + let result = Q() + seeds.forEach(function (item) { + result = result.then(function () { + return item + }) + }) + return result } diff --git a/test/unit/commands.spec.js b/test/unit/commands.spec.js index 95d8b532..94d95e91 100644 --- a/test/unit/commands.spec.js +++ b/test/unit/commands.spec.js @@ -10,6 +10,7 @@ const Make = require('../../src/Commands/Make') const Run = require('../../src/Commands/Run') +const Ioc = require('adonis-fold').Ioc const Rollback = require('../../src/Commands/Rollback') const chai = require('chai') const path = require('path') @@ -28,12 +29,36 @@ const Helpers = { } } } +Ioc.bind('Adonis/Src/Helpers', function () { + return Helpers +}) + +Ioc.bind('Adonis/Src/Console', function () { + return { + icon: function () { + return '' + }, + success: function () { + }, + info: function () { + + } + } +}) + describe('Commands', function () { - before(function () { + before(function (done) { GLOBAL.use = function () { return function () {} } + fs.emptyDir(path.join(__dirname, './migrations'), function (error) { + if (error) { + done(error) + } else { + done() + } + }) }) after(function (done) { @@ -47,23 +72,53 @@ describe('Commands', function () { }) context('Make', function () { + + it('should handle error when unable to create migrations file', function (done) { + expect(Make.description).not.equal(undefined) + expect(Make.signature).not.equal(undefined) + + Ioc.bind('Adonis/Src/Helpers', function () { + return { + migrationsPath: function (name) { + return path.join(__dirname, './mg', name) + } + } + }) + + co(function *() { + yield Make.handle({name: 'create_users_table'}) + }) + .then(function (){ + + }) + .catch(function(error) { + expect(error.code).to.equal('ENOENT') + done() + }) + }) + it('should create a file inside migrations directory', function (done) { - const make = new Make(Helpers) - make.description() - make.signature() + expect(Make.description).not.equal(undefined) + expect(Make.signature).not.equal(undefined) - make - .handle({name: 'create_users_table'}) - .then(function () { - fs.ensureFile(migName, function (err) { - if (err) { - done(err) - } else { - done() - } - }) + Ioc.bind('Adonis/Src/Helpers', function () { + return Helpers + }) + + co(function * () { + yield Make.handle({name: 'create_users_table'}) + }) + .then(function () { + fs.ensureFile(migName, function (err) { + if (err) { + done(err) + } else { + done() + } }) - .catch(done) + }) + .catch(done) + }) }) @@ -71,12 +126,15 @@ describe('Commands', function () { it('should throw error when running in production environment', function (done) { process.env.NODE_ENV = 'production' const Runner = { - up: function * (files) {} + up: function * (files) { + return {status:'completed'} + } } - const run = new Run(Helpers, Runner) - + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) co(function * () { - return yield run.handle({}, {}) + return yield Run.handle({}, {}) }) .then(function () {}) .catch(function (error) { @@ -91,14 +149,17 @@ describe('Commands', function () { const Runner = { up: function * (files) { migrations = files + return {status:'completed'} } } - const run = new Run(Helpers, Runner) - run.description() - run.signature() + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) + expect(Run.description).not.equal(undefined) + expect(Run.signature).not.equal(undefined) co(function * () { - return yield run.handle({}, {}) + return yield Run.handle({}, {}) }) .then(function () { const basename = path.basename(migName).replace('.js', '') @@ -107,18 +168,53 @@ describe('Commands', function () { }) .catch(done) }) + + it('should pass handle skipped status', function (done) { + process.env.NODE_ENV = 'development' + let infoCalled = false + const Runner = { + up: function * (files) { + return {status:'skipped'} + } + } + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) + Ioc.bind('Adonis/Src/Console', function () { + return { + icon: function () {}, + info: function () { + infoCalled = true + } + } + }) + expect(Run.description).not.equal(undefined) + expect(Run.signature).not.equal(undefined) + + co(function * () { + return yield Run.handle({}, {}) + }) + .then(function () { + expect(infoCalled).to.equal(true) + done() + }) + .catch(done) + }) }) context('Rollback', function () { it('should throw error when running in production environment', function (done) { process.env.NODE_ENV = 'production' const Runner = { - up: function * (files) {} + up: function * (files) { + return {status:'completed'} + } } - const rollback = new Rollback(Helpers, Runner) - + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) co(function * () { - return yield rollback.handle({}, {}) + return yield Rollback.handle({}, {}) }) .then(function () {}) .catch(function (error) { @@ -133,14 +229,24 @@ describe('Commands', function () { const Runner = { down: function * (files) { migrations = files + return {status:'completed'} } } - const rollback = new Rollback(Helpers, Runner) - rollback.description() - rollback.signature() + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) + Ioc.bind('Adonis/Src/Console', function () { + return { + icon: function () {}, + info: function () {}, + success: function () {} + } + }) + expect(Rollback.description).not.equal(undefined) + expect(Rollback.signature).not.equal(undefined) co(function * () { - return yield rollback.handle({}, {}) + return yield Rollback.handle({}, {}) }) .then(function () { const basename = path.basename(migName).replace('.js', '') @@ -149,5 +255,38 @@ describe('Commands', function () { }) .catch(done) }) + + it('should handle skipped status', function (done) { + process.env.NODE_ENV = 'development' + let infoCalled = false + const Runner = { + down: function * (files) { + return {status:'skipped'} + } + } + Ioc.bind('Adonis/Src/Runner', function () { + return Runner + }) + Ioc.bind('Adonis/Src/Console', function () { + return { + icon: function () {}, + info: function () { + infoCalled = true + }, + success: function () {} + } + }) + expect(Rollback.description).not.equal(undefined) + expect(Rollback.signature).not.equal(undefined) + + co(function * () { + return yield Rollback.handle({}, {}) + }) + .then(function () { + expect(infoCalled).to.equal(true) + done() + }) + .catch(done) + }) }) }) diff --git a/test/unit/database.spec.js b/test/unit/database.spec.js index c08ede20..dadd1306 100644 --- a/test/unit/database.spec.js +++ b/test/unit/database.spec.js @@ -10,6 +10,7 @@ const Database = require('../../src/Database') const path = require('path') const chai = require('chai') +const manageDb = require('./blueprints/manage') const expect = chai.expect let alternateConnection = { @@ -38,18 +39,51 @@ let Config = { } describe('Database', function () { + + before(function (done) { + manageDb + .make(path.join(__dirname, './storage/test.sqlite3')) + .then(function () { + return manageDb.make(path.join(__dirname, './storage/connection.sqlite3')) + }) + .then(function () { + done() + }) + .catch(done) + }) + + after(function (done) { + manageDb + .remove(path.join(__dirname, './storage/test.sqlite3')) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/connection.sqlite3')) + }) + .then(function () { + done() + }) + .catch(done) + }) + + it('should throw error when database connection is not defined', function () { + const Config = { + get: function () { + return undefined + } + } + const db = function () { + return new Database(Config) + } + expect(db).to.throw(/Specify connection under config\/database file/) + }) + it('should make connection with sqlite database', function () { const db = new Database(Config) expect(db.client.config.client).to.equal('sqlite3') }) - it('should be able to switch connections using connection method', function (done) { + it('should be able to switch connections using connection method', function () { const db = new Database(Config) - db.connection('new') - .table('accounts') - .then(function (accounts) { - expect(accounts).to.be.an('array') - done() - }).catch(done) + const newConnection = db.connection('new') + expect(newConnection.client.config.connection.filename).to.equal(path.join(__dirname, './storage/connection.sqlite3')) }) }) diff --git a/test/unit/migrations/.gitkeep b/test/unit/migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/model-relations.spec.js b/test/unit/model-relations.spec.js index 476feee2..ace5ec23 100644 --- a/test/unit/model-relations.spec.js +++ b/test/unit/model-relations.spec.js @@ -26,6 +26,7 @@ const expect = chai.expect const blueprint = require('./blueprints/model-relations-blueprint') const co = require('co') const Ioc = require('adonis-fold').Ioc +const manageDb = require('./blueprints/manage') const Database = require('../../src/Database') const Model = require('../../src/Orm/Proxy/Model') const _ = require('lodash') @@ -39,7 +40,7 @@ let Config = { return { client: 'sqlite3', connection: { - filename: path.join(__dirname, './storage/test.sqlite3') + filename: path.join(__dirname, './storage/relation.sqlite3') }, debug: false } @@ -57,11 +58,15 @@ const db = new Database(Config) * Tests begins here */ describe('Model Relations', function () { + before(function (done) { - blueprint - .setup(db) + manageDb + .make(path.join(__dirname, './storage/relation.sqlite3')) + .then(function () { + return blueprint.setup(db) + }) .then(function () { - blueprint.seed(db) + return blueprint.seed(db) }) .then(function () { done() @@ -72,6 +77,9 @@ describe('Model Relations', function () { after(function (done) { blueprint .tearDown(db) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/relation.sqlite3')) + }) .then(function () { done() }) diff --git a/test/unit/model.spec.js b/test/unit/model.spec.js index 52654d45..f4b3d775 100644 --- a/test/unit/model.spec.js +++ b/test/unit/model.spec.js @@ -10,6 +10,7 @@ const path = require('path') const chai = require('chai') const expect = chai.expect const co = require('co') +const manageDb = require('./blueprints/manage') const blueprint = require('./blueprints/model-blueprint') const Database = require('../../src/Database') const Model = require('../../src/Orm/Proxy/Model') @@ -20,7 +21,7 @@ let Config = { return { client: 'sqlite3', connection: { - filename: path.join(__dirname, './storage/test.sqlite3') + filename: path.join(__dirname, './storage/model.sqlite3') }, debug: false } @@ -30,19 +31,27 @@ let Config = { const db = new Database(Config) describe('Model', function () { + before(function (done) { - blueprint - .setup(db) + manageDb + .make(path.join(__dirname, './storage/model.sqlite3')) + .then(function () { + return blueprint.setup(db) + }) .then(function () { - blueprint.seed(db) + return blueprint.seed(db) }).then(function () { - done() - }).catch(done) + done() + }) + .catch(done) }) after(function (done) { blueprint .tearDown(db) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/model.sqlite3')) + }) .then(function () { done() }).catch(done) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index 5dd598a1..9ee979b9 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -10,6 +10,7 @@ const Runner = require('../../src/Runner') const Schema = require('../../src/Schema') const chai = require('chai') +const manageDb = require('./blueprints/manage') const blueprint = require('./blueprints/schema-blueprint') const path = require('path') const expect = chai.expect @@ -23,6 +24,15 @@ describe('Runner', function () { .catch(done) }) + after(function (done) { + manageDb + .remove(path.join(__dirname, './storage/schema.sqlite3')) + .then(function () { + done() + }) + .catch(done) + }) + beforeEach(function () { const Config = { get: function (name) { diff --git a/test/unit/staticProxy.spec.js b/test/unit/staticProxy.spec.js index 3bc266ad..5e58fcb4 100644 --- a/test/unit/staticProxy.spec.js +++ b/test/unit/staticProxy.spec.js @@ -4,6 +4,7 @@ const path = require('path') const chai = require('chai') const expect = chai.expect const co = require('co') +const manageDb = require('./blueprints/manage') const blueprint = require('./blueprints/model-blueprint') const Database = require('../../src/Database') const StaticProxy = require('../../src/Orm/Proxy/Static') @@ -13,7 +14,7 @@ let Config = { return { client: 'sqlite3', connection: { - filename: path.join(__dirname, './storage/test.sqlite3') + filename: path.join(__dirname, './storage/proxy.sqlite3') }, debug: false } @@ -24,19 +25,26 @@ const db = new Database(Config) describe('StaticProxy', function () { before(function (done) { - blueprint - .setup(db) + manageDb + .make(path.join(__dirname, './storage/proxy.sqlite3')) + .then(function () { + return blueprint.setup(db) + }) .then(function () { blueprint.seed(db) - }).then(function () { - done() - }).catch(done) - + }) + .then(function () { + done() + }) + .catch(done) }) after(function (done) { blueprint .tearDown(db) + .then(function () { + return manageDb.remove(path.join(__dirname, './storage/proxy.sqlite3')) + }) .then(function () { done() }).catch(done) diff --git a/test/unit/storage/.gitkeep b/test/unit/storage/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/storage/connection.sqlite3 b/test/unit/storage/connection.sqlite3 deleted file mode 100644 index 973bf168..00000000 Binary files a/test/unit/storage/connection.sqlite3 and /dev/null differ diff --git a/test/unit/storage/schema.sqlite3 b/test/unit/storage/schema.sqlite3 deleted file mode 100644 index 22680cc5..00000000 Binary files a/test/unit/storage/schema.sqlite3 and /dev/null differ diff --git a/test/unit/storage/test.sqlite3 b/test/unit/storage/test.sqlite3 deleted file mode 100644 index bafbf00b..00000000 Binary files a/test/unit/storage/test.sqlite3 and /dev/null differ