1
1
var Code = require ( 'code' ) ;
2
2
var Lab = require ( 'lab' ) ;
3
+ var proxyquire = require ( 'proxyquire' ) . noPreserveCache ( ) ;
3
4
var lab = exports . lab = Lab . script ( ) ;
4
5
var Migration = require ( '../lib/migration.js' ) ;
5
6
@@ -20,8 +21,21 @@ lab.experiment('migration', { parallel: true }, function() {
20
21
21
22
lab . experiment ( 'get template' , { parallel : true } ,
22
23
getTemplate ) ;
24
+
25
+ lab . experiment ( 'when using db-migrate as module' , { parallel : true } ,
26
+ asModule ) ;
23
27
} ) ;
24
28
29
+ function asModule ( ) {
30
+ lab . test ( 'should create migration' , function ( done ) {
31
+
32
+ var dbmigrate = stubApiInstance ( true , { } , { } ) ;
33
+ dbmigrate . setConfigParam ( '_' , [ ] ) ;
34
+
35
+ dbmigrate . create ( 'migrationName' ) . then ( done ) ;
36
+ } ) ;
37
+ }
38
+
25
39
function newMigrationObject ( ) {
26
40
27
41
lab . experiment ( 'with 2 parameters as the complete filepath' ,
@@ -240,6 +254,22 @@ function getTemplate() {
240
254
} ) ;
241
255
}
242
256
257
+ function stubApiInstance ( isModule , stubs , options , callback ) {
258
+
259
+ delete require . cache [ require . resolve ( '../api.js' ) ] ;
260
+ delete require . cache [ require . resolve ( 'optimist' ) ] ;
261
+ var mod = proxyquire ( '../api.js' , stubs ) ,
262
+ plugins = { } ;
263
+ options = options || { } ;
264
+
265
+ options = Object . assign ( options , {
266
+ throwUncatched : true ,
267
+ cwd : __dirname
268
+ } ) ;
269
+
270
+ return new mod ( plugins , isModule , options , callback ) ;
271
+ }
272
+
243
273
function createDateForTest ( ) {
244
274
var date = new Date ( ) ;
245
275
date . setUTCFullYear ( 2014 ) ;
0 commit comments