File tree Expand file tree Collapse file tree 4 files changed +20
-21
lines changed
Expand file tree Collapse file tree 4 files changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,13 @@ if (!fs.existsSync('./.data')) fs.mkdirSync('./.data');
1313/* istanbul ignore if */
1414if ( ! fs . existsSync ( './.data/db' ) ) fs . mkdirSync ( './.data/db' ) ;
1515
16- const db = new Datastore ( { filename : './.data/db/pushes.db' , autoload : true } ) ;
16+ // export for testing purposes
17+ export let db : Datastore ;
18+ if ( process . env . NODE_ENV === 'test' ) {
19+ db = new Datastore ( { inMemoryOnly : true , autoload : true } ) ;
20+ } else {
21+ db = new Datastore ( { filename : './.data/db/pushes.db' , autoload : true } ) ;
22+ }
1723try {
1824 db . ensureIndex ( { fieldName : 'id' , unique : true } ) ;
1925} catch ( e ) {
Original file line number Diff line number Diff line change @@ -14,8 +14,12 @@ if (!fs.existsSync('./.data')) fs.mkdirSync('./.data');
1414if ( ! fs . existsSync ( './.data/db' ) ) fs . mkdirSync ( './.data/db' ) ;
1515
1616// export for testing purposes
17- export const db = new Datastore ( { filename : './.data/db/repos.db' , autoload : true } ) ;
18-
17+ export let db : Datastore ;
18+ if ( process . env . NODE_ENV === 'test' ) {
19+ db = new Datastore ( { inMemoryOnly : true , autoload : true } ) ;
20+ } else {
21+ db = new Datastore ( { filename : './.data/db/repos.db' , autoload : true } ) ;
22+ }
1923try {
2024 db . ensureIndex ( { fieldName : 'url' , unique : true } ) ;
2125} catch ( e ) {
Original file line number Diff line number Diff line change @@ -11,7 +11,13 @@ if (!fs.existsSync('./.data')) fs.mkdirSync('./.data');
1111/* istanbul ignore if */
1212if ( ! fs . existsSync ( './.data/db' ) ) fs . mkdirSync ( './.data/db' ) ;
1313
14- const db = new Datastore ( { filename : './.data/db/users.db' , autoload : true } ) ;
14+ // export for testing purposes
15+ export let db : Datastore ;
16+ if ( process . env . NODE_ENV === 'test' ) {
17+ db = new Datastore ( { inMemoryOnly : true , autoload : true } ) ;
18+ } else {
19+ db = new Datastore ( { filename : './.data/db/users.db' , autoload : true } ) ;
20+ }
1521
1622// Using a unique constraint with the index
1723try {
You can’t perform that action at this time.
0 commit comments