@@ -4,97 +4,92 @@ const { execSync } = require('child_process')
4
4
const rimraf = require ( 'rimraf' )
5
5
const { error } = require ( './helpers/logger' )
6
6
7
+ const tmpDir = `tmp-${ Math . floor ( Math . random ( ) * 1000000 ) } `
8
+
7
9
// TODO: Jest can't process coverage of spaned processes
8
10
// May need to wrap NYC to get the coverage of all the
9
11
// code executed here
10
12
// https://github.com/amclin/react-project-boilerplate/issues/28
11
13
12
14
describe ( 'Integration Test' , ( ) => {
13
- describe ( 'Generated App' , ( ) => {
14
- beforeAll ( async ( ) => {
15
- // Run the generator expecting successful STDOUT
16
- try {
17
- await execSync ( 'node ./index.js --use-npm --no-git --with-ssr -- tmp' , { stdio : 'inherit' } )
18
- } catch ( e ) {
19
- error ( 'Failed to complete generation process.' , e )
20
- expect ( true ) . toEqual ( false ) // Force test failure
21
- }
22
- } )
23
- afterAll ( ( ) => {
24
- // Cleanup the temp
25
- rimraf . sync ( './tmp' , { } , ( ) => {
26
- error ( 'No tmp directory to remove.' )
27
- expect ( true ) . toEqual ( false ) // Force test failure
15
+ describe ( 'Generated App' , ( ) => {
16
+ beforeAll ( async ( ) => {
17
+ // Run the generator expecting successful STDOUT
18
+ try {
19
+ await execSync (
20
+ `node ./index.js --use-npm --no-git --with-ssr -- ${ tmpDir } ` ,
21
+ { stdio : 'inherit' }
22
+ )
23
+ } catch ( e ) {
24
+ error ( 'Failed to complete generation process.' , e )
25
+ expect ( true ) . toEqual ( false ) // Force test failure
26
+ }
27
+ } )
28
+ afterAll ( ( ) => {
29
+ // Cleanup the temp
30
+ rimraf . sync ( `./${ tmpDir } ` , { } , ( ) => {
31
+ error ( `No tmp directory (${ tmpDir } ) to remove.` )
32
+ expect ( true ) . toEqual ( false ) // Force test failure
33
+ } )
28
34
} )
29
- } )
30
35
31
- it ( 'can build' , async ( ) => {
32
- // Generated app should be buildable
33
- try {
34
- await execSync ( ' (cd tmp ; npm run build)' , { stdio : 'inherit' } )
35
- } catch ( e ) {
36
- error ( 'Generated app failed to build with `npm run build`' , e )
37
- expect ( true ) . toEqual ( false ) // Force test failure
38
- }
39
- } )
36
+ it ( 'can build' , async ( ) => {
37
+ // Generated app should be buildable
38
+ try {
39
+ await execSync ( ` (cd ${ tmpDir } ; npm run build)` , { stdio : 'inherit' } )
40
+ } catch ( e ) {
41
+ error ( 'Generated app failed to build with `npm run build`' , e )
42
+ expect ( true ) . toEqual ( false ) // Force test failure
43
+ }
44
+ } )
40
45
41
- it ( 'can export static html' , async ( ) => {
42
- // Generated app should be exportable
43
- try {
44
- await execSync ( ' (cd tmp ; npm run export)' , { stdio : 'inherit' } )
45
- } catch ( e ) {
46
- error ( 'Generated app failed to export with `npm run export`' , e )
47
- expect ( true ) . toEqual ( false ) // Force test failure
48
- }
49
- } )
46
+ it ( 'can export static html' , async ( ) => {
47
+ // Generated app should be exportable
48
+ try {
49
+ await execSync ( ` (cd ${ tmpDir } ; npm run export)` , { stdio : 'inherit' } )
50
+ } catch ( e ) {
51
+ error ( 'Generated app failed to export with `npm run export`' , e )
52
+ expect ( true ) . toEqual ( false ) // Force test failure
53
+ }
54
+ } )
50
55
51
- describe ( 'New component wizard(plop)' , ( ) => {
52
- const componentTypes = {
53
- atom : {
54
- files : [
55
- 'index.js' ,
56
- 'MockComponent.jsx' ,
57
- 'MockComponent.test.jsx'
58
- ]
59
- } ,
60
- molecule : {
61
- files : [
62
- 'index.js' ,
63
- 'MockComponent.jsx' ,
64
- 'MockComponent.test.jsx'
65
- ]
66
- } ,
67
- organism : {
68
- files : [
69
- 'index.js' ,
70
- 'MockComponent.jsx' ,
71
- 'MockComponent.test.jsx'
72
- ]
56
+ describe ( 'New component wizard(plop)' , ( ) => {
57
+ const componentTypes = {
58
+ atom : {
59
+ files : [ 'index.js' , 'MockComponent.jsx' , 'MockComponent.test.jsx' ]
60
+ } ,
61
+ molecule : {
62
+ files : [ 'index.js' , 'MockComponent.jsx' , 'MockComponent.test.jsx' ]
63
+ } ,
64
+ organism : {
65
+ files : [ 'index.js' , 'MockComponent.jsx' , 'MockComponent.test.jsx' ]
66
+ }
73
67
}
74
- }
75
68
76
- // Loop through each type of component and test the files are created
77
- Object . entries ( componentTypes ) . forEach ( ( [ componentType , data ] ) => {
78
- it ( `can generate new ${ componentType } s through the wizard` , async ( ) => {
79
- const path = `tmp /src/components/${ componentType } s/MockComponent`
80
- const cmd = `(cd tmp ; npm run generate -- component ${ componentType } "mock component" "short description")`
69
+ // Loop through each type of component and test the files are created
70
+ Object . entries ( componentTypes ) . forEach ( ( [ componentType , data ] ) => {
71
+ it ( `can generate new ${ componentType } s through the wizard` , async ( ) => {
72
+ const path = `${ tmpDir } /src/components/${ componentType } s/MockComponent`
73
+ const cmd = `(cd ${ tmpDir } ; npm run generate -- component ${ componentType } "mock component" "short description")`
81
74
82
- try {
83
- await execSync ( cmd )
84
- } catch ( e ) {
85
- error ( `Failed to run plop for a ${ componentType } ` , e )
86
- expect ( true ) . toEqual ( false ) // Force test failure
87
- }
75
+ try {
76
+ await execSync ( cmd )
77
+ } catch ( e ) {
78
+ error ( `Failed to run plop for a ${ componentType } ` , e )
79
+ expect ( true ) . toEqual ( false ) // Force test failure
80
+ }
88
81
89
- // Check that all expected files are generated
90
- data . files . forEach ( ( file ) => {
91
- expect ( fs . readFileSync ( `${ path } /${ file } ` , 'utf-8' ) ) . toMatchSnapshot ( )
82
+ // Check that all expected files are generated
83
+ data . files . forEach ( file => {
84
+ expect (
85
+ fs . readFileSync ( `${ path } /${ file } ` , 'utf-8' )
86
+ ) . toMatchSnapshot ( )
87
+ } )
92
88
} )
93
89
} )
94
- } )
95
90
96
- it . skip ( 'can generate new pages through the wizard' , async ( ) => { } )
97
- it . skip ( 'can generate new apis through the wizard' , async ( ) => { } )
91
+ it . skip ( 'can generate new pages through the wizard' , async ( ) => { } )
92
+ it . skip ( 'can generate new apis through the wizard' , async ( ) => { } )
93
+ } )
98
94
} )
99
95
} )
100
- } )
0 commit comments