@@ -60,6 +60,41 @@ describe('complete extraction for search', () => {
6060 await rm ( dir , { recursive : true , force : true } )
6161 }
6262 } )
63+ it ( 'preserves cancellation before inspecting a spreadsheet buffer' , async ( ) => {
64+ const reason = new Error ( 'Cancelled by caller' )
65+ await expect (
66+ new XlsxParser ( ) . parseBuffer ( Buffer . from ( 'invalid workbook' ) , {
67+ contentMode : 'complete' ,
68+ signal : AbortSignal . abort ( reason ) ,
69+ } )
70+ ) . rejects . toBe ( reason )
71+ } )
72+ it . each ( [ 1 , 2 ] ) ( 'preserves cancellation while extracting a %i-row spreadsheet' , async ( rows ) => {
73+ const workbook = XLSX . utils . book_new ( )
74+ XLSX . utils . book_append_sheet (
75+ workbook ,
76+ XLSX . utils . aoa_to_sheet ( [ [ 'first' ] , [ 'second' ] ] . slice ( 0 , rows ) ) ,
77+ 'Data'
78+ )
79+ const buffer = XLSX . write ( workbook , { type : 'buffer' , bookType : 'xlsx' } )
80+ const controller = new AbortController ( )
81+ const reason = new Error ( 'Cancelled during extraction' )
82+ const formatCell = XLSX . utils . format_cell
83+ const format = vi . spyOn ( XLSX . utils , 'format_cell' ) . mockImplementationOnce ( ( ...args ) => {
84+ controller . abort ( reason )
85+ return formatCell ( ...args )
86+ } )
87+ try {
88+ await expect (
89+ new XlsxParser ( ) . parseBuffer ( buffer , {
90+ contentMode : 'complete' ,
91+ signal : controller . signal ,
92+ } )
93+ ) . rejects . toBe ( reason )
94+ } finally {
95+ format . mockRestore ( )
96+ }
97+ } )
6398 it ( 'marks a workbook with only whitespace as degraded in complete mode' , async ( ) => {
6499 const workbook = XLSX . utils . book_new ( )
65100 XLSX . utils . book_append_sheet (
0 commit comments