@@ -45,6 +45,34 @@ test('bundleCssModule(filePath)', async () => {
45
45
expect ( result ) . toMatch ( 'dep/main.css' ) ;
46
46
} ) ;
47
47
48
+ test ( 'new Writer(filePath)' , ( ) => {
49
+ const filePath = path . join ( __dirname , 'test-assets/my-module-1/main.css' ) ;
50
+ const fileRef = 'my-module-1/main.css' ;
51
+
52
+ const writer = new Writer ( filePath ) ;
53
+ const items = [ ] ;
54
+
55
+ writer . on ( 'data' , item => {
56
+ items . push ( item ) ;
57
+ } ) ;
58
+
59
+ writer . on ( 'end' , ( ) => {
60
+ const result1 = items [ 0 ] ;
61
+ const result2 = items [ 1 ] ;
62
+
63
+ expect ( result1 . id ) . toBe ( hasher ( `my-module-1|1.0.1|${ fileRef } ` ) ) ;
64
+ expect ( result2 ) . toBeFalsy ( ) ;
65
+ } ) ;
66
+ } ) ;
67
+
68
+ test ( 'new Writer(filePath) relative paths throw error' , ( ) => {
69
+ const filePath = './test-assets/my-module-1/main.css' ;
70
+
71
+ const result = ( ) => new Writer ( filePath ) ;
72
+
73
+ expect ( result ) . toThrow ( ) ;
74
+ } ) ;
75
+
48
76
test ( 'new Writer([filePath])' , ( ) => {
49
77
const filePath = path . join ( __dirname , 'test-assets/my-module-1/main.css' ) ;
50
78
const fileRef = 'my-module-1/main.css' ;
@@ -112,14 +140,30 @@ test('new Writer([filePath1, filePath2]) ensures correct order', () => {
112
140
} ) ;
113
141
} ) ;
114
142
115
- test ( 'new Writer([filePath]) ensures filePath[] is an array ' , ( ) => {
143
+ test ( 'new Writer([filePath]) ensures filePath[] is not null ' , ( ) => {
116
144
const filePath = null ;
117
145
118
146
const result = ( ) => new Writer ( filePath ) ;
119
147
120
148
expect ( result ) . toThrow ( ) ;
121
149
} ) ;
122
150
151
+ test ( 'new Writer([filePath]) ensures filePath[] is not a number' , ( ) => {
152
+ const filePath = 2 ;
153
+
154
+ const result = ( ) => new Writer ( filePath ) ;
155
+
156
+ expect ( result ) . toThrow ( ) ;
157
+ } ) ;
158
+
159
+ test ( 'new Writer([filePath]) ensures filePath is not an object' , ( ) => {
160
+ const filePath = { } ;
161
+
162
+ const result = ( ) => new Writer ( filePath ) ;
163
+
164
+ expect ( result ) . toThrow ( ) ;
165
+ } ) ;
166
+
123
167
test ( 'new Writer([filePath]) ensures filePath[] is an array of strings' , ( ) => {
124
168
const filePath = null ;
125
169
@@ -128,7 +172,15 @@ test('new Writer([filePath]) ensures filePath[] is an array of strings', () => {
128
172
expect ( result ) . toThrow ( ) ;
129
173
} ) ;
130
174
131
- test ( 'new Writer([filePath]) ensures valid filePaths provided' , ( ) => {
175
+ test ( 'new Writer([filePath]) ensures valid filePath provided' , ( ) => {
176
+ const filePath = 'fake.css' ;
177
+
178
+ const result = ( ) => new Writer ( filePath ) ;
179
+
180
+ expect ( result ) . toThrow ( ) ;
181
+ } ) ;
182
+
183
+ test ( 'new Writer([filePath]) ensures valid filePaths provided in array' , ( ) => {
132
184
const filePath = 'fake.css' ;
133
185
134
186
const result = ( ) => new Writer ( [ filePath ] ) ;
0 commit comments