11const assert = require ( 'assert' ) ;
2- const fs = require ( 'fs' ) ;
3- const { bundle, run, assertBundleTree} = require ( './utils' ) ;
4- const promisify = require ( '../src/utils/promisify' ) ;
5- const ncp = promisify ( require ( 'ncp' ) ) ;
6- const rimraf = require ( 'rimraf' ) ;
2+ const fs = require ( '../src/utils/fs' ) ;
3+ const { bundle, run, assertBundleTree, rimraf, ncp} = require ( './utils' ) ;
74
85describe ( 'css' , function ( ) {
96 it ( 'should produce two bundles when importing a CSS file' , async function ( ) {
107 let b = await bundle ( __dirname + '/integration/css/index.js' ) ;
118
12- assertBundleTree ( b , {
9+ await assertBundleTree ( b , {
1310 name : 'index.js' ,
1411 assets : [ 'index.js' , 'index.css' , 'local.js' , 'local.css' ] ,
1512 childBundles : [
@@ -24,15 +21,15 @@ describe('css', function() {
2421 ]
2522 } ) ;
2623
27- let output = run ( b ) ;
24+ let output = await run ( b ) ;
2825 assert . equal ( typeof output , 'function' ) ;
2926 assert . equal ( output ( ) , 3 ) ;
3027 } ) ;
3128
3229 it ( 'should support loading a CSS bundle along side dynamic imports' , async function ( ) {
3330 let b = await bundle ( __dirname + '/integration/dynamic-css/index.js' ) ;
3431
35- assertBundleTree ( b , {
32+ await assertBundleTree ( b , {
3633 name : 'index.js' ,
3734 assets : [
3835 'index.js' ,
@@ -68,15 +65,15 @@ describe('css', function() {
6865 ]
6966 } ) ;
7067
71- let output = run ( b ) ;
68+ let output = await run ( b ) ;
7269 assert . equal ( typeof output , 'function' ) ;
7370 assert . equal ( await output ( ) , 3 ) ;
7471 } ) ;
7572
7673 it ( 'should support importing CSS from a CSS file' , async function ( ) {
7774 let b = await bundle ( __dirname + '/integration/css-import/index.js' ) ;
7875
79- assertBundleTree ( b , {
76+ await assertBundleTree ( b , {
8077 name : 'index.js' ,
8178 assets : [ 'index.js' , 'index.css' , 'other.css' , 'local.css' ] ,
8279 childBundles : [
@@ -92,11 +89,11 @@ describe('css', function() {
9289 ]
9390 } ) ;
9491
95- let output = run ( b ) ;
92+ let output = await run ( b ) ;
9693 assert . equal ( typeof output , 'function' ) ;
9794 assert . equal ( output ( ) , 2 ) ;
9895
99- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
96+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
10097 assert ( css . includes ( '.local' ) ) ;
10198 assert ( css . includes ( '.other' ) ) ;
10299 assert ( / @ m e d i a p r i n t { \s * .o t h e r / . test ( css ) ) ;
@@ -106,7 +103,7 @@ describe('css', function() {
106103 it ( 'should support linking to assets with url() from CSS' , async function ( ) {
107104 let b = await bundle ( __dirname + '/integration/css-url/index.js' ) ;
108105
109- assertBundleTree ( b , {
106+ await assertBundleTree ( b , {
110107 name : 'index.js' ,
111108 assets : [ 'index.js' , 'index.css' ] ,
112109 childBundles : [
@@ -126,11 +123,11 @@ describe('css', function() {
126123 ]
127124 } ) ;
128125
129- let output = run ( b ) ;
126+ let output = await run ( b ) ;
130127 assert . equal ( typeof output , 'function' ) ;
131128 assert . equal ( output ( ) , 2 ) ;
132129
133- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
130+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
134131 assert ( / u r l \( " t e s t \. [ 0 - 9 a - f ] + \. w o f f 2 " \) / . test ( css ) ) ;
135132 assert ( css . includes ( 'url("http://google.com")' ) ) ;
136133 assert ( css . includes ( '.index' ) ) ;
@@ -140,7 +137,7 @@ describe('css', function() {
140137 assert ( css . includes ( '.no-quote' ) ) ;
141138
142139 assert (
143- fs . existsSync (
140+ await fs . exists (
144141 __dirname + '/dist/' + css . match ( / u r l \( " ( t e s t \. [ 0 - 9 a - f ] + \. w o f f 2 ) " \) / ) [ 1 ]
145142 )
146143 ) ;
@@ -151,7 +148,7 @@ describe('css', function() {
151148 production : true
152149 } ) ;
153150
154- assertBundleTree ( b , {
151+ await assertBundleTree ( b , {
155152 name : 'index.js' ,
156153 assets : [ 'index.js' , 'index.css' ] ,
157154 childBundles : [
@@ -171,11 +168,11 @@ describe('css', function() {
171168 ]
172169 } ) ;
173170
174- let output = run ( b ) ;
171+ let output = await run ( b ) ;
175172 assert . equal ( typeof output , 'function' ) ;
176173 assert . equal ( output ( ) , 2 ) ;
177174
178- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
175+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
179176 assert ( / u r l \( t e s t \. [ 0 - 9 a - f ] + \. w o f f 2 \) / . test ( css ) , 'woff ext found in css' ) ;
180177 assert ( css . includes ( 'url(http://google.com)' ) , 'url() found' ) ;
181178 assert ( css . includes ( '.index' ) , '.index found' ) ;
@@ -185,7 +182,7 @@ describe('css', function() {
185182 assert ( css . includes ( '.no-quote' ) ) ;
186183
187184 assert (
188- fs . existsSync (
185+ await fs . exists (
189186 __dirname + '/dist/' + css . match ( / u r l \( ( t e s t \. [ 0 - 9 a - f ] + \. w o f f 2 ) \) / ) [ 1 ]
190187 )
191188 ) ;
@@ -194,7 +191,7 @@ describe('css', function() {
194191 it ( 'should support transforming with postcss' , async function ( ) {
195192 let b = await bundle ( __dirname + '/integration/postcss/index.js' ) ;
196193
197- assertBundleTree ( b , {
194+ await assertBundleTree ( b , {
198195 name : 'index.js' ,
199196 assets : [ 'index.js' , 'index.css' ] ,
200197 childBundles : [
@@ -209,15 +206,15 @@ describe('css', function() {
209206 ]
210207 } ) ;
211208
212- let output = run ( b ) ;
209+ let output = await run ( b ) ;
213210 assert . equal ( typeof output , 'function' ) ;
214211
215212 let value = output ( ) ;
216213 assert ( / _ i n d e x _ [ 0 - 9 a - z ] + _ 1 / . test ( value ) ) ;
217214
218215 let cssClass = value . match ( / ( _ i n d e x _ [ 0 - 9 a - z ] + _ 1 ) / ) [ 1 ] ;
219216
220- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
217+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
221218 assert ( css . includes ( `.${ cssClass } ` ) ) ;
222219 } ) ;
223220
@@ -226,18 +223,18 @@ describe('css', function() {
226223 production : true
227224 } ) ;
228225
229- let output = run ( b ) ;
226+ let output = await run ( b ) ;
230227 assert . equal ( typeof output , 'function' ) ;
231228 assert . equal ( output ( ) , 3 ) ;
232229
233- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
230+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
234231 assert ( css . includes ( '.local' ) ) ;
235232 assert ( css . includes ( '.index' ) ) ;
236233 assert ( ! css . includes ( '\n' ) ) ;
237234 } ) ;
238235
239236 it ( 'should automatically install postcss plugins with npm if needed' , async function ( ) {
240- rimraf . sync ( __dirname + '/input' ) ;
237+ await rimraf ( __dirname + '/input' ) ;
241238 await ncp ( __dirname + '/integration/autoinstall/npm' , __dirname + '/input' ) ;
242239 await bundle ( __dirname + '/input/index.css' ) ;
243240
@@ -249,12 +246,12 @@ describe('css', function() {
249246 assert ( pkg . devDependencies [ 'caniuse-lite' ] ) ;
250247
251248 // cssnext is applied
252- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
249+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
253250 assert ( css . includes ( 'rgba' ) ) ;
254251 } ) ;
255252
256253 it ( 'should automatically install postcss plugins with yarn if needed' , async function ( ) {
257- rimraf . sync ( __dirname + '/input' ) ;
254+ await rimraf ( __dirname + '/input' ) ;
258255 await ncp (
259256 __dirname + '/integration/autoinstall/yarn' ,
260257 __dirname + '/input'
@@ -269,11 +266,11 @@ describe('css', function() {
269266 assert ( pkg . devDependencies [ 'caniuse-lite' ] ) ;
270267
271268 // appveyor is not currently writing to the yarn.lock file and will require further investigation
272- // let lockfile = fs.readFileSync (__dirname + '/input/yarn.lock', 'utf8');
269+ // let lockfile = await fs.readFile (__dirname + '/input/yarn.lock', 'utf8');
273270 // assert(lockfile.includes('postcss-cssnext'));
274271
275272 // cssnext is applied
276- let css = fs . readFileSync ( __dirname + '/dist/index.css' , 'utf8' ) ;
273+ let css = await fs . readFile ( __dirname + '/dist/index.css' , 'utf8' ) ;
277274 assert ( css . includes ( 'rgba' ) ) ;
278275 } ) ;
279276} ) ;
0 commit comments