How to use the @pollyjs/utils.assert function in @pollyjs/utils

To help you get started, we’ve selected a few @pollyjs/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Netflix / pollyjs / packages / @pollyjs / core / src / polly.js View on Github external
configure(config = {}) {
    const { container } = this;

    assert(
      'Cannot call `configure` once requests have been handled.',
      this._requests.length === 0
    );
    assert(
      'Cannot call `configure` on an instance of Polly that is not running.',
      this.mode !== MODES.STOPPED
    );

    // Disconnect from all current adapters before updating the config
    this.disconnect();

    this.config = mergeConfigs(DefaultConfig, this.config, config);

    // Register and connect to all specified adapters
    this.config.adapters.forEach(adapter => this.connectTo(adapter));

    /* Handle Persister */
    let { persister } = this.config;

    if (persister) {
github Netflix / pollyjs / packages / @pollyjs / core / src / utils / validators.js View on Github external
export function validateRequestConfig(config) {
  assert(
    `Invalid config provided. Expected object, received: "${typeof config}".`,
    isObjectLike(config) && !Array.isArray(config)
  );

  // The following options cannot be overridden on a per request basis
  [
    'mode',
    'adapters',
    'adapterOptions',
    'persister',
    'persisterOptions'
  ].forEach(key =>
    assert(
      `Invalid configuration option provided. The "${key}" option cannot be overridden using the server configuration API.`,
      !(key in config)
    )
github Netflix / pollyjs / packages / @pollyjs / core / src / polly.js View on Github external
this.config = mergeConfigs(DefaultConfig, this.config, config);

    // Register and connect to all specified adapters
    this.config.adapters.forEach(adapter => this.connectTo(adapter));

    /* Handle Persister */
    let { persister } = this.config;

    if (persister) {
      if (typeof persister === 'function') {
        container.register(persister);
        persister = persister.name;
      }

      assert(
        `Persister matching the name \`${persister}\` was not registered.`,
        container.has(`persister:${persister}`)
      );

      this.persister = new (container.lookup(`persister:${persister}`))(this);
    }
  }
github Netflix / pollyjs / packages / @pollyjs / persister / src / index.js View on Github external
static get name() {
    assert('Must override the static `name` getter.');
  }
github Netflix / pollyjs / packages / @pollyjs / core / src / utils / validators.js View on Github external
export function validateRecordingName(name) {
  assert(
    `Invalid recording name provided. Expected string, received: "${typeof name}".`,
    typeof name === 'string'
  );

  assert(
    `Invalid recording name provided. Received An empty or blank string.`,
    name.trim().length > 0
  );
}
github Netflix / pollyjs / packages / @pollyjs / adapter / src / index.js View on Github external
assert(message, ...args) {
    assert(
      `[${this.constructor.type}:${this.constructor.name}] ${message}`,
      ...args
    );
  }
github Netflix / pollyjs / packages / @pollyjs / core / src / -private / event-emitter.js View on Github external
function assertListener(listener) {
  assert(
    `Invalid listener provided. Expected function, received: "${typeof listener}".`,
    typeof listener === 'function'
  );
}
github Netflix / pollyjs / packages / @pollyjs / core / src / -private / event-emitter.js View on Github external
emitSync(eventName, ...args) {
    assertEventName(eventName, this[EVENT_NAMES]);

    const event = new Event(eventName);

    for (const listener of this.listeners(eventName)) {
      const returnValue = listener(...args, event);

      assert(
        `Attempted to emit a synchronous event "${eventName}" but an asynchronous listener was called.`,
        !(isObjectLike(returnValue) && typeof returnValue.then === 'function')
      );

      if (event.shouldStopPropagating) {
        return false;
      }
    }

    return true;
  }
}
github Netflix / pollyjs / packages / @pollyjs / core / src / -private / response.js View on Github external
status(statusCode) {
    const status = parseInt(statusCode, 10);

    assert(
      `[Response] Invalid status code: ${status}`,
      status >= 100 && status < 600
    );

    this.statusCode = status;

    return this;
  }