@@ -3,18 +3,17 @@ const { existsSync } = require('fs');
3
3
const Database = require ( '../.' ) ;
4
4
5
5
describe ( 'new Database()' , function ( ) {
6
- it ( 'should throw when file path is not a string' , function ( ) {
7
- expect ( ( ) => new Database ( ) ) . to . throw ( TypeError ) ;
8
- expect ( ( ) => new Database ( null ) ) . to . throw ( TypeError ) ;
6
+ it ( 'should throw when given invalid argument types' , function ( ) {
7
+ expect ( ( ) => new Database ( '' , '' ) ) . to . throw ( TypeError ) ;
8
+ expect ( ( ) => new Database ( { } , '' ) ) . to . throw ( TypeError ) ;
9
+ expect ( ( ) => new Database ( { } , { } ) ) . to . throw ( TypeError ) ;
10
+ expect ( ( ) => new Database ( { } ) ) . to . throw ( TypeError ) ;
9
11
expect ( ( ) => new Database ( 0 ) ) . to . throw ( TypeError ) ;
10
12
expect ( ( ) => new Database ( 123 ) ) . to . throw ( TypeError ) ;
11
13
expect ( ( ) => new Database ( new String ( util . next ( ) ) ) ) . to . throw ( TypeError ) ;
12
14
expect ( ( ) => new Database ( ( ) => util . next ( ) ) ) . to . throw ( TypeError ) ;
13
15
expect ( ( ) => new Database ( [ util . next ( ) ] ) ) . to . throw ( TypeError ) ;
14
16
} ) ;
15
- it ( 'should throw when file path is empty' , function ( ) {
16
- expect ( ( ) => new Database ( '' ) ) . to . throw ( TypeError ) ;
17
- } ) ;
18
17
it ( 'should throw when boolean options are provided as non-booleans' , function ( ) {
19
18
expect ( ( ) => new Database ( util . next ( ) , { readOnly : false } ) ) . to . throw ( TypeError ) ;
20
19
expect ( ( ) => new Database ( util . next ( ) , { readonly : undefined } ) ) . to . throw ( TypeError ) ;
@@ -26,6 +25,20 @@ describe('new Database()', function () {
26
25
expect ( ( ) => new Database ( `file:${ util . next ( ) } ` ) ) . to . throw ( TypeError ) ;
27
26
expect ( ( ) => new Database ( `file:${ util . next ( ) } ?mode=memory&cache=shared` ) ) . to . throw ( TypeError ) ;
28
27
} ) ;
28
+ it ( 'should allow anonymous temporary databases to be created' , function ( ) {
29
+ for ( const args of [ [ '' ] , [ ] , [ null ] , [ undefined ] , [ '' , { timeout : 2000 } ] ] ) {
30
+ const db = new Database ( ...args ) ;
31
+ expect ( db . name ) . to . equal ( '' ) ;
32
+ expect ( db . memory ) . to . be . true ;
33
+ expect ( db . readonly ) . to . be . false ;
34
+ expect ( db . open ) . to . be . true ;
35
+ expect ( db . inTransaction ) . to . be . false ;
36
+ expect ( existsSync ( '' ) ) . to . be . false ;
37
+ expect ( existsSync ( 'null' ) ) . to . be . false ;
38
+ expect ( existsSync ( 'undefined' ) ) . to . be . false ;
39
+ expect ( existsSync ( '[object Object]' ) ) . to . be . false ;
40
+ }
41
+ } ) ;
29
42
it ( 'should allow anonymous in-memory databases to be created' , function ( ) {
30
43
const db = new Database ( ':memory:' ) ;
31
44
expect ( db . name ) . to . equal ( ':memory:' ) ;
@@ -57,7 +70,9 @@ describe('new Database()', function () {
57
70
} ) ;
58
71
it ( 'should not allow conflicting in-memory options' , function ( ) {
59
72
expect ( ( ) => new Database ( ':memory:' , { memory : false } ) ) . to . throw ( TypeError ) ;
73
+ expect ( ( ) => new Database ( '' , { memory : false } ) ) . to . throw ( TypeError ) ;
60
74
( new Database ( ':memory:' , { memory : true } ) ) . close ( ) ;
75
+ ( new Database ( '' , { memory : true } ) ) . close ( ) ;
61
76
} ) ;
62
77
it ( 'should allow readonly database connections to be created' , function ( ) {
63
78
expect ( existsSync ( util . next ( ) ) ) . to . be . false ;
@@ -76,6 +91,7 @@ describe('new Database()', function () {
76
91
expect ( existsSync ( util . next ( ) ) ) . to . be . false ;
77
92
expect ( ( ) => new Database ( util . current ( ) , { memory : true , readonly : true } ) ) . to . throw ( TypeError ) ;
78
93
expect ( ( ) => new Database ( ':memory:' , { readonly : true } ) ) . to . throw ( TypeError ) ;
94
+ expect ( ( ) => new Database ( '' , { readonly : true } ) ) . to . throw ( TypeError ) ;
79
95
expect ( existsSync ( util . current ( ) ) ) . to . be . false ;
80
96
} ) ;
81
97
it ( 'should accept the "fileMustExist" option' , function ( ) {
0 commit comments