1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
- const child_process = require ( 'child_process' ) ;
4
3
const assert = require ( 'assert' ) ;
5
4
const glob = require ( 'tiny-glob/sync.js' ) ;
5
+ const shell = require ( "shelljs" ) ;
6
6
7
- const bin = path . resolve ( `svelte` ) ;
7
+ const cli = path . resolve ( __dirname , "../../cli/index.ts.js" ) ;
8
8
9
9
function normalize ( str ) {
10
10
return str
11
11
. replace ( / ^ \s + $ / gm, '' )
12
- . replace ( / g e n e r a t e d b y S v e l t e v [ . \d ] + / , `generated by Svelte vx.y.z` )
12
+ . replace (
13
+ / \/ \* ( .* ?) g e n e r a t e d b y S v e l t e v [ . \d ] + / ,
14
+ ( _ , path ) => `/*${ path . replace ( / \\ / g, '/' ) } generated by Svelte vx.y.z`
15
+ )
13
16
. trim ( ) ;
14
17
}
15
18
@@ -31,49 +34,48 @@ describe('cli', () => {
31
34
32
35
const command = fs . readFileSync ( 'command.sh' , 'utf-8' ) ;
33
36
34
- child_process . exec ( `
35
- alias svelte=${ bin }
36
- mkdir -p actual
37
- rm -rf actual/*
38
- ${ command }
39
- ` , ( err , stdout , stderr ) => {
40
- if ( err ) {
41
- done ( err ) ;
42
- return ;
43
- }
37
+ shell . mkdir ( "-p" , "actual" ) ;
38
+ shell . rm ( "-rf" , "actual/*" ) ;
39
+ const { commandErr } = shell . exec (
40
+ command . replace ( / ^ s v e l t e / , `node ${ cli } ` )
41
+ ) ;
42
+
43
+ if ( commandErr ) {
44
+ done ( commandErr ) ;
45
+ return ;
46
+ }
47
+
48
+ const actual = glob ( '**' , { cwd : 'actual' , filesOnly : true } )
49
+ . map ( file => {
50
+ return {
51
+ file,
52
+ contents : normalize ( fs . readFileSync ( `actual/${ file } ` , 'utf-8' ) )
53
+ } ;
54
+ } ) ;
44
55
45
- const actual = glob ( '**' , { cwd : 'actual' , filesOnly : true } )
46
- . map ( file => {
47
- return {
48
- file,
49
- contents : normalize ( fs . readFileSync ( `actual/${ file } ` , 'utf-8' ) )
50
- } ;
51
- } ) ;
52
-
53
- const expected = glob ( '**' , { cwd : 'expected' , filesOnly : true } )
54
- . map ( file => {
55
- return {
56
- file,
57
- contents : normalize (
58
- fs . readFileSync ( `expected/${ file } ` , 'utf-8' )
59
- )
60
- } ;
61
- } ) ;
62
-
63
- actual . forEach ( ( a , i ) => {
64
- const e = expected [ i ] ;
65
-
66
- assert . equal ( a . file , e . file , 'File list mismatch' ) ;
67
-
68
- if ( / \. m a p $ / . test ( a . file ) ) {
69
- assert . deepEqual ( JSON . parse ( a . contents ) , JSON . parse ( e . contents ) ) ;
70
- } else {
71
- assert . equal ( a . contents , e . contents ) ;
72
- }
56
+ const expected = glob ( '**' , { cwd : 'expected' , filesOnly : true } )
57
+ . map ( file => {
58
+ return {
59
+ file,
60
+ contents : normalize (
61
+ fs . readFileSync ( `expected/${ file } ` , 'utf-8' )
62
+ )
63
+ } ;
73
64
} ) ;
74
65
75
- done ( ) ;
66
+ actual . forEach ( ( a , i ) => {
67
+ const e = expected [ i ] ;
68
+
69
+ assert . equal ( a . file , e . file , 'File list mismatch' ) ;
70
+
71
+ if ( / \. m a p $ / . test ( a . file ) ) {
72
+ assert . deepEqual ( JSON . parse ( a . contents ) , JSON . parse ( e . contents ) ) ;
73
+ } else {
74
+ assert . equal ( a . contents , e . contents ) ;
75
+ }
76
76
} ) ;
77
+
78
+ done ( ) ;
77
79
} ) ;
78
80
} ) ;
79
81
} ) ;
0 commit comments