-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/tests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/tests #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR sets up Vitest for testing, adds comprehensive tests, refactors imports to use path aliases, and introduces a new getConfig method in HttpClient.
- Configure Vitest and TypeScript for tests (
vitest.config.ts,tsconfig.test.json) - Add tests for types, helpers,
HttpClient, and app-level functions - Refactor imports to
@/aliases and exposegetConfiginHttpClient - Update package scripts and CI workflow to run tests
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | Configure Vitest (environment, coverage, globals) |
| tsconfig.test.json | Add test-specific TS config and path aliases |
| tests/types/types.test.ts | Validate type definitions |
| tests/helpers/helpers.test.ts | Test helper utilities |
| tests/client/http-client.test.ts | Exercise HttpClient methods over network |
| tests/app/app.test.ts | Test app-level HTTP shortcuts |
| src/helpers/utils.ts | Update imports to use path aliases |
| src/client/http-client.ts | Update imports and add getConfig |
| src/app/app.ts | Update imports to use path aliases |
| package.json | Add Vitest scripts and dev dependencies |
| .github/workflows/publish.yml | Run tests before build in CI |
Comments suppressed due to low confidence (1)
.github/workflows/publish.yml:100
- Silently skipping failing or missing tests may mask regressions; it’s better to let the step fail so that CI surfaces test failures.
run: npm run test || echo "No tests found, skipping..."
| const signal = createTimeoutSignal(1000); | ||
| expect(signal).toBeInstanceOf(AbortSignal); | ||
| expect(signal.aborted).toBe(false); | ||
|
|
||
| // Wait for the timeout to complete | ||
| return new Promise((resolve) => { | ||
| setTimeout(() => { | ||
| expect(signal.aborted).toBe(true); | ||
| resolve(true); | ||
| }, 1000); | ||
| }); |
Copilot
AI
Jun 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test waits a real 1s timeout, which can slow down the suite; consider using Vitest's fake timers or mocking setTimeout to simulate the timeout instantly.
| const signal = createTimeoutSignal(1000); | |
| expect(signal).toBeInstanceOf(AbortSignal); | |
| expect(signal.aborted).toBe(false); | |
| // Wait for the timeout to complete | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| expect(signal.aborted).toBe(true); | |
| resolve(true); | |
| }, 1000); | |
| }); | |
| vi.useFakeTimers(); | |
| const signal = createTimeoutSignal(1000); | |
| expect(signal).toBeInstanceOf(AbortSignal); | |
| expect(signal.aborted).toBe(false); | |
| // Simulate the timeout | |
| vi.advanceTimersByTime(1000); | |
| expect(signal.aborted).toBe(true); | |
| vi.restoreAllMocks(); |
| const client = new HttpClient({ baseURL }); | ||
| const response = await client.request({ method: 'GET', url: '/users' }); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.content).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('should handle GET request', async () => { | ||
| const client = new HttpClient({ baseURL }); |
Copilot
AI
Jun 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] These tests perform real HTTP requests against an external API, which can be slow or flaky; consider mocking fetch or using a local mock server to improve reliability and speed.
| const client = new HttpClient({ baseURL }); | |
| const response = await client.request({ method: 'GET', url: '/users' }); | |
| expect(response.status).toBe(200); | |
| expect(response.content).not.toBeNull(); | |
| }); | |
| it('should handle GET request', async () => { | |
| const client = new HttpClient({ baseURL }); | |
| const client = new HttpClient({ baseURL }); | |
| // Mock the response for the GET request | |
| vi.spyOn(client, 'request').mockResolvedValue({ | |
| status: 200, | |
| content: [{ id: 1, name: 'John Doe' }], | |
| }); | |
| const response = await client.request({ method: 'GET', url: '/users' }); | |
| expect(response.status).toBe(200); | |
| expect(response.content).not.toBeNull(); | |
| expect(response.content[0].id).toBe(1); | |
| }); | |
| it('should handle GET request', async () => { | |
| const client = new HttpClient({ baseURL }); | |
| // Mock the response for the GET request | |
| vi.spyOn(client, 'get').mockResolvedValue({ | |
| status: 200, | |
| content: { id: 1, name: 'John Doe' }, | |
| }); |
| it('should create a Brex client with default config', async () => { | ||
| const client = createBrexClient({ baseURL }); | ||
|
|
||
| const response = await client.request({ |
Copilot
AI
Jun 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The app-level tests hit the real API as well; mocking responses will make tests more deterministic and faster.
| } | ||
|
|
||
| getConfig(): HttpClientConfig { | ||
| return this.config; |
Copilot
AI
Jun 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning the internal config object exposes mutable state to callers; consider returning a shallow copy to prevent accidental external mutations.
| return this.config; | |
| return { ...this.config }; |
This pull request introduces significant changes to enhance testing capabilities, improve code organization, and add new features to the
HttpClient. The key updates include the integration ofvitestfor testing, the addition of comprehensive test cases, the adoption of path aliases, and the introduction of a new method in theHttpClientclass.Testing Enhancements:
vitestas the testing framework, configured invitest.config.tswith support for code coverage, test inclusion/exclusion patterns, and global test utilities.tsconfig.test.jsonfile to support path aliases (@/*forsrcand@tests/*fortests) and include test-related files.HttpClient, helpers, and type definitions, covering various scenarios such as HTTP methods, interceptors, and error handling. [1] [2] [3] [4]Code Organization:
@/) in files likesrc/app/app.ts,src/client/http-client.ts, andsrc/helpers/utils.tsfor better maintainability and readability. [1] [2] [3] [4]New Features:
getConfigmethod in theHttpClientclass to retrieve the current configuration, enhancing its usability.Build and Test Integration:
package.jsonto include newvitestcommands (test,test:watch,test:ui,test:coverage,test:ci) and added@vitestdependencies. [1] [2]publish.yml) to execute tests before building the project.