Skip to content

Commit

Permalink
test(create): Fix testing as module when no database.json on root
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Manrique committed Sep 13, 2017
1 parent 2829058 commit 8fb4a1b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/migration_test.js
@@ -1,8 +1,8 @@
var Code = require('code');
var Lab = require('lab');
var proxyquire = require('proxyquire').noPreserveCache();
var lab = exports.lab = Lab.script();
var Migration = require('../lib/migration.js');
var DBMigrate = require('../index');

var date = createDateForTest();
var dateString = '20140220143050';
Expand All @@ -29,7 +29,7 @@ lab.experiment('migration', { parallel: true }, function() {
function asModule() {
lab.test('should create migration', function (done) {

var dbmigrate = DBMigrate.getInstance(true);
var dbmigrate = stubApiInstance(true, {}, {});
dbmigrate.setConfigParam('_',[]);

dbmigrate.create('migrationName').then(done);
Expand Down Expand Up @@ -254,6 +254,22 @@ function getTemplate() {
});
}

function stubApiInstance(isModule, stubs, options, callback) {

delete require.cache[require.resolve('../api.js')];
delete require.cache[require.resolve('optimist')];
var mod = proxyquire('../api.js', stubs),
plugins = {};
options = options || {};

options = Object.assign(options, {
throwUncatched: true,
cwd: __dirname
});

return new mod(plugins, isModule, options, callback);
}

function createDateForTest() {
var date = new Date();
date.setUTCFullYear(2014);
Expand Down

0 comments on commit 8fb4a1b

Please sign in to comment.