Skip to content

Integration tests#23

Merged
TristramN merged 5 commits intomainfrom
integration-tests
Mar 20, 2026
Merged

Integration tests#23
TristramN merged 5 commits intomainfrom
integration-tests

Conversation

@TristramN
Copy link
Copy Markdown
Contributor

No description provided.

…sts for SDK workflows, and coverage support

- Added unit tests for `auto-capture` and `capture-runtime` modules to validate core functionality.
- Introduced integration tests for live SDK workflows using the real backend for enrollment, verification, and API validation.
- Created helper methods for mock camera and video processing in `sharpness` tests.
- Added `@vitest/coverage-v8` and configured `test:coverage` script for test coverage reporting.
- Included integration test configurations in `vitest.integration.config.ts`.
- Introduced `face-c.jpg` for testing verification with a non-matching face.
- Updated integration tests to validate both match and no-match scenarios comprehensively.
- Revised `README.md` to clarify fixture file purposes and replace guidance.
Copilot AI review requested due to automatic review settings March 20, 2026 14:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated integration-test suite for exercising the live SimFace backend, while tightening unit-test execution by enabling coverage thresholds in CI.

Changes:

  • Introduces a separate Vitest config + npm script for live-backend integration tests (src/integration/**).
  • Enables v8 coverage reporting with thresholds for the main test run, and updates CI to run coverage by default.
  • Adds/extends unit tests around capture runtime utilities, auto-capture messaging, face detection, and sharpness scoring.

Reviewed changes

Copilot reviewed 11 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
vitest.integration.config.ts New Vitest config for node-based, non-concurrent integration tests.
vite.config.ts Excludes integration tests from unit runs and configures coverage thresholds.
src/shared/capture-runtime.test.ts New unit tests for capture-runtime utilities (camera access, frame capture, blob helpers).
src/shared/auto-capture.test.ts New unit tests for auto-capture countdown/completion messaging.
src/services/sharpness.test.ts Expands tests to cover computeSharpnessScore behavior.
src/services/face-detection.test.ts Adds coverage for image-mode assessFaceQuality and refines mocks.
src/integration/sdk-workflow.integration.test.ts New live-backend workflow integration test (validate/enroll/verify).
src/integration/fixtures/README.md Documents fixture purpose and replacement guidance.
src/index.test.ts Adds tests for enroll/verify edge cases (cancel, alreadyEnrolled, API key failure).
package.json Adds test:integration, test:coverage, and @vitest/coverage-v8.
package-lock.json Locks new coverage dependency and Vitest-related version updates.
.github/workflows/test.yml Runs unit tests with coverage and adds a gated live-backend integration test job.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/integration/sdk-workflow.integration.test.ts Outdated
Comment on lines +33 to +43
// Unique client ID per run to avoid collisions across parallel CI jobs
const CLIENT_ID = `ci-test-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;

function loadFixture(name: string): Blob {
const buffer = readFileSync(resolve(__dirname, 'fixtures', name));
return new Blob([buffer], { type: 'image/jpeg' });
}

describe.skipIf(!hasCredentials)('SDK integration (live backend)', () => {
let client: SimFaceAPIClient;
let faceA: Blob;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These integration tests share state via CLIENT_ID and rely on earlier it(...) blocks having run successfully (enroll before verify). This is brittle (e.g., --sequence.shuffle or a mid-suite failure causes cascading failures); consider combining into a single end-to-end test or marking the suite explicitly sequential (e.g. describe.sequential) and using beforeAll/afterAll to manage setup/cleanup.

Copilot uses AI. Check for mistakes.
});
return ctx;
}

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file installs several global/prototype spies/mocks (e.g. HTMLCanvasElement.prototype.getContext / toBlob, navigator.mediaDevices, etc.) but never restores them, which can leak state into other tests and cause flaky failures. Capture originals and restore in afterEach (or use vi.restoreAllMocks() plus restoring overwritten globals).

Suggested change
afterEach(() => {
vi.restoreAllMocks();
});

Copilot uses AI. Check for mistakes.
Comment on lines +241 to +258
it('rejects when FileReader errors', async () => {
const OriginalFileReader = globalThis.FileReader;

globalThis.FileReader = class MockFileReader {
onload: ((this: FileReader, ev: ProgressEvent<FileReader>) => unknown) | null = null;
onerror: ((this: FileReader, ev: ProgressEvent<FileReader>) => unknown) | null = null;
result: string | ArrayBuffer | null = null;

readAsDataURL() {
// Simulate async error
queueMicrotask(() => this.onerror?.(new ProgressEvent('error') as ProgressEvent<FileReader>));
}
} as unknown as typeof FileReader;

await expect(blobToDataURL(new Blob(['x']))).rejects.toThrow('Failed to read image');

globalThis.FileReader = OriginalFileReader;
});
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

globalThis.FileReader is reassigned and only restored at the end of the test body; if the assertion fails/throws early, the original won’t be restored and later tests may break. Restore via try/finally or move the restoration to an afterEach hook.

Copilot uses AI. Check for mistakes.
Comment on lines +270 to +274
it('resolves with an HTMLImageElement on success', async () => {
const revokeStub = vi.fn();
globalThis.URL.createObjectURL = vi.fn().mockReturnValue('blob:fake-url');
globalThis.URL.revokeObjectURL = revokeStub;

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests overwrite URL.createObjectURL / URL.revokeObjectURL but don’t restore the originals in afterEach, so later tests may see the mocked implementations. Save originals and restore them alongside globalThis.Image in the existing afterEach.

Copilot uses AI. Check for mistakes.
Comment thread src/services/sharpness.test.ts Outdated
- Moved `REFERENCE_VARIANCE` to `capture-config.ts` for centralized configuration.
- Updated integration tests to use `vitest.integration.config.ts` and enforced sequential execution for live backend tests.
- Added `afterEach` hooks to restore global mocks in `capture-runtime.test.ts`.
- Refactored `blobToDataURL` and `blobToImage` tests for clearer cleanup logic.
@TristramN TristramN merged commit 774278f into main Mar 20, 2026
2 checks passed
@TristramN TristramN deleted the integration-tests branch March 20, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants