fix(build): align TypeScript and test imports with NodeNext builds and safely copy Uint8Array inputs in browser processing
This commit is contained in:
+16
-4
@@ -1,5 +1,5 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartpreview from '../ts_web/index.ts';
|
||||
import * as smartpreview from '../ts_web/index.js';
|
||||
|
||||
// Test data - minimal PDF as Uint8Array for browser testing
|
||||
const createMinimalPdfBuffer = (): Uint8Array => {
|
||||
@@ -74,10 +74,16 @@ startxref
|
||||
return new TextEncoder().encode(pdfContent);
|
||||
};
|
||||
|
||||
const uint8ArrayToArrayBuffer = (input: Uint8Array): ArrayBuffer => {
|
||||
const arrayBuffer = new ArrayBuffer(input.byteLength);
|
||||
new Uint8Array(arrayBuffer).set(input);
|
||||
return arrayBuffer;
|
||||
};
|
||||
|
||||
// Create a mock File object for testing
|
||||
const createMockPdfFile = (): File => {
|
||||
const buffer = createMinimalPdfBuffer();
|
||||
return new File([buffer], 'test.pdf', { type: 'application/pdf' });
|
||||
return new File([uint8ArrayToArrayBuffer(buffer)], 'test.pdf', { type: 'application/pdf' });
|
||||
};
|
||||
|
||||
tap.test('should check browser compatibility', async () => {
|
||||
@@ -117,6 +123,9 @@ tap.test('should throw error when not initialized', async () => {
|
||||
expect(true).toEqual(false); // Should not reach here
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(smartpreview.PreviewError);
|
||||
if (!(error instanceof smartpreview.PreviewError)) {
|
||||
throw error;
|
||||
}
|
||||
expect(error.errorType).toEqual('PROCESSING_FAILED');
|
||||
}
|
||||
});
|
||||
@@ -129,6 +138,9 @@ tap.test('should validate input', async () => {
|
||||
expect(true).toEqual(false); // Should not reach here
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(smartpreview.PreviewError);
|
||||
if (!(error instanceof smartpreview.PreviewError)) {
|
||||
throw error;
|
||||
}
|
||||
expect(error.errorType).toEqual('PROCESSING_FAILED');
|
||||
}
|
||||
});
|
||||
@@ -298,7 +310,7 @@ tap.test('should measure different input type processing times', async () => {
|
||||
|
||||
// Test ArrayBuffer input
|
||||
const buffer = createMinimalPdfBuffer();
|
||||
const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
||||
const arrayBuffer = uint8ArrayToArrayBuffer(buffer);
|
||||
const bufferStartTime = performance.now();
|
||||
try {
|
||||
await preview.generatePreview(arrayBuffer, { quality: 70, width: 300, height: 200 });
|
||||
@@ -367,4 +379,4 @@ tap.test('should measure progress callback overhead', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user