zimicjs / zimic

TypeScript-first HTTP request mocking
https://npmjs.com/package/zimic
MIT License
9 stars 2 forks source link

Migration guide: v0.8.0 #278

Closed diego-aquino closed 3 months ago

diego-aquino commented 3 months ago

Migration guide: v0.8.0

1. Install the latest Zimic version

Manager Command
npm npm install zimic@latest --save-dev
pnpm pnpm add zimic@latest --dev
yarn yarn add zimic@latest --dev
bun bun add zimic@latest --dev

2. Change imports to the new structure

v0.8 introduces many improvements to the exported Zimic modules.

A summary of the changes is shown below:

Summary of changes to zimic

Resource (v0.7) Previously exported from (v0.8) Now exported from
type HttpBody zimic zimic/http
type HttpRequest zimic zimic/http
type HttpResponse zimic zimic/http
HttpSearchParams zimic zimic/http
type HttpSearchParamsInit zimic zimic/http
type HttpSearchParamsSchema zimic zimic/http
type HttpSearchParamsSchemaTuple zimic zimic/http
type StrictURLSearchParams zimic zimic/http
HttpHeaders zimic zimic/http
type HttpHeadersInit zimic zimic/http
type HttpHeadersSchema zimic zimic/http
type HttpHeadersSchemaTuple zimic zimic/http
type StrictHeaders zimic zimic/http
HttpFormData zimic zimic/http
type HttpFormDataSchema zimic zimic/http
type StrictFormData zimic zimic/http
type HttpSchema zimic zimic/http
type HttpMethod zimic zimic/http
type HttpServiceSchema zimic zimic/http
type HttpServiceMethodsSchema zimic zimic/http
type HttpServiceMethodSchema zimic zimic/http
type HttpServiceRequestSchema zimic zimic/http
type HttpServiceResponseSchemaByStatusCode zimic zimic/http
type HttpServiceResponseSchema zimic zimic/http
type HttpServiceResponseSchemaStatusCode zimic zimic/http
type HttpServiceSchemaMethod zimic zimic/http
type HttpServiceSchemaPath zimic zimic/http
type LiteralHttpServiceSchemaPath zimic zimic/http
type NonLiteralHttpServiceSchemaPath zimic zimic/http
type PathParamsSchemaFromPath zimic zimic/http
InvalidFormDataError zimic zimic/http

Summary of changes to zimic/interceptor

Resource (v0.7) Previously exported from (v0.8) Now exported from
http zimic/interceptor zimic/interceptor/http as httpInterceptor
type HttpInterceptorNamespace zimic/interceptor zimic/interceptor/http
type HttpInterceptorNamespaceDefault zimic/interceptor zimic/interceptor/http
type HttpInterceptor zimic/interceptor zimic/interceptor/http
type LocalHttpInterceptor zimic/interceptor zimic/interceptor/http
type RemoteHttpInterceptor zimic/interceptor zimic/interceptor/http
type HttpInterceptorPlatform zimic/interceptor zimic/interceptor/http
type HttpInterceptorType zimic/interceptor zimic/interceptor/http
type HttpInterceptorOptions zimic/interceptor zimic/interceptor/http
type LocalHttpInterceptorOptions zimic/interceptor zimic/interceptor/http
type RemoteHttpInterceptorOptions zimic/interceptor zimic/interceptor/http
type UnhandledRequestStrategy zimic/interceptor zimic/interceptor/http
type ExtractHttpInterceptorSchema zimic/interceptor zimic/interceptor/http
type HttpInterceptorRequest zimic/interceptor zimic/interceptor/http
type HttpInterceptorResponse zimic/interceptor zimic/interceptor/http
type TrackedHttpInterceptorRequest zimic/interceptor zimic/interceptor/http
type HttpRequestHandler zimic/interceptor zimic/interceptor/http
type LocalHttpRequestHandler zimic/interceptor zimic/interceptor/http
type RemoteHttpRequestHandler zimic/interceptor zimic/interceptor/http
type SyncedRemoteHttpRequestHandler zimic/interceptor zimic/interceptor/http
type PendingRemoteHttpRequestHandler zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerResponseDeclaration zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerResponseDeclarationFactory zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerRestriction zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerComputedRestriction zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerHeadersStaticRestriction zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerSearchParamsStaticRestriction zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerStaticRestriction zimic/interceptor zimic/interceptor/http
type HttpRequestHandlerBodyStaticRestriction zimic/interceptor zimic/interceptor/http
UnknownHttpInterceptorPlatformError zimic/interceptor zimic/interceptor/http
UnknownHttpInterceptorTypeError zimic/interceptor zimic/interceptor/http
NotStartedHttpInterceptorError zimic/interceptor zimic/interceptor/http
UnregisteredBrowserServiceWorkerError zimic/interceptor zimic/interceptor/http
DisabledRequestSavingError zimic/interceptor zimic/interceptor/http

Summary of changes to zimic/server

Resource (v0.7) Previously exported from (v0.8) Now exported from
createInterceptorServer zimic/server zimic/interceptor/server as interceptorServer.create
InterceptorServer zimic/server zimic/interceptor/server
InterceptorServerOptions zimic/server zimic/interceptor/server
NotStartedInterceptorServerError zimic/server zimic/interceptor/server
runCommand zimic/server [removed]
CommandError zimic/server [removed]
DEFAULT_ACCESS_CONTROL_HEADERS zimic/server zimic/interceptor/server
DEFAULT_PREFLIGHT_STATUS_CODE zimic/server zimic/interceptor/server

3. Migrate from runCommand and CommandError

runCommand and CommandError were removed, mainly because:

  1. Zimic is not focused on running commands, so exporting runCommand did not make sense for Zimic's goal.
  2. runCommand and CommandError are not tied in any way to interceptor servers, so those utilities did not belong to zimic/interceptor/server.
  3. There are better alternatives to runCommand, especially execa and cross-spawn.

If you used runCommand before v0.8, execa is a great alternative. For example:

import { runCommand, CommandError } from 'zimic/server';

try {
  await runCommand('node', ['example.js']);
} catch (error) {
  if (error instanceof CommandError) {
    // ...
  }
}

Can be refactored to:

import { execa as $, ExecaError } from 'execa';

try {
  await $('node', ['example.js'], { stdio: 'inherit' });
} catch (error) {
  if (error instanceof ExecaError) {
    // ...
  }
}

See execa's documentation for more information.


After that, you should be able to use Zimic v0.8 without any issues! If you face problems, feel free to open an issue or create a discussion.

github-actions[bot] commented 3 months ago

Released in v0.8.0 :tada: