11import { PDFDocument } from "pdf-lib" ;
22import { readFileSync } from "node:fs" ;
3+ import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest' ;
34
45import {
56 loadPdf ,
@@ -20,14 +21,14 @@ describe("Pdf utility functions", () => {
2021 } ) ;
2122
2223 afterEach ( ( ) => {
23- jest . clearAllMocks ( ) ;
24+ vi . clearAllMocks ( ) ;
2425 } ) ;
2526
2627 describe ( "pdfPagesToBlob" , ( ) => {
2728 it ( "should convert range of pages to a Blob object" , async ( ) => {
28- const copyMock = jest . spyOn ( PDFDocument . prototype , "copyPages" ) ;
29- const saveMock = jest . spyOn ( PDFDocument . prototype , "save" ) ;
30- const addMock = jest . spyOn ( PDFDocument . prototype , "addPage" ) ;
29+ const copyMock = vi . spyOn ( PDFDocument . prototype , "copyPages" ) ;
30+ const saveMock = vi . spyOn ( PDFDocument . prototype , "save" ) ;
31+ const addMock = vi . spyOn ( PDFDocument . prototype , "addPage" ) ;
3132
3233 // Call the method
3334 const result = await pdfPagesToBlob ( pdf , 4 , 8 ) ;
@@ -106,7 +107,7 @@ describe("Pdf utility functions", () => {
106107 it ( "should return true, null, and 0 if the file is not a PDF" , async ( ) => {
107108 const file = {
108109 name : "document.txt" ,
109- content : jest . fn ( ) . mockResolvedValue ( new ArrayBuffer ( 0 ) ) ,
110+ content : vi . fn ( ) . mockResolvedValue ( new ArrayBuffer ( 0 ) ) ,
110111 } ;
111112
112113 const result = await loadPdf ( file as any ) ;
@@ -118,7 +119,7 @@ describe("Pdf utility functions", () => {
118119 it ( "should return true, null, and 0 if the file is not a PDF without basing on file extension" , async ( ) => {
119120 const file = {
120121 name : "uuid1234" ,
121- content : jest . fn ( ) . mockResolvedValue ( new ArrayBuffer ( 0 ) ) ,
122+ content : vi . fn ( ) . mockResolvedValue ( new ArrayBuffer ( 0 ) ) ,
122123 } ;
123124
124125 const result = await loadPdf ( file as any ) ;
@@ -131,7 +132,7 @@ describe("Pdf utility functions", () => {
131132 it ( "should return true, null, and 0 if there is an error while loading the PDF" , async ( ) => {
132133 const file = {
133134 name : "document.pdf" ,
134- arrayBuffer : jest . fn ( ) . mockRejectedValue ( new ArrayBuffer ( 0 ) ) ,
135+ arrayBuffer : vi . fn ( ) . mockRejectedValue ( new ArrayBuffer ( 0 ) ) ,
135136 } ;
136137
137138 const result = await loadPdf ( file as any ) ;
@@ -147,7 +148,7 @@ describe("Pdf utility functions", () => {
147148 arrayBuffer : ( ) => file . buffer ,
148149 } ;
149150
150- const loadMock = jest . spyOn ( PDFDocument , "load" ) ;
151+ const loadMock = vi . spyOn ( PDFDocument , "load" ) ;
151152
152153 const [ error , _ , pages ] = await loadPdf ( f as any ) ;
153154
@@ -164,8 +165,8 @@ describe("Pdf utility functions", () => {
164165 arrayBuffer : ( ) => file . buffer ,
165166 } ;
166167
167- jest . clearAllMocks ( ) ; // Reset Mocks Between Tests
168- const loadMock = jest . spyOn ( PDFDocument , "load" ) ;
168+ vi . clearAllMocks ( ) ; // Reset Mocks Between Tests
169+ const loadMock = vi . spyOn ( PDFDocument , "load" ) ;
169170
170171 const [ error , _ , pages ] = await loadPdf ( f as any ) ;
171172
0 commit comments