Skip to content
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: custom unhandled request strategies (#9) #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ea74e8d
feat(#zimic): support custom local unhandled request strategy
diego-aquino May 18, 2024
0564081
refactor(#zimic): improve error messages
diego-aquino May 18, 2024
53f1de7
feat(#zimic): support custom remote unhandled request strategy
diego-aquino May 18, 2024
350785a
test(#zimic): use default logging as false on tests
diego-aquino May 18, 2024
83ab6ae
build(#zimic): use default bundle splitting config
diego-aquino May 18, 2024
01aab59
test(#zimic): adapt tests to new error messages and logs
diego-aquino May 18, 2024
e15c90e
build(#zimic): use commonjs-compatible chalk version
diego-aquino May 19, 2024
26b6bcb
fix(#zimic): skip log when using default preflight response
diego-aquino May 19, 2024
a7c6e0b
fix(#zimic): return error response on local unhandled request
diego-aquino May 19, 2024
35dc186
test(#zimic): verify server unhandled request logs
diego-aquino May 19, 2024
d1c5c6f
refactor(#zimic): make unhandled request handling more consistent
diego-aquino May 19, 2024
a2befa7
test(#zimic): verify interceptor unhandled requests
diego-aquino May 19, 2024
433bfec
feat(#zimic): support custom default unhandled request strategies
diego-aquino May 19, 2024
9d875ca
refactor(#zimic): replace default log flag by worker store
diego-aquino May 19, 2024
4c2b74f
refactor(#zimic): freeze constant objects
diego-aquino May 19, 2024
881e62b
test(#zimic): verify unhandled request defaults
diego-aquino May 19, 2024
0b0ee5f
feat(#zimic): add restriction and unhandled request type exports
diego-aquino May 19, 2024
c61d358
docs(examples-jest-node): ignore unhandled requests by default
diego-aquino May 19, 2024
8bf02ed
chore(zimic-test-client): use default unhandled request strategy
diego-aquino May 19, 2024
8c58baa
chore(examples): increase playwright timeouts
diego-aquino May 21, 2024
d8c2d7b
chore(ci): reduce test concurrency to 1
diego-aquino May 21, 2024
7557e52
Merge branch 'canary' into @diego-aquino/9-custom-unhandled-request-s…
diego-aquino May 24, 2024
2a785af
docs(#zimic): improve documentation
diego-aquino May 24, 2024
e3ba555
Merge branch 'canary' into @diego-aquino/9-custom-unhandled-request-s…
diego-aquino May 24, 2024
6141ec8
Merge branch 'canary' into @diego-aquino/9-custom-unhandled-request-s…
diego-aquino May 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
type HttpInterceptorOptions,
type LocalHttpInterceptorOptions,
type RemoteHttpInterceptorOptions,
type UnhandledRequestStrategy,
type ExtractHttpInterceptorSchema,
type HttpInterceptorRequest,
type HttpInterceptorResponse,
Expand All @@ -51,6 +52,12 @@ import {
type PendingRemoteHttpRequestHandler,
type HttpRequestHandlerResponseDeclaration,
type HttpRequestHandlerResponseDeclarationFactory,
type HttpRequestHandlerRestriction,
type HttpRequestHandlerComputedRestriction,
type HttpRequestHandlerHeadersStaticRestriction,
type HttpRequestHandlerSearchParamsStaticRestriction,
type HttpRequestHandlerStaticRestriction,
type HttpRequestHandlerBodyStaticRestriction,
UnknownHttpInterceptorPlatform,
NotStartedHttpInterceptorError,
UnregisteredServiceWorkerError,
Expand Down Expand Up @@ -106,6 +113,15 @@ describe('Exports', () => {
expectTypeOf(http.createInterceptor).not.toBeAny();
expect(typeof http.createInterceptor).toBe('function');
expectTypeOf<HttpNamespace>().not.toBeAny();

expectTypeOf(http.default.onUnhandledRequest).not.toBeAny();
expect(typeof http.default.onUnhandledRequest).toBe('function');
expectTypeOf<UnhandledRequestStrategy>().not.toBeAny();
expectTypeOf<UnhandledRequestStrategy.Action>().not.toBeAny();
expectTypeOf<UnhandledRequestStrategy.Declaration>().not.toBeAny();
expectTypeOf<UnhandledRequestStrategy.Handler>().not.toBeAny();
expectTypeOf<UnhandledRequestStrategy.HandlerContext>().not.toBeAny();

expectTypeOf<HttpInterceptor<never>>().not.toBeAny();
expectTypeOf<LocalHttpInterceptor<never>>().not.toBeAny();
expectTypeOf<RemoteHttpInterceptor<never>>().not.toBeAny();
Expand All @@ -127,6 +143,13 @@ describe('Exports', () => {
expectTypeOf<HttpRequestHandlerResponseDeclaration<never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerResponseDeclarationFactory<never, never>>().not.toBeAny();

expectTypeOf<HttpRequestHandlerRestriction<never, never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerComputedRestriction<never, never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerHeadersStaticRestriction<never, never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerSearchParamsStaticRestriction<never, never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerStaticRestriction<never, never, never>>().not.toBeAny();
expectTypeOf<HttpRequestHandlerBodyStaticRestriction<never, never, never>>().not.toBeAny();

expectTypeOf<UnknownHttpInterceptorPlatform>().not.toBeAny();
expect(typeof UnknownHttpInterceptorPlatform).toBe('function');
expectTypeOf<NotStartedHttpInterceptorError>().not.toBeAny();
Expand Down
3 changes: 3 additions & 0 deletions examples/with-jest-node/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { beforeAll, beforeEach, afterAll } from '@jest/globals';
import { http } from 'zimic/interceptor';

import githubInterceptor from './interceptors/github';

http.default.onUnhandledRequest({ log: false });

beforeAll(async () => {
await githubInterceptor.start();
});
Expand Down
2 changes: 1 addition & 1 deletion examples/with-next-js/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export default defineConfig({
stdout: 'pipe',
stderr: 'pipe',
reuseExistingServer: true,
timeout: 1000 * 20,
timeout: 30 * 1000,
},
});
2 changes: 1 addition & 1 deletion examples/with-playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export default defineConfig({
stdout: 'pipe',
stderr: 'pipe',
reuseExistingServer: true,
timeout: 1000 * 20,
timeout: 30 * 1000,
},
});
3 changes: 3 additions & 0 deletions examples/with-vitest-node/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { afterAll, beforeAll, beforeEach } from 'vitest';
import { http } from 'zimic/interceptor';

import githubInterceptor from './interceptors/github';

http.default.onUnhandledRequest({ log: false });

beforeAll(async () => {
await githubInterceptor.start();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/zimic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
"dependencies": {
"@whatwg-node/server": "^0.9.33",
"chalk": "^5.3.0",
"chalk": "^4.1.2",
"cross-spawn": "^7.0.3",
"isomorphic-ws": "^5.0.0",
"msw": "^2.2.13",
Expand Down
10 changes: 8 additions & 2 deletions packages/zimic/src/cli/__tests__/browser.cli.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ describe('CLI (browser)', () => {
expect(copyFileSpy).toHaveBeenCalledWith(MOCK_SERVICE_WORKER_PATH, serviceWorkerDestinationPath);

expect(spies.log).toHaveBeenCalledTimes(3);
expect(spies.log).toHaveBeenCalledWith(expect.stringContaining(absolutePublicDirectory));
expect(spies.log).toHaveBeenCalledWith(expect.stringContaining(serviceWorkerDestinationPath));
expect(spies.log).toHaveBeenCalledWith(
expect.any(String) as string,
expect.stringContaining(absolutePublicDirectory),
);
expect(spies.log).toHaveBeenCalledWith(
expect.any(String) as string,
expect.stringContaining(serviceWorkerDestinationPath),
);
});
});

Expand Down