diff --git a/MIGRATING.md b/MIGRATING.md index bf0e77f2d..8ddc0e003 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -82,7 +82,7 @@ A response resolver now exposes a single object argument instead of `(req, res, #### General -- `request`, a Fetch API `Request` instance representing a captured request. +- `request`, a Fetch API `Request` instance representing an intercepted request. - `cookies`, a parsed cookies object based on the request cookies. #### REST-specific @@ -100,7 +100,7 @@ To mock responses, you should now return a Fetch API `Response` instance from th ```js http.get('/greet/:name', ({ request, params }) => { - console.log('Captured %s %s', request.method, request.url) + console.log('Intercepted %s %s', request.method, request.url) return new Response(`hello, ${params.name}!`) }) ``` diff --git a/README.md b/README.md index 3480e72fb..ae35703cf 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ - **Seamless**. A dedicated layer of requests interception at your disposal. Keep your application's code and tests unaware of whether something is mocked or not. - **Deviation-free**. Request the same production resources and test the actual behavior of your app. Augment an existing API, or design it as you go when there is none. -- **Familiar & Powerful**. Use [Express](https://github.com/expressjs/express)-like routing syntax to capture requests. Use parameters, wildcards, and regular expressions to match requests, and respond with necessary status codes, headers, cookies, delays, or completely custom resolvers. +- **Familiar & Powerful**. Use [Express](https://github.com/expressjs/express)-like routing syntax to intercept requests. Use parameters, wildcards, and regular expressions to match requests, and respond with necessary status codes, headers, cookies, delays, or completely custom resolvers. --- @@ -53,7 +53,7 @@ This README will give you a brief overview on the library but there's no better ### How does it work? -In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API), which can intercept requests for the purpose of caching, Mock Service Worker responds to captured requests with your mock definition on the network level. This way your application knows nothing about the mocking. +In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API), which can intercept requests for the purpose of caching, Mock Service Worker responds to intercepted requests with your mock definition on the network level. This way your application knows nothing about the mocking. **Take a look at this quick presentation on how Mock Service Worker functions in a browser:** diff --git a/src/browser/setupWorker/glossary.ts b/src/browser/setupWorker/glossary.ts index 9bedc369c..084f3cc65 100644 --- a/src/browser/setupWorker/glossary.ts +++ b/src/browser/setupWorker/glossary.ts @@ -35,7 +35,7 @@ type RequestWithoutMethods = Omit< export interface ServiceWorkerIncomingRequest extends RequestWithoutMethods { /** * Unique ID of the request generated once the request is - * captured by the "fetch" event in the Service Worker. + * intercepted by the "fetch" event in the Service Worker. */ id: string body?: ArrayBuffer | null @@ -174,7 +174,7 @@ export interface StartOptions extends SharedOptions { } /** - * Disables the logging of captured requests + * Disables the logging of the intercepted requests * into browser's console. * @default false */ diff --git a/src/browser/utils/deferNetworkRequestsUntil.test.ts b/src/browser/utils/deferNetworkRequestsUntil.test.ts index 8ba23be8a..c5f0e963c 100644 --- a/src/browser/utils/deferNetworkRequestsUntil.test.ts +++ b/src/browser/utils/deferNetworkRequestsUntil.test.ts @@ -31,7 +31,7 @@ test('defers any requests that happen while a given promise is pending', async ( events.push('promise resolved') }) - // Calling this functions captures all requests that happen while + // Calling this functions intercepts all requests that happen while // the given promise is pending, and defers their execution // until the promise is resolved. deferNetworkRequestsUntil(workerPromise) diff --git a/src/core/graphql.ts b/src/core/graphql.ts index bd79d5050..b3409eb7f 100644 --- a/src/core/graphql.ts +++ b/src/core/graphql.ts @@ -68,7 +68,7 @@ function createGraphQLOperationHandler(url: Path) { const standardGraphQLHandlers = { /** - * Captures a GraphQL query by a given name. + * Intercepts a GraphQL query by a given name. * * @example * graphql.query('GetUser', () => { diff --git a/src/core/handlers/RequestHandler.ts b/src/core/handlers/RequestHandler.ts index f3d6269ca..b2216e631 100644 --- a/src/core/handlers/RequestHandler.ts +++ b/src/core/handlers/RequestHandler.ts @@ -120,7 +120,7 @@ export abstract class RequestHandler< } /** - * Determine if the captured request should be mocked. + * Determine if the intercepted request should be mocked. */ abstract predicate( request: Request, @@ -138,7 +138,7 @@ export abstract class RequestHandler< ): void /** - * Parse the captured request to extract additional information from it. + * Parse the intercepted request to extract additional information from it. * Parsed result is then exposed to other methods of this request handler. */ async parse( diff --git a/src/core/utils/request/onUnhandledRequest.test.ts b/src/core/utils/request/onUnhandledRequest.test.ts index 48c0123cd..5649ea866 100644 --- a/src/core/utils/request/onUnhandledRequest.test.ts +++ b/src/core/utils/request/onUnhandledRequest.test.ts @@ -12,7 +12,7 @@ const resolver: ResponseResolver = () => void 0 const fixtures = { warningWithoutSuggestions: `\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /api @@ -20,7 +20,7 @@ If you still wish to intercept this unhandled request, please create a request h Read more: https://mswjs.io/docs/getting-started/mocks`, errorWithoutSuggestions: `\ -[MSW] Error: captured a request without a matching request handler: +[MSW] Error: intercepted a request without a matching request handler: • GET /api @@ -28,7 +28,7 @@ If you still wish to intercept this unhandled request, please create a request h Read more: https://mswjs.io/docs/getting-started/mocks`, warningWithSuggestions: (suggestions: string) => `\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /api diff --git a/src/core/utils/request/onUnhandledRequest.ts b/src/core/utils/request/onUnhandledRequest.ts index 3230bbcdf..89a571360 100644 --- a/src/core/utils/request/onUnhandledRequest.ts +++ b/src/core/utils/request/onUnhandledRequest.ts @@ -188,7 +188,7 @@ export async function onUnhandledRequest( const handlerSuggestion = generateHandlerSuggestion() const messageTemplate = [ - `captured a request without a matching request handler:`, + `intercepted a request without a matching request handler:`, ` \u2022 ${requestHeader}`, handlerSuggestion, `\ diff --git a/test/browser/graphql-api/anonymous-operation.test.ts b/test/browser/graphql-api/anonymous-operation.test.ts index c5702e34f..efc6a2479 100644 --- a/test/browser/graphql-api/anonymous-operation.test.ts +++ b/test/browser/graphql-api/anonymous-operation.test.ts @@ -67,7 +67,7 @@ test('does not warn on anonymous GraphQL operation when no GraphQL handlers are // This has nothing to do with the operation being anonymous. expect(consoleSpy.get('warning')).toEqual([ `\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • anonymous query (POST ${endpointUrl}) @@ -76,7 +76,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`, ]) }) - // // Must print the warning because anonymous operations cannot be captured + // // Must print the warning because anonymous operations cannot be intercepted // // using standard "graphql.query()" and "graphql.mutation()" handlers. // await waitFor(() => { // expect(consoleSpy.get('warning')).toEqual( @@ -205,6 +205,6 @@ test('does not print a warning on anonymous GraphQL operation handled by "graphq }) // Must not print any warnings because a permissive "graphql.operation()" - // handler was used to capture and mock the anonymous GraphQL operation. + // handler was used to intercept and mock the anonymous GraphQL operation. expect(consoleSpy.get('warning')).toBeUndefined() }) diff --git a/test/browser/graphql-api/mutation.test.ts b/test/browser/graphql-api/mutation.test.ts index 791f9ccbf..4a5a9af77 100644 --- a/test/browser/graphql-api/mutation.test.ts +++ b/test/browser/graphql-api/mutation.test.ts @@ -49,7 +49,7 @@ test('sends a mocked response to a GraphQL mutation', async ({ }) }) -test('prints a warning when captured an anonymous GraphQL mutation', async ({ +test('prints a warning when intercepted an anonymous GraphQL mutation', async ({ loadExample, spyOnConsole, query, diff --git a/test/browser/graphql-api/query.test.ts b/test/browser/graphql-api/query.test.ts index 44d3244b9..b1dbc6171 100644 --- a/test/browser/graphql-api/query.test.ts +++ b/test/browser/graphql-api/query.test.ts @@ -85,7 +85,7 @@ test('mocks a GraphQL query issued with a POST request', async ({ }) }) -test('prints a warning when captured an anonymous GraphQL query', async ({ +test('prints a warning when intercepted an anonymous GraphQL query', async ({ loadExample, spyOnConsole, query, diff --git a/test/browser/msw-api/setup-worker/fallback-mode/fallback-mode.test.ts b/test/browser/msw-api/setup-worker/fallback-mode/fallback-mode.test.ts index a5fcfe8f5..b1ffc8bb4 100644 --- a/test/browser/msw-api/setup-worker/fallback-mode/fallback-mode.test.ts +++ b/test/browser/msw-api/setup-worker/fallback-mode/fallback-mode.test.ts @@ -144,7 +144,7 @@ test('warns on the unhandled request by default', async ({ expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET ${server.http.url('/unknown-resource')} diff --git a/test/browser/msw-api/setup-worker/start/on-unhandled-request/callback-print.test.ts b/test/browser/msw-api/setup-worker/start/on-unhandled-request/callback-print.test.ts index de8f756e8..da68cdfbe 100644 --- a/test/browser/msw-api/setup-worker/start/on-unhandled-request/callback-print.test.ts +++ b/test/browser/msw-api/setup-worker/start/on-unhandled-request/callback-print.test.ts @@ -24,7 +24,7 @@ test('executes a default "warn" strategy in a custom callback', async ({ expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET https://mswjs.io/use-warn @@ -58,7 +58,7 @@ test('executes a default "error" strategy in a custom callback', async ({ expect(consoleSpy.get('error')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Error: captured a request without a matching request handler: +[MSW] Error: intercepted a request without a matching request handler: • GET https://mswjs.io/use-error diff --git a/test/browser/msw-api/setup-worker/start/on-unhandled-request/default.test.ts b/test/browser/msw-api/setup-worker/start/on-unhandled-request/default.test.ts index 46cafea89..ebaff06b9 100644 --- a/test/browser/msw-api/setup-worker/start/on-unhandled-request/default.test.ts +++ b/test/browser/msw-api/setup-worker/start/on-unhandled-request/default.test.ts @@ -14,7 +14,7 @@ test('warns on unhandled requests by default', async ({ expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringMatching( - /\[MSW\] Warning: captured a request without a matching request handler/, + /\[MSW\] Warning: intercepted a request without a matching request handler/, ), ]), ) diff --git a/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.graphql.test.ts b/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.graphql.test.ts index 1bbdfd001..77bd1c96c 100644 --- a/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.graphql.test.ts +++ b/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.graphql.test.ts @@ -46,7 +46,7 @@ test.describe('GraphQL API', () => { expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • query PaymentHistory (POST /graphql) @@ -92,7 +92,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • query GetUsers (POST /graphql) @@ -140,7 +140,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • query SubmitCheckout (POST /graphql) @@ -188,7 +188,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • query ActiveUsers (POST /graphql) diff --git a/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.rest.test.ts b/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.rest.test.ts index 0bef29269..cec86e941 100644 --- a/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.rest.test.ts +++ b/test/browser/msw-api/setup-worker/start/on-unhandled-request/suggestions.rest.test.ts @@ -32,7 +32,7 @@ test.describe('REST API', () => { expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /user-details @@ -61,7 +61,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /users @@ -97,7 +97,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • POST /users @@ -131,7 +131,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`), expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /pamyents diff --git a/test/browser/msw-api/setup-worker/start/on-unhandled-request/warn.test.ts b/test/browser/msw-api/setup-worker/start/on-unhandled-request/warn.test.ts index 2a5502de4..7c6a68830 100644 --- a/test/browser/msw-api/setup-worker/start/on-unhandled-request/warn.test.ts +++ b/test/browser/msw-api/setup-worker/start/on-unhandled-request/warn.test.ts @@ -15,7 +15,7 @@ test('warns on an unhandled REST API request with an absolute URL', async ({ expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET https://mswjs.io/non-existing-page @@ -40,7 +40,7 @@ test('warns on an unhandled REST API request with a relative URL', async ({ expect(consoleSpy.get('warning')).toEqual( expect.arrayContaining([ expect.stringContaining(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET /user-details @@ -65,7 +65,7 @@ test('does not warn on request which handler explicitly returns no mocked respon expect(consoleSpy.get('warning')).toEqual( expect.not.arrayContaining([ expect.stringContaining( - '[MSW] Warning: captured a request without a matching request handler', + '[MSW] Warning: intercepted a request without a matching request handler', ), ]), ) @@ -86,7 +86,7 @@ test('does not warn on request which handler implicitly returns no mocked respon expect(consoleSpy.get('warning')).toEqual( expect.not.arrayContaining([ expect.stringContaining( - '[MSW] Warning: captured a request without a matching request handler', + '[MSW] Warning: intercepted a request without a matching request handler', ), ]), ) diff --git a/test/browser/msw-api/setup-worker/start/quiet.test.ts b/test/browser/msw-api/setup-worker/start/quiet.test.ts index 0d4e3c61d..12d1e830e 100644 --- a/test/browser/msw-api/setup-worker/start/quiet.test.ts +++ b/test/browser/msw-api/setup-worker/start/quiet.test.ts @@ -7,7 +7,7 @@ declare namespace window { } } -test('does not log the captured request when the "quiet" option is set to "true"', async ({ +test('does not log the intercepted request when the "quiet" option is set to "true"', async ({ loadExample, spyOnConsole, page, diff --git a/test/browser/rest-api/cookies-request.mocks.ts b/test/browser/rest-api/cookies-request.mocks.ts index 06ba33770..18b89e3e2 100644 --- a/test/browser/rest-api/cookies-request.mocks.ts +++ b/test/browser/rest-api/cookies-request.mocks.ts @@ -2,7 +2,7 @@ import { http, HttpResponse } from 'msw' import { setupWorker } from 'msw/browser' const worker = setupWorker( - // Use wildcard so that we capture any "GET /user" requests + // Use wildcard so that we intercept any "GET /user" requests // regardless of the origin, and can assert "same-origin" credentials. http.get('*/user', ({ cookies }) => { return HttpResponse.json({ cookies }) diff --git a/test/browser/rest-api/logging.test.ts b/test/browser/rest-api/logging.test.ts index a0ef1b8bc..ff230dce8 100644 --- a/test/browser/rest-api/logging.test.ts +++ b/test/browser/rest-api/logging.test.ts @@ -2,7 +2,7 @@ import { test, expect } from '../playwright.extend' import { StatusCodeColor } from '../../../src/core/utils/logging/getStatusCodeColor' import { waitFor } from '../../support/waitFor' -test('prints a captured request info into browser console', async ({ +test('prints the intercepted request info into browser console', async ({ loadExample, spyOnConsole, fetch, diff --git a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/callback-throws.node.test.ts b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/callback-throws.node.test.ts index 8a44c0355..c941910c3 100644 --- a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/callback-throws.node.test.ts +++ b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/callback-throws.node.test.ts @@ -16,7 +16,7 @@ beforeAll(() => onUnhandledRequest(request) { /** * @fixme @todo For some reason, the exception from the "onUnhandledRequest" - * callback doesn't propagate to the captured request but instead is thrown + * callback doesn't propagate to the intercepted request but instead is thrown * in this test's context. */ throw new Error(`Custom error for ${request.method} ${request.url}`) diff --git a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/default.node.test.ts b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/default.node.test.ts index 53e0f121f..460c85e6b 100644 --- a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/default.node.test.ts +++ b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/default.node.test.ts @@ -30,7 +30,7 @@ test('warns on unhandled requests by default', async () => { expect(console.error).not.toBeCalled() expect(console.warn).toBeCalledWith(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET https://test.mswjs.io/ diff --git a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/error.node.test.ts b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/error.node.test.ts index 47658b1ed..c6bb16f9f 100644 --- a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/error.node.test.ts +++ b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/error.node.test.ts @@ -62,7 +62,7 @@ test('errors on unhandled request when using the "error" value', async () => { `request to ${endpointUrl} failed, reason: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.`, ) expect(console.error) - .toHaveBeenCalledWith(`[MSW] Error: captured a request without a matching request handler: + .toHaveBeenCalledWith(`[MSW] Error: intercepted a request without a matching request handler: • GET ${endpointUrl} diff --git a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/warn.node.test.ts b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/warn.node.test.ts index 091864ce0..28fd440f9 100644 --- a/test/node/msw-api/setup-server/scenarios/on-unhandled-request/warn.node.test.ts +++ b/test/node/msw-api/setup-server/scenarios/on-unhandled-request/warn.node.test.ts @@ -26,7 +26,7 @@ test('warns on unhandled request when using the "warn" value', async () => { expect(res).toHaveProperty('status', 404) expect(console.warn).toBeCalledWith(`\ -[MSW] Warning: captured a request without a matching request handler: +[MSW] Warning: intercepted a request without a matching request handler: • GET https://test.mswjs.io/