@@ -40,9 +40,7 @@ export function runNcaAndVerifyOutput(verifyOutput: VerifyOutput, ...args: strin
40
40
}
41
41
42
42
export function createAliasAndVerifyOutput ( testCompletion : TestCompletion ) {
43
- try {
44
- setup ( ) ;
45
-
43
+ installNcaAndTest ( ( ) => {
46
44
throwErrorIfExitCodeNotZero ( createAlias ( testCompletion . aliasCommand ) ) ;
47
45
48
46
const aliasCommandResult = runCommandSync (
@@ -58,18 +56,11 @@ export function createAliasAndVerifyOutput(testCompletion: TestCompletion) {
58
56
59
57
expect ( aliasCommandResult . stderr ) . to . equal ( commandResult . stderr ) ;
60
58
expect ( aliasCommandResult . stdout ) . to . equal ( commandResult . stdout ) ;
61
- } catch ( error ) {
62
- console . error ( error ) ;
63
- throw error ;
64
- } finally {
65
- cleanup ( testCompletion . aliasName ) ;
66
- }
59
+ } , testCompletion . aliasName ) ;
67
60
}
68
61
69
62
export function renameAliasAndVerifyOutput ( aliasName : string , aliasNewName : string , args : string [ ] ) {
70
- try {
71
- setup ( ) ;
72
-
63
+ installNcaAndTest ( ( ) => {
73
64
throwErrorIfExitCodeNotZero ( createAlias ( args ) ) ;
74
65
75
66
const aliasCommandResult = runCommandSync ( aliasName ) ;
@@ -80,18 +71,11 @@ export function renameAliasAndVerifyOutput(aliasName: string, aliasNewName: stri
80
71
81
72
expect ( aliasCommandResult . stderr ) . to . equal ( postRenameCommandResult . stderr ) ;
82
73
expect ( aliasCommandResult . stdout ) . to . equal ( postRenameCommandResult . stdout ) ;
83
- } catch ( error ) {
84
- console . error ( error ) ;
85
- throw error ;
86
- } finally {
87
- cleanup ( aliasNewName ) ;
88
- }
74
+ } , aliasNewName ) ;
89
75
}
90
76
91
77
export function verifyNcaAliasCompletion ( testCompletion : TestCompletion ) {
92
- try {
93
- setup ( ) ;
94
-
78
+ installNcaAndTest ( ( ) => {
95
79
throwErrorIfExitCodeNotZero ( createAlias ( testCompletion . aliasCommand ) ) ;
96
80
97
81
const completionResult = runCommandSync ( 'nca' , 'completion' ) ;
@@ -110,11 +94,19 @@ export function verifyNcaAliasCompletion(testCompletion: TestCompletion) {
110
94
expect ( '' ) . to . equal ( invokeAliasCompletionResult . stderr ) ;
111
95
const expected = testCompletion . expectedOutput . join ( '\n' ) + '\n' ;
112
96
expect ( expected ) . to . equal ( invokeAliasCompletionResult . stdout ) ;
97
+ } , testCompletion . aliasName ) ;
98
+ }
99
+
100
+ export function installNcaAndTest ( testFunction : ( ) => void , aliasName : string | null = null ) {
101
+ try {
102
+ setup ( ) ;
103
+
104
+ testFunction ( ) ;
113
105
} catch ( error ) {
114
106
console . error ( error ) ;
115
107
throw error ;
116
108
} finally {
117
- cleanup ( testCompletion . aliasName ) ;
109
+ cleanup ( aliasName ) ;
118
110
}
119
111
}
120
112
@@ -154,19 +146,19 @@ function runNcaCommand(...args: string[]): ChildProcess {
154
146
return spawn ( Platform . values . ncaCommand , args , { shell : true } ) ;
155
147
}
156
148
157
- function createAlias ( args : string [ ] ) : SpawnSyncReturns < string > {
149
+ export function createAlias ( args : string [ ] ) : SpawnSyncReturns < string > {
158
150
return spawnSync ( 'nca' , [ 'alias' , 'add' , ...args ] , { encoding : 'utf-8' , shell : true } ) ;
159
151
}
160
152
161
- function runCommandSync ( command : string , ...args : string [ ] ) : SpawnSyncReturns < string > {
153
+ export function runCommandSync ( command : string , ...args : string [ ] ) : SpawnSyncReturns < string > {
162
154
return spawnSync ( command , args , { encoding : 'utf-8' , shell : true } ) ;
163
155
}
164
156
165
157
function bufferToString ( buffer : ArrayBuffer | SharedArrayBuffer | { valueOf ( ) : ArrayBuffer | SharedArrayBuffer ; } ) : string {
166
158
return Buffer . from ( buffer ) . toString ( ) ;
167
159
}
168
160
169
- function throwErrorIfExitCodeNotZero ( result : SpawnSyncReturns < string > ) {
161
+ export function throwErrorIfExitCodeNotZero ( result : SpawnSyncReturns < string > ) {
170
162
if ( result . status !== 0 ) {
171
163
throw new Error ( result . stderr ) ;
172
164
}
0 commit comments