Skip to content

Commit

Permalink
docs: use "intercept" instead of "capture"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 4, 2023
1 parent 96caf8a commit 2bcc39c
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}!`)
})
```
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down Expand Up @@ -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:**

Expand Down
4 changes: 2 additions & 2 deletions src/browser/setupWorker/glossary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/browser/utils/deferNetworkRequestsUntil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/handlers/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/request/onUnhandledRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ 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
If you still wish to intercept this unhandled request, please create a request handler for it.
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
If you still wish to intercept this unhandled request, please create a request handler for it.
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
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/request/onUnhandledRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
`\
Expand Down
6 changes: 3 additions & 3 deletions test/browser/graphql-api/anonymous-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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(
Expand Down Expand Up @@ -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()
})
2 changes: 1 addition & 1 deletion test/browser/graphql-api/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/browser/graphql-api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
),
]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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',
),
]),
)
Expand All @@ -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',
),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion test/browser/msw-api/setup-worker/start/quiet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/browser/rest-api/cookies-request.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion test/browser/rest-api/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 2bcc39c

Please sign in to comment.