@@ -6,10 +6,15 @@ import { promisify } from "util";
6
6
const asyncExec = promisify ( cpExec ) ;
7
7
8
8
export function createExec ( cwd : string ) {
9
- return function exec (
9
+ return async function exec (
10
10
command : string
11
- ) : Promise < { stdout : string ; stderr : string } > | never {
12
- return asyncExec ( command , { cwd } ) ;
11
+ ) : Promise < { stdout : string | null ; stderr : string } > {
12
+ try {
13
+ const result = await asyncExec ( command , { cwd } ) ;
14
+ return result ;
15
+ } catch ( e ) {
16
+ return { stdout : null , stderr : e . message } ;
17
+ }
13
18
} ;
14
19
}
15
20
@@ -31,46 +36,57 @@ export function createCherryPick(cwd: string) {
31
36
}
32
37
33
38
export function createCommandRunner ( cwd : string ) {
34
- return async function runCommands ( commands : string [ ] , dir ?: string ) {
39
+ return async function runCommands (
40
+ commands : string [ ] ,
41
+ dir ?: string
42
+ ) : Promise < boolean > {
43
+ let errors = [ ] ;
35
44
for ( const command of commands ) {
36
45
try {
37
46
console . log ( `> ${ command } ` ) ;
38
47
let cwdDir = cwd ;
39
48
if ( dir ) {
40
49
cwdDir = path . join ( cwd , dir ) ;
41
50
}
42
- await createExec ( cwdDir ) ( command ) ;
51
+ const { stdout, stderr } = await createExec ( cwdDir ) ( command ) ;
52
+
53
+ console . warn ( stderr ) ;
54
+ console . log ( stdout ) ;
43
55
} catch ( e ) {
44
- console . log ( `Setup command failed: "${ command } "` ) ;
45
- console . log ( e . message ) ;
56
+ console . error ( `Command failed: "${ command } "` ) ;
57
+ console . warn ( e . message ) ;
58
+ errors . push ( e . message ) ;
46
59
}
47
60
}
61
+ return ! ! errors . length ;
48
62
} ;
49
63
}
50
64
51
- function isAbsolute ( p : string ) {
52
- return path . normalize ( p + "/" ) === path . normalize ( path . resolve ( p ) + "/" ) ;
53
- }
65
+ // function isAbsolute(p: string) {
66
+ // return path.normalize(p + "/") === path.normalize(path.resolve(p) + "/");
67
+ // }
54
68
55
69
export function createTestRunner ( cwd : string , config : T . TestRunnerConfig ) {
56
70
const { command, args, directory } = config ;
57
71
58
- const commandIsAbsolute = isAbsolute ( command ) ;
72
+ // const commandIsAbsolute = isAbsolute(command);
59
73
60
- let runnerPath ;
61
- if ( commandIsAbsolute ) {
62
- // absolute path
63
- runnerPath = command ;
64
- } else {
65
- // relative path
66
- runnerPath = path . join ( cwd , directory || "" , command ) ;
74
+ let wd = cwd ;
75
+ if ( directory ) {
76
+ wd = path . join ( cwd , directory ) ;
67
77
}
68
78
69
- const commandWithArgs = `${ runnerPath } ${ args . tap } ` ;
79
+ const commandWithArgs = `${ command } ${ args . tap } ` ;
70
80
71
- return async function runTest ( ) {
72
- const { stdout, stderr } = await createExec ( cwd ) ( commandWithArgs ) ;
73
- console . log ( stdout ) ;
74
- console . warn ( stderr ) ;
81
+ return async function runTest ( ) : Promise < {
82
+ stdout : string | null ;
83
+ stderr : string | null ;
84
+ } > {
85
+ try {
86
+ // console.log(await createExec(wd)("ls -a node_modules/.bin"));
87
+ return await createExec ( wd ) ( commandWithArgs ) ;
88
+ } catch ( e ) {
89
+ return Promise . resolve ( { stdout : null , stderr : e . message } ) ;
90
+ }
75
91
} ;
76
92
}
0 commit comments