Skip to content

Commit

Permalink
Use a less complicated test template for the errorHandler tests to av…
Browse files Browse the repository at this point in the history
…oid unnecessary overlap with the UnterminatedForLoopError tests.
  • Loading branch information
jjhbw committed Jul 31, 2023
1 parent af8ab37 commit 76308b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 139 deletions.
164 changes: 42 additions & 122 deletions src/__tests__/__snapshots__/error_handling.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,77 +97,31 @@ exports[`noSandbox custom ErrorHandler handles arbitrary errors occurring in com

exports[`noSandbox custom ErrorHandler properly handles InvalidCommandError 1`] = `
"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p w14:paraId="25CE4A56" w14:textId="12830165" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Error:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="60A04E47" w14:textId="2D4C8860" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">ReferenceError: notavailable is not defined</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t xml:space="preserve"></w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:t xml:space="preserve"></w:t>
</w:r>
</w:p>
<w:p w14:paraId="6C18A250" w14:textId="6D8A5112" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2"/>
<w:p w14:paraId="6E5519D2" w14:textId="5DB8C384" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Error:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="20A8246E" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">ReferenceError: something is not defined</w:t>
</w:r>
</w:p>
<w:p w14:paraId="1584BF35" w14:textId="52D65C7B" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2"/>
<w:p w14:paraId="04A6C59C" w14:textId="31466F18" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Correct:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">FIRST</w:t>
<w:p w:rsidR="00A17023" w:rsidRPr="00537D95" w:rsidRDefault="00A17023">
<w:r w:rsidRPr="00537D95">
<w:t xml:space="preserve">Here is the query…</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">SECOND</w:t>
<w:p w:rsidR="00413949" w:rsidRDefault="00413949">
<w:r w:rsidRPr="0070400C">
<w:t xml:space="preserve">Invalid command…</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:p w:rsidR="00537D95" w:rsidRPr="0070400C" w:rsidRDefault="00537D95">
<w:r>
<w:t xml:space="preserve">THIRD</w:t>
<w:t xml:space="preserve">SyntaxError: Unexpected identifier</w:t>
</w:r>
</w:p>
<w:p w14:paraId="5D2C8BCB" w14:textId="0D718F4F" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00DB2764"/>
<w:p w14:paraId="589378FA" w14:textId="21FBC58C" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00DB2764">
<w:r>
<w:t xml:space="preserve">Error</w:t>
</w:r>
<w:r w:rsidR="000F3664">
<w:t xml:space="preserve">:</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve"> (</w:t>
</w:r>
<w:r w:rsidR="003E2DAE">
<w:t xml:space="preserve">invalid END-IF location</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve">):</w:t>
<w:p w:rsidR="00413949" w:rsidRPr="0070400C" w:rsidRDefault="00413949">
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
<w:r w:rsidRPr="0070400C">
<w:t xml:space="preserve">Post command…</w:t>
</w:r>
</w:p>
<w:sectPr w:rsidR="0034542D">
<w:sectPr w:rsidR="00413949" w:rsidRPr="0070400C">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1417" w:right="1701" w:bottom="1417" w:left="1701" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
Expand All @@ -177,6 +131,12 @@ exports[`noSandbox custom ErrorHandler properly handles InvalidCommandError 1`]
</w:document>"
`;

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`] = `
Expand Down Expand Up @@ -276,77 +236,31 @@ exports[`sandbox custom ErrorHandler handles arbitrary errors occurring in comma

exports[`sandbox custom ErrorHandler properly handles InvalidCommandError 1`] = `
"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p w14:paraId="25CE4A56" w14:textId="12830165" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Error:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="60A04E47" w14:textId="2D4C8860" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Error: ReferenceError: notavailable is not defined</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t xml:space="preserve"></w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:t xml:space="preserve"></w:t>
</w:r>
</w:p>
<w:p w14:paraId="6C18A250" w14:textId="6D8A5112" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2"/>
<w:p w14:paraId="6E5519D2" w14:textId="5DB8C384" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Error:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="20A8246E" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">Error: ReferenceError: something is not defined</w:t>
</w:r>
</w:p>
<w:p w14:paraId="1584BF35" w14:textId="52D65C7B" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2"/>
<w:p w14:paraId="04A6C59C" w14:textId="31466F18" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="00257AA2">
<w:r>
<w:t xml:space="preserve">Correct:</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">FIRST</w:t>
<w:p w:rsidR="00A17023" w:rsidRPr="00537D95" w:rsidRDefault="00A17023">
<w:r w:rsidRPr="00537D95">
<w:t xml:space="preserve">Here is the query…</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:r>
<w:t xml:space="preserve">SECOND</w:t>
<w:p w:rsidR="00413949" w:rsidRDefault="00413949">
<w:r w:rsidRPr="0070400C">
<w:t xml:space="preserve">Invalid command…</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6AF2A9B5" w14:textId="77777777" w:rsidR="000F3664" w:rsidRDefault="000F3664" w:rsidP="000F3664">
<w:p w:rsidR="00537D95" w:rsidRPr="0070400C" w:rsidRDefault="00537D95">
<w:r>
<w:t xml:space="preserve">THIRD</w:t>
<w:t xml:space="preserve">Error: SyntaxError: Unexpected identifier</w:t>
</w:r>
</w:p>
<w:p w14:paraId="5D2C8BCB" w14:textId="0D718F4F" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00DB2764"/>
<w:p w14:paraId="589378FA" w14:textId="21FBC58C" w:rsidR="00257AA2" w:rsidRDefault="00257AA2" w:rsidP="00DB2764">
<w:r>
<w:t xml:space="preserve">Error</w:t>
</w:r>
<w:r w:rsidR="000F3664">
<w:t xml:space="preserve">:</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve"> (</w:t>
</w:r>
<w:r w:rsidR="003E2DAE">
<w:t xml:space="preserve">invalid END-IF location</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve">):</w:t>
<w:p w:rsidR="00413949" w:rsidRPr="0070400C" w:rsidRDefault="00413949">
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
<w:r w:rsidRPr="0070400C">
<w:t xml:space="preserve">Post command…</w:t>
</w:r>
</w:p>
<w:sectPr w:rsidR="0034542D">
<w:sectPr w:rsidR="00413949" w:rsidRPr="0070400C">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1417" w:right="1701" w:bottom="1417" w:left="1701" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
Expand All @@ -356,6 +270,12 @@ exports[`sandbox custom ErrorHandler properly handles InvalidCommandError 1`] =
</w:document>"
`;

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"`;
Expand Down
22 changes: 5 additions & 17 deletions src/__tests__/error_handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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}`;
Expand All @@ -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!');
},
Expand Down

0 comments on commit 76308b7

Please sign in to comment.