diff --git a/src/__tests__/__snapshots__/error_handling.test.ts.snap b/src/__tests__/__snapshots__/error_handling.test.ts.snap index 483491f..a40e227 100644 --- a/src/__tests__/__snapshots__/error_handling.test.ts.snap +++ b/src/__tests__/__snapshots__/error_handling.test.ts.snap @@ -97,77 +97,31 @@ exports[`noSandbox custom ErrorHandler handles arbitrary errors occurring in com exports[`noSandbox custom ErrorHandler properly handles InvalidCommandError 1`] = ` " - + - - - Error: - - - - - ReferenceError: notavailable is not defined - - - - - - - - - - - - - - Error: - - - - - ReferenceError: something is not defined - - - - - - Correct: - - - - - FIRST + + + Here is the query… - - - SECOND + + + Invalid command… - + - THIRD + SyntaxError: Unexpected identifier - - - - Error - - - : - - - ( - - - invalid END-IF location - - - ): + + + + + Post command… - + @@ -177,6 +131,12 @@ exports[`noSandbox custom ErrorHandler properly handles InvalidCommandError 1`] " `; +exports[`noSandbox custom ErrorHandler properly handles InvalidCommandError 2`] = ` +[ + [SyntaxError: Unexpected identifier], +] +`; + exports[`noSandbox rejectNullish setting IMAGE 1`] = `"Result of command qr(\`some random string\`) is null or undefined and rejectNullish is set"`; exports[`sandbox custom ErrorHandler allows graceful handling of NullishCommandResultError 1`] = ` @@ -276,77 +236,31 @@ exports[`sandbox custom ErrorHandler handles arbitrary errors occurring in comma exports[`sandbox custom ErrorHandler properly handles InvalidCommandError 1`] = ` " - + - - - Error: - - - - - Error: ReferenceError: notavailable is not defined - - - - - - - - - - - - - - Error: - - - - - Error: ReferenceError: something is not defined - - - - - - Correct: - - - - - FIRST + + + Here is the query… - - - SECOND + + + Invalid command… - + - THIRD + Error: SyntaxError: Unexpected identifier - - - - Error - - - : - - - ( - - - invalid END-IF location - - - ): + + + + + Post command… - + @@ -356,6 +270,12 @@ exports[`sandbox custom ErrorHandler properly handles InvalidCommandError 1`] = " `; +exports[`sandbox custom ErrorHandler properly handles InvalidCommandError 2`] = ` +[ + [Error: SyntaxError: Unexpected identifier], +] +`; + exports[`sandbox rejectNullish setting IMAGE 1`] = `"Result of command qr(\`some random string\`) is null or undefined and rejectNullish is set"`; exports[`throw when result of INS command is an object 1`] = `"Result of command 'companies' is an object"`; diff --git a/src/__tests__/error_handling.test.ts b/src/__tests__/error_handling.test.ts index 119c1d6..8e6b6d8 100644 --- a/src/__tests__/error_handling.test.ts +++ b/src/__tests__/error_handling.test.ts @@ -159,7 +159,7 @@ if (process.env.DEBUG) setDebugLogSink(console.log); it('properly handles InvalidCommandError', async () => { const template = await fs.promises.readFile( - path.join(__dirname, 'fixtures', 'invalidMultipleErrors.docx') + path.join(__dirname, 'fixtures', 'invalidCommand.docx') ); const errs: Error[] = []; @@ -168,13 +168,7 @@ if (process.env.DEBUG) setDebugLogSink(console.log); { noSandbox, template, - data: { - companies: [ - { name: 'FIRST' }, - { name: 'SECOND' }, - { name: 'THIRD' }, - ], - }, + data: {}, errorHandler: (err, code) => { errs.push(err); return `${err}`; @@ -184,25 +178,19 @@ if (process.env.DEBUG) setDebugLogSink(console.log); ) ).toMatchSnapshot(); - expect(errs.some(e => e instanceof InvalidCommandError)).toBeTruthy(); + expect(errs).toMatchSnapshot(); }); it('handler can decide to re-throw the error, crashing the render', async () => { const template = await fs.promises.readFile( - path.join(__dirname, 'fixtures', 'invalidMultipleErrors.docx') + path.join(__dirname, 'fixtures', 'invalidCommand.docx') ); await expect( createReport({ noSandbox, template, - data: { - companies: [ - { name: 'FIRST' }, - { name: 'SECOND' }, - { name: 'THIRD' }, - ], - }, + data: {}, errorHandler: (err, code) => { throw new Error('yeah, no!'); },