Sha256: e0ceb39ed14305a51247e7d4e1b2b027414fc629bedf2c00494049af84a7b99b

Contents?: true

Size: 1.72 KB

Versions: 26

Compression:

Stored size: 1.72 KB

Contents

import { SetupWorkerInternalContext, StartOptions } from '../../glossary'
import {
  DEFAULT_START_OPTIONS,
  resolveStartOptions,
  prepareStartHandler,
} from './prepareStartHandler'

describe('resolveStartOptions', () => {
  test('returns default options given no custom start options', () => {
    expect(resolveStartOptions()).toEqual(DEFAULT_START_OPTIONS)
    expect(resolveStartOptions(undefined)).toEqual(DEFAULT_START_OPTIONS)
    expect(resolveStartOptions({})).toEqual(DEFAULT_START_OPTIONS)
  })

  test('deeply merges the default and custom start options', () => {
    expect(
      resolveStartOptions({
        quiet: true,
        serviceWorker: {
          url: './custom.js',
        },
      }),
    ).toEqual({
      ...DEFAULT_START_OPTIONS,
      quiet: true,
      serviceWorker: {
        url: './custom.js',
        options: null,
      },
    })
  })
})

describe('prepareStartHandler', () => {
  test('exposes resolved start options to the generated star handler', () => {
    const createStartHandler = vi.fn()
    const context: SetupWorkerInternalContext = {} as any
    const startHandler = prepareStartHandler(createStartHandler, context)
    expect(startHandler).toBeInstanceOf(Function)

    const initialOptions: StartOptions = {
      quiet: true,
      serviceWorker: {
        url: './custom.js',
      },
    }
    const resolvedOptions = resolveStartOptions(initialOptions)
    startHandler(initialOptions)

    // Calls the handler creator with both resolved and initial options.
    expect(createStartHandler).toHaveBeenCalledWith(
      resolvedOptions,
      initialOptions,
    )

    // Sets the resolved options on the internal context.
    expect(context).toHaveProperty('startOptions', resolvedOptions)
  })
})

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.test.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/msw/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts