fix(build): align TypeScript and test imports with NodeNext builds and safely copy Uint8Array inputs in browser processing

This commit is contained in:
2026-05-01 16:10:01 +00:00
parent aa976061b1
commit c4dc34cd1a
14 changed files with 2811 additions and 4447 deletions
+16 -4
View File
@@ -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();
+7 -1
View File
@@ -1,5 +1,5 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartpreview from '../ts/index.ts';
import * as smartpreview from '../ts/index.js';
// Test data - minimal PDF buffer for testing
const createMinimalPdf = (): Buffer => {
@@ -105,6 +105,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');
}
});
@@ -117,6 +120,9 @@ tap.test('should validate input buffer', 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');
}
});
+7 -4
View File
@@ -277,7 +277,8 @@ tap.test('Performance Benchmark Suite', async () => {
await preview.cleanup();
} catch (error) {
console.log(` ❌ Test skipped: ${error.message}\n`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.log(` ❌ Test skipped: ${errorMessage}\n`);
// Expected if dependencies are not available
expect(error).toBeInstanceOf(smartpreview.PreviewError);
}
@@ -356,7 +357,8 @@ tap.test('Memory Usage Analysis', async () => {
await preview.cleanup();
} catch (error) {
console.log(`❌ Memory test skipped: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.log(`❌ Memory test skipped: ${errorMessage}`);
expect(error).toBeInstanceOf(smartpreview.PreviewError);
}
});
@@ -407,9 +409,10 @@ tap.test('Stress Test - Rapid Conversions', async () => {
await preview.cleanup();
} catch (error) {
console.log(`❌ Stress test skipped: ${error.message}`);
const errorMessage = error instanceof Error ? error.message : String(error);
console.log(`❌ Stress test skipped: ${errorMessage}`);
expect(error).toBeInstanceOf(smartpreview.PreviewError);
}
});
export default tap.start();
export default tap.start();