Sha256: a8589c3c04a8ed5464b3db54921f373445946f5787f6e6ca77670fe21804c784

Contents?: true

Size: 1.13 KB

Versions: 26

Compression:

Stored size: 1.13 KB

Contents

import { RequiredDeep } from '~/core/typeUtils'
import { mergeRight } from '~/core/utils/internal/mergeRight'
import {
  SetupWorker,
  SetupWorkerInternalContext,
  StartHandler,
  StartOptions,
} from '../../glossary'

export const DEFAULT_START_OPTIONS: RequiredDeep<StartOptions> = {
  serviceWorker: {
    url: '/mockServiceWorker.js',
    options: null as any,
  },
  quiet: false,
  waitUntilReady: true,
  onUnhandledRequest: 'warn',
  findWorker(scriptURL, mockServiceWorkerUrl) {
    return scriptURL === mockServiceWorkerUrl
  },
}

/**
 * Returns resolved worker start options, merging the default options
 * with the given custom options.
 */
export function resolveStartOptions(
  initialOptions?: StartOptions,
): RequiredDeep<StartOptions> {
  return mergeRight(
    DEFAULT_START_OPTIONS,
    initialOptions || {},
  ) as RequiredDeep<StartOptions>
}

export function prepareStartHandler(
  handler: StartHandler,
  context: SetupWorkerInternalContext,
): SetupWorker['start'] {
  return (initialOptions) => {
    context.startOptions = resolveStartOptions(initialOptions)
    return handler(context.startOptions, initialOptions || {})
  }
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.ts