-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Features - [#zimic] Added the module `zimic/server` to export server resources and allow programmatic management. The exported resources are: - `createInterceptorServer` - `InterceptorServer` - `InterceptorServerOptions` - `NotStartedInterceptorServerError` - `runCommand` - `CommandError` - `DEFAULT_ACCESS_CONTROL_HEADERS` - `DEFAULT_PREFLIGHT_STATUS_CODE` ### Refactoring - [examples] Simplified the examples using remote interceptors. Now that the function `runCommand` is exported from `zimic/server`, we can create a load script to apply the mocks before starting the applications. - [#zimic] Removed the prefix `[zimic]` from errors because it is not necessary. ### Documentation - [examples] Improved the documentation of some examples. Closes #130.
- Loading branch information
1 parent
f32320f
commit df29f2a
Showing
73 changed files
with
511 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
apps/zimic-test-client/tests/v0/interceptor/exports/exports.node.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, expectTypeOf, it } from 'vitest'; | ||
import { | ||
createInterceptorServer, | ||
InterceptorServer, | ||
InterceptorServerOptions, | ||
NotStartedInterceptorServerError, | ||
runCommand, | ||
CommandError, | ||
DEFAULT_ACCESS_CONTROL_HEADERS, | ||
DEFAULT_PREFLIGHT_STATUS_CODE, | ||
} from 'zimic0/server'; | ||
|
||
describe('Exports (Node.js)', () => { | ||
it('should export all expected resources', () => { | ||
expect(typeof createInterceptorServer).toBe('function'); | ||
expectTypeOf<InterceptorServer>().not.toBeAny(); | ||
expectTypeOf<InterceptorServerOptions>().not.toBeAny(); | ||
expectTypeOf<NotStartedInterceptorServerError>().not.toBeAny(); | ||
expect(typeof NotStartedInterceptorServerError).toBe('function'); | ||
expect(typeof runCommand).toBe('function'); | ||
expectTypeOf<CommandError>().not.toBeAny(); | ||
expect(typeof CommandError).toBe('function'); | ||
|
||
expect(DEFAULT_ACCESS_CONTROL_HEADERS).toEqual(expect.any(Object)); | ||
expect(DEFAULT_PREFLIGHT_STATUS_CODE).toEqual(expect.any(Number)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
NODE_ENV=development | ||
|
||
ZIMIC_SERVER_URL=http://localhost:3005 | ||
NEXT_PUBLIC_GITHUB_API_BASE_URL=$ZIMIC_SERVER_URL/github | ||
GITHUB_API_BASE_URL=https://api.github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
NODE_ENV=test | ||
|
||
ZIMIC_SERVER_URL=http://localhost:3005 | ||
GITHUB_API_BASE_URL=$ZIMIC_SERVER_URL/github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const environment = { | ||
GITHUB_API_BASE_URL: process.env.NEXT_PUBLIC_GITHUB_API_BASE_URL ?? '', | ||
GITHUB_API_BASE_URL: process.env.GITHUB_API_BASE_URL ?? '', | ||
}; | ||
|
||
export default environment; |
17 changes: 0 additions & 17 deletions
17
examples/with-next-js-app/src/providers/interceptors/InterceptorProvider.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { http } from 'zimic/interceptor'; | ||
|
||
import environment from '../../src/config/environment'; | ||
import { GitHubRepository } from '../../src/services/github'; | ||
|
||
const githubInterceptor = http.createInterceptor<{ | ||
'/repos/:owner/:name': { | ||
GET: { | ||
response: { | ||
200: { body: GitHubRepository }; | ||
404: { body: { message: string } }; | ||
500: { body: { message: string } }; | ||
}; | ||
}; | ||
}; | ||
}>({ | ||
type: 'remote', | ||
baseURL: environment.GITHUB_API_BASE_URL, | ||
}); | ||
|
||
export const githubFixtures = { | ||
repository: { | ||
id: 1, | ||
name: 'example', | ||
full_name: 'owner/example', | ||
html_url: 'https://github.com/owner/example', | ||
owner: { login: 'owner' }, | ||
} satisfies GitHubRepository, | ||
|
||
async apply() { | ||
await githubInterceptor.get('/repos/:owner/:name').respond({ | ||
status: 404, | ||
body: { message: 'Not Found' }, | ||
}); | ||
|
||
await githubInterceptor.get(`/repos/${this.repository.owner.login}/${this.repository.name}`).respond({ | ||
status: 200, | ||
body: this.repository, | ||
}); | ||
}, | ||
}; | ||
|
||
export default githubInterceptor; |
26 changes: 0 additions & 26 deletions
26
examples/with-next-js-app/tests/interceptors/github/fixtures.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
examples/with-next-js-app/tests/interceptors/github/interceptor.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.