@@ -47,6 +47,10 @@ function getTestBinaryPath() {
4747 unrtfPath = join ( __dirname , "lib" , "win32" , "unrtf-0.19.3" , "bin" ) ;
4848 }
4949
50+ if ( ! unrtfPath ) {
51+ throw new Error ( `Unable to find ${ platform } UnRTF binaries.` ) ;
52+ }
53+
5054 return normalize ( unrtfPath ) ;
5155}
5256
@@ -90,9 +94,11 @@ describe("Node-UnRTF module", () => {
9094 // eslint-disable-next-line no-unused-vars -- This is intentional
9195 const unRtf = new UnRTFMock ( ) ;
9296 } catch ( err ) {
93- expect ( err . message ) . toBe (
94- `Unable to find ${ mockPlatform } UnRTF binaries, please pass the installation directory as a parameter to the UnRTF instance.`
95- ) ;
97+ if ( err instanceof Error ) {
98+ expect ( err . message ) . toBe (
99+ `Unable to find ${ mockPlatform } UnRTF binaries, please pass the installation directory as a parameter to the UnRTF instance.`
100+ ) ;
101+ }
96102 }
97103 } ) ;
98104
@@ -115,22 +121,32 @@ describe("Node-UnRTF module", () => {
115121 // eslint-disable-next-line no-unused-vars -- This is intentional
116122 const unRtf = new UnRTFMock ( ) ;
117123 } catch ( err ) {
118- expect ( err . message ) . toBe ( "Unable to determine UnRTF version." ) ;
124+ if ( err instanceof Error ) {
125+ expect ( err . message ) . toBe (
126+ "Unable to determine UnRTF version."
127+ ) ;
128+ }
119129 }
120130 } ) ;
121131 } ) ;
122132
123133 const unRtf = new UnRTF ( testBinaryPath ) ;
124134
125135 describe ( "Convert function" , ( ) => {
136+ /** @type {string } */
126137 let version ;
127138
128139 beforeAll ( async ( ) => {
129140 const { stderr } = await execFileAsync (
130141 join ( testBinaryPath , "unrtf" ) ,
131142 [ "--version" ]
132143 ) ;
133- version = / ^ ( \d { 1 , 2 } \. \d { 1 , 2 } \. \d { 1 , 2 } ) / u. exec ( stderr ) [ 1 ] ;
144+
145+ const match = / ^ ( \d { 1 , 2 } \. \d { 1 , 2 } \. \d { 1 , 2 } ) / u. exec ( stderr ) ;
146+ if ( ! match ?. [ 1 ] ) {
147+ throw new Error ( "Unable to parse UnRTF version from stderr" ) ;
148+ }
149+ version = match [ 1 ] ;
134150 } ) ;
135151
136152 it ( "Converts RTF if any valid options are set" , async ( ) => {
@@ -302,6 +318,7 @@ describe("Node-UnRTF module", () => {
302318 "Rejects with an Error object if $testName" ,
303319 async ( { filePath, options, expError } ) => {
304320 await expect (
321+ // @ts -expect-error: Testing invalid parameters being passed
305322 unRtf . convert ( filePath , {
306323 noPictures : true ,
307324 ...options ,
0 commit comments