1
1
/* globals afterEach, beforeEach, describe, it, expect, jasmine */
2
2
3
3
const build = require ( '../../lib/build' )
4
+ const loadConfig = require ( '../../lib/load-config' )
4
5
const util = require ( '../test-utils/util.js' )
5
6
6
7
const originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL
@@ -16,48 +17,45 @@ describe('build', () => {
16
17
} )
17
18
18
19
describe ( 'development' , ( ) => {
19
- it ( 'should transform js' , ( done ) => {
20
- const results = build ( {
21
- config : { } ,
20
+ it ( 'should transform js' , async ( ) => {
21
+ const [ result ] = await build ( {
22
+ config : loadConfig ( process . cwd ( ) , null , 'development' ) ,
22
23
files : [ [ `${ mockDir } /index.js` ] ]
23
24
} )
24
25
25
- results [ 0 ]
26
- . then ( ( buf ) => {
27
- expect ( buf . toString ( ) . indexOf ( 'MockTestComponentUniqueName' ) ) . to . not . equal ( - 1 )
28
- done ( )
29
- } )
30
- . catch ( done )
26
+ const transpiledString = result . toString ( )
27
+ expect ( transpiledString . indexOf ( 'MockTestComponentUniqueName' ) ) . not . toBe ( - 1 )
28
+ expect ( transpiledString . length ) . toMatchSnapshot ( )
31
29
} )
32
30
33
31
it ( 'should transform css' , async ( ) => {
34
- const results = build ( {
35
- config : { } ,
32
+ const [ result ] = await build ( {
33
+ config : loadConfig ( process . cwd ( ) , null , 'development' ) ,
36
34
files : [ [ `${ mockDir } /index.css` ] ]
37
35
} )
38
36
39
- const result = await results [ 0 ]
40
37
const css = result . css
41
38
expect ( css . indexOf ( 'criticalClass' ) ) . toBeGreaterThan ( - 1 )
39
+ expect ( css . length ) . toMatchSnapshot ( )
42
40
} )
43
41
} )
44
42
45
43
describe ( 'production' , ( ) => {
46
- it ( 'should transform and minify js' , async ( ) => {
47
- const results = build ( {
48
- config : { } ,
44
+ it ( 'should transform and minify js and css ' , async ( ) => {
45
+ const [ jsResult , cssResult ] = await build ( {
46
+ config : loadConfig ( process . cwd ( ) , null , 'production' ) ,
49
47
env : 'production' ,
50
48
files : [
51
49
[ `${ mockDir } /index.js` ] ,
52
50
[ `${ mockDir } /index.css` ]
53
51
] ,
54
52
minify : true
55
53
} )
56
-
57
- const output = await Promise . all ( results )
58
-
59
- expect ( output [ 0 ] . toString ( ) . indexOf ( 'MockTestComponentUniqueName' ) ) . not . toBe ( - 1 )
60
- expect ( output [ 1 ] . css . indexOf ( 'criticalClass' ) ) . not . toBe ( - 1 )
54
+ const transpiledString = jsResult . toString ( )
55
+ expect ( transpiledString . indexOf ( 'MockTestComponentUniqueName' ) ) . not . toBe ( - 1 )
56
+ expect ( cssResult . css . indexOf ( 'criticalClass' ) ) . not . toBe ( - 1 )
57
+ expect ( transpiledString . length ) . toMatchSnapshot ( )
58
+ expect ( cssResult . css . length ) . toMatchSnapshot ( )
61
59
} )
62
60
} )
63
61
} )
0 commit comments