How to use the @pollyjs/core.Polly function in @pollyjs/core

To help you get started, we’ve selected a few @pollyjs/core 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 / tests / integration / persister-tests.js View on Github external
const { recordingName, recordingId, config } = this.polly;

    const orderedRecordUrl = order => `${this.recordUrl()}?order=${order}`;

    await this.fetch(orderedRecordUrl(1));
    await this.fetch(orderedRecordUrl(2));
    await this.polly.persister.persist();

    let har = await this.polly.persister.find(recordingId);

    expect(har).to.be.an('object');
    expect(har.log.entries).to.have.lengthOf(2);

    await this.polly.stop();

    this.polly = new Polly(recordingName, config);
    this.polly.replay();
    this.polly.configure({
      persisterOptions: {
        keepUnusedRequests: false
      }
    });

    await this.fetch(orderedRecordUrl(1)); // -> Replay
    await this.fetch(orderedRecordUrl(3)); // -> New recording
    await this.polly.persister.persist();

    har = await this.polly.persister.find(recordingId);

    expect(har).to.be.an('object');
    expect(har.log.entries).to.have.lengthOf(2);
    expect(har.log.entries[0].request.url).to.include(orderedRecordUrl(1));
github gchq / stroom / stroom-ui / src / lib / storybook / PollyDecorator.tsx View on Github external
};
  dictionaries: {
    [dictionaryId: string]: Dictionary;
  };
  trackers: Array;
  dataList: StreamAttributeMapResult;
  dataSource: DataSourceType;
  usersAndGroups: {
    users: Array;
    userGroupMemberships: Array;
  };
}

// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
  adapters: ["fetch"],
  logging: true
});
const { server } = polly;

// The cache acts as a singular global object who's contents are replaced
export interface TestCache {
  data?: TestData;
}

const testCache: TestCache = {};

const startTime = Date.now();

// Hot loading should pass through
github gchq / stroom / stroom-ui / storybook / PollyDecorator.tsx View on Github external
const testConfig = {
  authenticationServiceUrl: "/authService/authentication/v1",
  authorisationServiceUrl: "/api/authorisation/v1",
  stroomBaseServiceUrl: "/api",
  authUsersUiUrl:
    "auth/users/because/they/are/loaded/in/an/iframe/which/is/beyond/scope/of/these/tests",
  authTokensUiUrl:
    "auth/tokens/because/they/are/loaded/in/an/iframe/which/is/beyond/scope/of/these/tests",
  advertisedUrl: "/",
  appClientId: "stroom-ui"
};

// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
  logging: true
});
const { server } = polly;

// The cache acts as a singular global object who's contents are replaced
const testCache = {
  data: {}
};

const startTime = Date.now();

// Hot loading should pass through
server.get("*.hot-update.json").passthrough();

// This is normally deployed as part of the server
github gchq / stroom / stroom-ui / src / lib / styleguide / PollyTestServer.tsx View on Github external
elements: ElementDefinitions;
  elementProperties: ElementPropertiesByElementIdType;
  xslt: {
    [xsltId: string]: string;
  };
  dictionaries: {
    [dictionaryId: string]: Dictionary;
  };
  trackers: Array;
  dataList: StreamAttributeMapResult;
  dataSource: DataSourceType;
}

// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
  adapters: ["fetch"],
  logging: true
});
const { server } = polly;

// The cache acts as a singular global object who's contents are replaced
export interface TestCache {
  data?: TestData;
}

const testCache: TestCache = {};

const startTime = Date.now();

// This is normally deployed as part of the server
github DefinitelyTyped / DefinitelyTyped / types / pollyjs__core / pollyjs__core-tests.ts View on Github external
order: true,

        url: {
            protocol: true,
            username: true,
            password: true,
            hostname: true,
            port: true,
            pathname: true,
            query: true,
            hash: false,
        },
    },
});

new Polly('test recording', {
    mode: 'record',
    expiryStrategy: 'warn',
    recordFailedRequests: true,
    adapters: ['xhr', 'fetch'],
    adapterOptions: {
        xhr: {
            context: {},
        },
        fetch: {
            context: {},
        },
        foo: {
            bar: true,
        },
    },
    persister: 'rest',
github DefinitelyTyped / DefinitelyTyped / types / pollyjs__core / pollyjs__core-tests.ts View on Github external
import { Polly, Timing, setupMocha, setupQunit } from '@pollyjs/core';
import { EXPIRY_STRATEGIES, MODES } from '@pollyjs/utils';

const polly = new Polly('test recording', {
    mode: MODES.PASSTHROUGH,
    recordFailedRequests: true,
    adapters: ['xhr', 'fetch'],
    persister: 'rest',
    expiryStrategy: EXPIRY_STRATEGIES.ERROR,
    timing: Timing.relative(3),
    matchRequestsBy: {
        method: true,
        headers: true,
        body: true,
        order: true,

        url: {
            protocol: true,
            username: true,
            password: true,
github sradevski / aida / packages / consumer-faked-http / fakedHttp.js View on Github external
export default function httpMockApi(routes, baseUri, options = {}) {
  const polly = new Polly('Faked HTTP', {
    adapters: ['xhr', 'fetch'],
    recordIfMissing: false,
    mode: 'passthrough',
  });

  const { server } = polly;
  const normalizedBasedUri = baseUri.endsWith('/')
    ? baseUri.slice(0, -1)
    : baseUri;

  //Polly doesn't support intercept on .any(), so we have to run it on each method separately.
  const handler = (req, res, interceptor) =>
    handleIntercept(req, res, interceptor, routes, normalizedBasedUri, options);

  server.get(`${normalizedBasedUri}/*`).intercept(handler);
  server.put(`${normalizedBasedUri}/*`).intercept(handler);
github Netflix / pollyjs / examples / puppeteer / index.js View on Github external
(async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();

  await page.setRequestInterception(true);

  const polly = new Polly('puppeteer', {
    adapters: ['puppeteer'],
    adapterOptions: { puppeteer: { page } },
    persister: 'fs',
    persisterOptions: {
      fs: {
        recordingsDir: path.join(__dirname, 'recordings')
      }
    }
  });

  const { server } = polly;

  server.host('http://localhost:3000', () => {
    server.get('/favicon.ico').passthrough();
    server.get('/sockjs-node/*').intercept((_, res) => res.sendStatus(200));
  });
github ngx-api-utils / ngx-api-utils / packages / ngx-api-utils / src / lib / ngx-api-utils.spec.ts View on Github external
},
        {
          provide: AUTH_TOKEN_NAME,
          useValue: apiUtilsConfig.authTokenName
        },
        {
          provide: API_HTTP_DEFAULT_HEADERS,
          useValue: apiUtilsConfig.defaultHeaders
        },
        {
          provide: API_HTTP_AUTHORIZATION_HEADER_NAME,
          useValue: apiUtilsConfig.authorizationHeaderName
        }
      ]
    });
    polly = new Polly('ngx-api-utils', {
      adapters: ['xhr', 'fetch']
    });
    localStorage.removeItem(apiUtilsConfig.authTokenName);
  });