1
- const fs = require ( ' fs-extra' ) ;
2
- const cli = require ( "../cli" ) ; ;
3
- const os = require ( 'os' ) ;
4
- const packageName = ' html5-boilerplate' ;
5
- const tempDir = os . tmpdir ( ) + `/${ packageName } -staging` ;
6
-
1
+ const fs = require ( " fs-extra" ) ;
2
+ const cli = require ( "../cli" ) ;
3
+ const os = require ( "os" ) ;
4
+ const packageName = " html5-boilerplate" ;
5
+ const tempDir = os . tmpdir ( ) + `/${ packageName } -staging` ;
6
+ const defaultDir = "./out/default_dir" ;
7
7
8
8
// TODO: fetch all versions:
9
9
// const { packument } = require('pacote');
10
10
// const versions = await packument(packageName);
11
11
// cases = ['', 'latest', '-r=7.3.0', ...Object.keys(versions)];
12
12
const all_versions = [
13
- '0.0.1' ,
14
- '5.3.0' ,
15
- '6.0.0' ,
16
- '6.0.1' ,
17
- '6.1.0' ,
18
- '7.0.0' ,
19
- '7.0.1' ,
20
- '7.1.0' ,
21
- '7.2.0' ,
22
- '7.3.0'
13
+ "0.0.1" ,
14
+ "5.3.0" ,
15
+ "6.0.0" ,
16
+ "6.0.1" ,
17
+ "6.1.0" ,
18
+ "7.0.0" ,
19
+ "7.0.1" ,
20
+ "7.1.0" ,
21
+ "7.2.0" ,
22
+ "7.3.0" ,
23
+ ] ;
24
+ const cases = [
25
+ null ,
26
+ "-r=latest" ,
27
+ "-r=7.2.0" ,
28
+ "-r=v7.2.0" ,
29
+ "-r=v7.2" ,
30
+ "--release=7.3.0" ,
31
+ ...all_versions . map ( ( v ) => "-r=" + v ) ,
23
32
] ;
24
- const cases = [ '-r=7.2.0' , '-r=v7.2.0' , '-r=v7.2' , '--release=7.3.0' , ...all_versions . map ( v => '-r=' + v ) ] ;
33
+ const versionFolder = ( version = null ) =>
34
+ version ? `./out/${ version } ` : defaultDir ;
25
35
26
- const runCli = async ( version ) => { //TODO: blank output
27
- process . argv . push ( `./out/${ version } ` ) ;
28
- if ( version ) {
29
- process . argv . push ( version )
36
+ const runCli = async ( version = null ) => {
37
+ let prevCwd ;
38
+ if ( version ) {
39
+ process . argv . push ( version ) ;
40
+ process . argv . push ( versionFolder ( version ) ) ;
41
+ } else {
42
+ await fs . ensureDir ( defaultDir ) ;
43
+ prevCwd = process . cwd ( ) ;
44
+ process . chdir ( defaultDir ) ;
30
45
}
31
46
await cli ( ) ;
32
- process . argv = process . argv . filter ( v => v !== version && v !== `./out/${ version } ` ) ; //revert process args
33
- }
34
- describe . each ( cases ) (
35
- "Downloading %s" ,
36
- ( version ) => {
37
- beforeAll ( async ( ) => {
38
- await runCli ( version ) ;
39
- } ) ;
40
- afterAll ( async ( ) => {
41
- await fs . remove ( `./out/${ version } ` ) ;
42
- } ) ;
47
+ if ( version ) {
48
+ process . argv = process . argv . filter (
49
+ ( v ) => v !== version && v !== versionFolder ( version )
50
+ ) ; //revert process args
51
+ } else {
52
+ process . chdir ( prevCwd ) ; //revert process current dir
53
+ }
54
+ } ;
55
+ describe . each ( cases ) ( "Downloading %s" , ( version ) => {
56
+ beforeAll ( async ( ) => {
57
+ await runCli ( version ) ;
58
+ } ) ;
59
+ afterAll ( async ( ) => {
60
+ await fs . remove ( versionFolder ( version ) ) ;
61
+ } ) ;
43
62
44
- if ( version ) {
45
- test ( `version ${ version } ` , async ( ) => {
46
- const cssContent = await fs . readFile ( `./out/${ version } /css/main.css` , 'utf-8' ) ;
47
- let versionClear = version . replace ( / ( - r = | - - r e l e a s e = | v ) / gi, '' ) ;
48
- if ( versionClear === '7.0.0' ) { versionClear = '6.1.0' }
49
- if ( versionClear === '0.0.1' ) { versionClear = '5.3.0' }
50
- expect ( cssContent . indexOf ( `HTML5 Boilerplate v${ versionClear } ` ) > - 1 ) . toBe ( true ) ;
51
- } ) ;
63
+ if ( version && version != "-r=latest" ) {
64
+ // if we will fetch all versions from npm registry we will be able to check latest
65
+ // for now we will skip this test for 'latest' version
66
+ test ( `version ${ version } ` , async ( ) => {
67
+ const cssContent = await fs . readFile (
68
+ `./out/${ version } /css/main.css` ,
69
+ "utf-8"
70
+ ) ;
71
+ let versionClear = version . replace ( / ( - r = | - - r e l e a s e = | v ) / gi, "" ) ;
72
+ if ( versionClear === "7.0.0" ) {
73
+ versionClear = "6.1.0" ;
52
74
}
75
+ if ( versionClear === "0.0.1" ) {
76
+ versionClear = "5.3.0" ;
77
+ }
78
+ expect (
79
+ cssContent . indexOf ( `HTML5 Boilerplate v${ versionClear } ` ) > - 1
80
+ ) . toBe ( true ) ;
81
+ } ) ;
82
+ }
83
+
84
+ test ( "./out directory exists" , async ( ) => {
85
+ const outDirExists = await fs . exists ( versionFolder ( version ) ) ;
86
+ expect ( outDirExists ) . toBe ( true ) ;
87
+ } ) ;
88
+
89
+ test ( "./out directory have files" , async ( ) => {
90
+ const dirContents = await fs . readdir ( versionFolder ( version ) ) ;
91
+ expect ( dirContents . length ) . toBeGreaterThanOrEqual ( 5 ) ;
92
+ } ) ;
93
+
94
+ test ( "./out directory specific files" , async ( ) => {
95
+ const dirContents = await fs . readdir ( versionFolder ( version ) ) ;
96
+ const check = [
97
+ "index.html" ,
98
+ "robots.txt" ,
99
+ "tile.png" ,
100
+ "css" ,
101
+ "js" ,
102
+ "img" ,
103
+ ] . filter ( ( v ) => dirContents . indexOf ( v ) === - 1 ) ;
104
+ expect ( check . length === 0 ) . toBe ( true ) ;
105
+ } ) ;
106
+
107
+ test ( "Temp dir removed" , async ( ) => {
108
+ const tempDirExists = await fs . exists ( tempDir ) ;
109
+ expect ( tempDirExists ) . toBe ( false ) ;
110
+ } ) ;
111
+ } ) ;
112
+
113
+ describe ( "Errors" , ( ) => {
114
+ test ( "wrong version 6..2.3" , async ( ) => {
115
+ const mockExit = jest . spyOn ( process , "exit" ) . mockImplementation ( ( ) => { } ) ;
116
+ const version = "-r=6..2.3" ;
53
117
54
- test ( './out directory exists' , async ( ) => {
55
- const outDirExists = await fs . exists ( `./out/${ version } ` ) ;
56
- expect ( outDirExists ) . toBe ( true ) ;
57
- } ) ;
58
- test ( './out directory have files' , async ( ) => {
59
- const dirContents = await fs . readdir ( `./out/${ version } ` ) ;
60
- expect ( dirContents . length ) . toBeGreaterThanOrEqual ( 5 ) ;
61
- } ) ;
62
- test ( './out directory specific files' , async ( ) => {
63
- const dirContents = await fs . readdir ( `./out/${ version } ` ) ;
64
- const check = [ 'index.html' , 'robots.txt' , 'tile.png' , 'css' , 'js' , 'img' ] . filter ( v => dirContents . indexOf ( v ) === - 1 ) ;
65
- expect ( check . length === 0 ) . toBe ( true ) ;
66
- } ) ;
67
- test ( 'Temp dir removed' , async ( ) => {
68
- const tempDirExists = await fs . exists ( tempDir ) ;
69
- expect ( tempDirExists ) . toBe ( false ) ;
70
- } ) ;
71
- }
72
- ) ;
118
+ await runCli ( version ) ;
73
119
74
- describe ( "Errors" , ( ) => {
75
- test ( "wrong version 6..2.3" , async ( ) => {
76
- const mockExit = jest . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => { } ) ;
77
- const version = '-r=6..2.3' ;
78
-
79
- await runCli ( version ) ;
80
-
81
- await fs . remove ( `./out/${ version } ` ) ;
82
- expect ( mockExit ) . toHaveBeenCalledWith ( 1 ) ;
83
- mockExit . mockRestore ( ) ;
84
- } )
85
- } ) ;
120
+ await fs . remove ( versionFolder ( version ) ) ;
121
+ expect ( mockExit ) . toHaveBeenCalledWith ( 1 ) ;
122
+ mockExit . mockRestore ( ) ;
123
+ } ) ;
124
+ } ) ;
0 commit comments