@@ -37,98 +37,81 @@ describe("ConfigFile", function() {
37
37
}
38
38
} ) ;
39
39
40
- it ( "returns an error" , function ( done ) {
41
- configFile . read ( function ( err ) {
42
- expect ( err ) . to . exist ;
43
- expect ( err . toString ( ) ) . to . contain ( 'non-existing-config.js' ) ;
44
- done ( ) ;
45
- } ) ;
40
+ it ( "it throws an error if file not found " , function ( ) {
41
+ var read = function ( ) {
42
+ configFile . read ( ) ;
43
+ } ;
44
+
45
+ expect ( read ) . to . throw ( / n o n - e x i s t i n g - c o n f i g \. j s / ) ;
46
46
} ) ;
47
47
48
48
describe ( "when createIfNotExists() is used before" , function ( ) {
49
49
beforeEach ( function ( ) {
50
50
configFile . createIfNotExists ( ) ;
51
51
} ) ;
52
52
53
- it ( "returns a empty config" , function ( done ) {
54
- configFile . read ( function ( err , config ) {
55
- expect ( err ) . to . not . exist ;
56
- expect ( config ) . to . exist . and . to . be . a ( 'object' ) . and . to . be . empty ;
57
- done ( ) ;
58
- } ) ;
53
+ it ( "returns a empty config" , function ( ) {
54
+ var config = configFile . read ( ) ;
55
+ expect ( config ) . to . exist . and . to . be . a ( 'object' ) . and . to . be . empty ;
59
56
} ) ;
60
57
} ) ;
61
58
} ) ;
62
59
63
60
describe ( "with a requirejs.config() call with a define() in the file" , function ( ) {
64
61
var configFile = new ConfigFile ( fixture ( 'config-with-define.js' ) ) ;
65
62
66
- it ( "returns all the properties in the config" , function ( done ) {
67
- var config = configFile . read ( function ( err , config ) {
68
- expect ( err ) . to . not . exist ;
63
+ it ( "returns all the properties in the config" , function ( ) {
64
+ var config = configFile . read ( ) ;
69
65
70
- expect ( config ) . to . include . keys ( 'paths' ) ;
71
- done ( ) ;
72
- } ) ;
66
+ expect ( config ) . to . include . keys ( 'paths' ) ;
73
67
} ) ;
74
68
} ) ;
75
69
76
70
77
71
describe ( "with a normal requirejs.config() call in the file" , function ( ) {
78
72
var configFile = new ConfigFile ( fixture ( 'normal-config.js' ) ) ;
79
73
80
- it ( "returns the config as an object" , function ( done ) {
81
- configFile . read ( function ( err , config ) {
82
- expect ( err ) . to . not . exist ;
83
- expect ( config ) . to . exist . and . to . be . an . object ;
84
- done ( ) ;
85
- } ) ;
74
+ it ( "returns the config as an object" , function ( ) {
75
+ var config = configFile . read ( ) ;
76
+ expect ( config ) . to . exist . and . to . be . an ( 'object' ) ;
86
77
} ) ;
87
78
88
- it ( "returns all the properties in the config" , function ( done ) {
89
- var config = configFile . read ( function ( err , config ) {
90
- expect ( err ) . to . not . exist ;
91
- expect ( config ) . to . include . keys ( 'paths' ) ;
92
- done ( ) ;
93
- } ) ;
79
+ it ( "returns all the properties in the config" , function ( ) {
80
+ var config = configFile . read ( ) ;
81
+
82
+ expect ( config ) . to . be . an ( 'object' ) . and . to . include . keys ( 'paths' ) ;
94
83
} ) ;
95
84
} ) ;
96
85
97
- describe ( "with a var require definition" , function ( ) {
86
+ describe ( "with a var require definition" , function ( ) {
98
87
var configFile = new ConfigFile ( fixture ( 'var-config.js' ) ) ;
99
88
100
- it ( "returns the properties from config" , function ( done ) {
101
- configFile . read ( function ( err , config ) {
102
- expect ( err ) . to . not . exist ;
103
- expect ( config ) . to . include . keys ( 'paths' ) ;
104
- done ( ) ;
105
- } ) ;
89
+ it ( "returns the properties from config" , function ( ) {
90
+ var config = configFile . read ( ) ;
91
+ expect ( config ) . to . include . keys ( 'paths' ) ;
106
92
} ) ;
107
93
} ) ;
108
94
109
95
describe ( "with an parse error config" , function ( ) {
110
96
var configFile = new ConfigFile ( fixture ( 'parse-error-config.js' ) ) ;
111
97
112
- it ( "shows an error" , function ( done ) {
113
- configFile . read ( function ( err ) {
114
- expect ( err ) . to . exist ;
115
- expect ( err ) . to . include ( 'syntax error' ) ;
116
- done ( ) ;
117
- } ) ;
98
+ it ( "shows an error" , function ( ) {
99
+ var read = function ( ) {
100
+ configFile . read ( ) ;
101
+ } ;
102
+
103
+ expect ( read ) . to . throw ( / s y n t a x e r r o r / ) ;
118
104
} ) ;
119
105
} ) ;
120
106
121
107
describe ( "with an empty config" , function ( ) {
122
108
var configFile = new ConfigFile ( fixture ( 'empty-config.js' ) ) ;
123
109
124
- it ( "reads the config file and returns an empty object without notice" , function ( done ) {
125
- configFile . read ( function ( err , config ) {
126
- expect ( err ) . to . not . exist ;
127
- expect ( config ) . to . exist . and . to . be . a ( 'object' ) . and . to . be . empty ;
128
- done ( ) ;
129
- } ) ;
130
- } ) ;
110
+ it ( "reads the config file and returns an empty object without notice" , function ( ) {
111
+ var config = configFile . read ( ) ;
131
112
113
+ expect ( config ) . to . exist . and . to . be . a ( 'object' ) . and . to . be . empty ;
114
+ } ) ;
132
115
} ) ;
133
116
} ) ;
134
117
@@ -140,21 +123,17 @@ describe("ConfigFile", function() {
140
123
141
124
var configFile = new ConfigFile ( configFilePath ) ;
142
125
143
- configFile . read ( function ( err , config ) {
144
- expect ( err ) . to . not . exist ;
126
+ var config = configFile . read ( ) ;
145
127
146
- modify ( config ) ;
128
+ modify ( config ) ;
147
129
148
- configFile . write ( function ( err ) {
149
- expect ( err ) . to . not . exist ;
130
+ configFile . write ( ) ;
150
131
151
- var expectedContents = fs . readFileSync ( fixture ( 'modified-' + configName ) ) . toString ( ) ;
152
- var actualContents = fs . readFileSync ( configFilePath ) . toString ( ) ;
132
+ var expectedContents = fs . readFileSync ( fixture ( 'modified-' + configName ) ) . toString ( ) ;
133
+ var actualContents = fs . readFileSync ( configFilePath ) . toString ( ) ;
153
134
154
- assert . equal ( actualContents , expectedContents ) ;
155
- done ( ) ;
156
- } ) ;
157
- } ) ;
135
+ assert . equal ( actualContents , expectedContents ) ;
136
+ done ( ) ;
158
137
} ) ;
159
138
} ;
160
139
@@ -200,26 +179,17 @@ describe("ConfigFile", function() {
200
179
}
201
180
} ) ;
202
181
203
- it ( "writes the file" , function ( done ) {
182
+ it ( "writes the file" , function ( ) {
204
183
configFile . createIfNotExists ( ) ;
205
-
206
- configFile . write ( function ( err ) {
207
- expect ( err ) . to . not . exist ;
208
- done ( ) ;
209
- } ) ;
184
+ configFile . write ( ) ;
210
185
} ) ;
211
186
212
-
213
- it ( "writes the file and creates directories" , function ( done ) {
187
+ it ( "writes the file and creates directories" , function ( ) {
214
188
var nonExistingFile = tmpPath ( 'in/directory/non-existing-config.js' ) ;
215
189
var configFile = new ConfigFile ( nonExistingFile ) ;
216
190
217
191
configFile . createIfNotExists ( ) ;
218
-
219
- configFile . write ( function ( err ) {
220
- expect ( err ) . to . not . exist ;
221
- done ( ) ;
222
- } ) ;
192
+ configFile . write ( ) ;
223
193
} ) ;
224
194
} ) ;
225
195
} ) ;
0 commit comments