3
3
4
4
var
5
5
assert = require ( 'assert' ) ,
6
- fs = require ( 'fs' ) ,
7
6
path = require ( 'path' ) ,
8
- existsSync = fs . existsSync || path . existsSync ,
9
7
assertions = require ( './assertions' ) ,
10
8
rimraf = require ( 'rimraf' ) ,
11
9
tmp = require ( '../lib/tmp' ) ;
12
10
13
11
14
- module . exports = function inbandStandard ( isFile , beforeHook ) {
15
- var testMode = isFile ? 0600 : 0700 ;
16
- describe ( 'without any parameters' , inbandStandardTests ( { mode : testMode , prefix : 'tmp-' } , null , isFile , beforeHook ) ) ;
17
- describe ( 'with prefix' , inbandStandardTests ( { mode : testMode } , { prefix : 'something' } , isFile , beforeHook ) ) ;
18
- describe ( 'with postfix' , inbandStandardTests ( { mode : testMode } , { postfix : '.txt' } , isFile , beforeHook ) ) ;
19
- describe ( 'with template and no leading path' , inbandStandardTests ( { mode : testMode , prefix : 'clike-' , postfix : '-postfix' } , { template : 'clike-XXXXXX-postfix' } , isFile , beforeHook ) ) ;
20
- describe ( 'with template and leading path' , inbandStandardTests ( { mode : testMode , prefix : 'clike-' , postfix : '-postfix' } , { template : path . join ( tmp . tmpdir , 'clike-XXXXXX-postfix' ) } , isFile , beforeHook ) ) ;
21
- describe ( 'with name' , inbandStandardTests ( { mode : testMode } , { name : 'using-name' } , isFile , beforeHook ) ) ;
22
- describe ( 'with mode' , inbandStandardTests ( null , { mode : 0755 } , isFile , beforeHook ) ) ;
23
- describe ( 'with multiple options' , inbandStandardTests ( null , { prefix : 'foo ' , postfix : 'bar' , mode : 0750 } , isFile , beforeHook ) ) ;
12
+ module . exports = function inbandStandard ( isFile , beforeHook , sync = false ) {
13
+ var testMode = isFile ? 0o600 : 0o700 ;
14
+ describe ( 'without any parameters' , inbandStandardTests ( { mode : testMode , prefix : 'tmp-' } , null , isFile , beforeHook , sync ) ) ;
15
+ describe ( 'with prefix' , inbandStandardTests ( { mode : testMode , prefix : 'tmp-' } , { prefix : 'tmp- something' } , isFile , beforeHook , sync ) ) ;
16
+ describe ( 'with postfix' , inbandStandardTests ( { mode : testMode , prefix : 'tmp-' } , { postfix : '.txt' } , isFile , beforeHook , sync ) ) ;
17
+ describe ( 'with template and no leading path' , inbandStandardTests ( { mode : testMode , prefix : 'tmp- clike-' , postfix : '-postfix' } , { template : 'tmp- clike-XXXXXX-postfix' } , isFile , beforeHook , sync ) ) ;
18
+ describe ( 'with template and leading path' , inbandStandardTests ( { mode : testMode , prefix : 'tmp- clike-' , postfix : '-postfix' } , { template : path . join ( tmp . tmpdir , 'tmp- clike-XXXXXX-postfix' ) } , isFile , beforeHook , sync ) ) ;
19
+ describe ( 'with name' , inbandStandardTests ( { mode : testMode } , { name : 'tmp- using-name' } , isFile , beforeHook , sync ) ) ;
20
+ describe ( 'with mode' , inbandStandardTests ( null , { mode : 0o755 } , isFile , beforeHook , sync ) ) ;
21
+ describe ( 'with multiple options' , inbandStandardTests ( null , { prefix : 'tmp-multiple ' , postfix : 'bar' , mode : 0o750 } , isFile , beforeHook , sync ) ) ;
24
22
if ( isFile ) {
25
- describe ( 'with discardDescriptor' , inbandStandardTests ( null , { mode : testMode , discardDescriptor : true } , isFile , beforeHook ) ) ;
26
- describe ( 'with detachDescriptor' , inbandStandardTests ( null , { mode : testMode , detachDescriptor : true } , isFile , beforeHook ) ) ;
23
+ describe ( 'with discardDescriptor' , inbandStandardTests ( null , { mode : testMode , discardDescriptor : true } , isFile , beforeHook , sync ) ) ;
24
+ describe ( 'with detachDescriptor' , inbandStandardTests ( null , { mode : testMode , detachDescriptor : true } , isFile , beforeHook , sync ) ) ;
27
25
}
28
26
} ;
29
27
30
28
31
- function inbandStandardTests ( testOpts , opts , isFile , beforeHook ) {
29
+ function inbandStandardTests ( testOpts , opts , isFile , beforeHook , sync = false ) {
32
30
return function ( ) {
33
31
opts = opts || { } ;
34
32
testOpts = testOpts || { } ;
@@ -51,7 +49,7 @@ function inbandStandardTests(testOpts, opts, isFile, beforeHook) {
51
49
assertions . assertMode ( this . topic . name , testOpts . mode || opts . mode ) ;
52
50
} . bind ( topic ) ) ;
53
51
54
- if ( opts . prefix || testOpts . prefix ) {
52
+ if ( testOpts . prefix || opts . prefix ) {
55
53
it ( 'should have the expected prefix' , function ( ) {
56
54
assertions . assertPrefix ( this . topic . name , testOpts . prefix || opts . prefix ) ;
57
55
} . bind ( topic ) ) ;
@@ -73,18 +71,26 @@ function inbandStandardTests(testOpts, opts, isFile, beforeHook) {
73
71
} . bind ( topic ) ) ;
74
72
}
75
73
76
- it ( 'should have a working removeCallback' , function ( done ) {
77
- const self = this ;
78
- this . topic . removeCallback ( function ( err ) {
79
- if ( err ) return done ( err ) ;
80
- try {
81
- assertions . assertDoesNotExist ( self . topic . name ) ;
82
- } catch ( err ) {
83
- rimraf . sync ( self . topic . name ) ;
84
- return done ( err ) ;
85
- }
86
- done ( ) ;
87
- } ) ;
88
- } . bind ( topic ) ) ;
74
+ if ( sync ) {
75
+ it ( 'should have a working removeCallback' , function ( ) {
76
+ assert . ok ( typeof this . topic . removeCallback === 'function' ) ;
77
+ // important: remove file or dir unconditionally
78
+ rimraf . sync ( this . topic . name ) ;
79
+ } . bind ( topic ) ) ;
80
+ } else {
81
+ it ( 'should have a working removeCallback' , function ( done ) {
82
+ const self = this ;
83
+ this . topic . removeCallback ( function ( err ) {
84
+ if ( err ) return done ( err ) ;
85
+ try {
86
+ assertions . assertDoesNotExist ( self . topic . name ) ;
87
+ } catch ( err ) {
88
+ rimraf . sync ( self . topic . name ) ;
89
+ return done ( err ) ;
90
+ }
91
+ done ( ) ;
92
+ } ) ;
93
+ } . bind ( topic ) ) ;
94
+ }
89
95
} ;
90
96
}
0 commit comments