How to use @pollyjs/core - 10 common examples

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 adobe / helix-cli / test / testUpCmd.js View on Github external
describe('Integration test for up command', function suite() {
  this.timeout(20000);
  let testDir;
  let buildDir;
  let testRoot;
  let testModules;

  setupPolly({
    recordFailedRequests: true,
    recordIfMissing: false,
    logging: false,
    adapters: [NodeHttpAdapter],
    persister: FSPersister,
    persisterOptions: {
      fs: {
        recordingsDir: path.resolve(__dirname, 'fixtures/recordings'),
      },
    },
  });

  before(async function beforeAll() {
    this.timeout(60000); // ensure enough time for installing modules on slow machines
    testModules = [await getTestModules(), ...module.paths];
  });
github adobe / helix-cli / test / testPublishCmd.js View on Github external
const FASTLY_AUTH = '----';
  const FASTLY_NAMESPACE = '477rh0E5FeeHKlKx5J3QXd';
  const WSK_AUTH = 'nope';
  const WSK_NAMESPACE = '---';

  this.timeout(50000);

  let testRoot;

  // How to create a new recording:
  // 1. update the `FASTLY_AUTH` with the correct value
  // 2. delete the recording.har file in the `fixtures/recordings` directory
  // 3. set the `recordIfMissing` to `true`
  // 4. run the test
  // 5. reset the `FASTLY_AUTH` and `recordIfMissing` to the original values.
  setupPolly({
    recordFailedRequests: true,
    recordIfMissing: false,
    logging: false,
    adapters: [NodeHttpAdapter],
    persister: FSPersister,
    persisterOptions: {
      fs: {
        recordingsDir: path.resolve(__dirname, 'fixtures/recordings'),
      },
    },
  });

  beforeEach(async () => {
    testRoot = await createTestRoot();
    await fs.copyFile(path.resolve(__dirname, 'fixtures', 'default.yaml'), path.resolve(testRoot, 'helix-config.yaml'));
  });
github gchq / stroom / stroom-ui / src / lib / styleguide / PollyTestServer.tsx View on Github external
* distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import * as uuidv4 from "uuid/v4";
import { connect } from "react-redux";
import { compose, lifecycle } from "recompose";
import { Polly } from "@pollyjs/core";
import FetchAdapter, {
  HttpRequest,
  HttpResponse
} from "@pollyjs/adapter-fetch";

// Register the fetch adapter so its accessible by all future polly instances
Polly.register(FetchAdapter);

import * as JsSearch from "js-search";

import {
  findItem,
  addItemsToTree,
  findByUuids,
  deleteItemsFromTree,
  iterateNodes
} from "../treeUtils";
import { GlobalStoreState } from "../../startup/reducers";
import { actionCreators as fetchActionCreators } from "../fetchTracker.redux";
import withConfig from "../../startup/withConfig";
import { Config } from "../../startup/config";
import { DocRefTypeList } from "../../components/DocRefTypes/redux";
import {
github gchq / stroom / stroom-ui / src / lib / storybook / PollyDecorator.tsx View on Github external
PipelineModelType,
  ElementDefinitions,
  ElementPropertiesByElementIdType,
  Dictionary,
  DataSourceType,
  StreamTaskType,
  User
} from "../../types";
import { StreamAttributeMapResult } from "../../sections/DataViewer/types";
import { DocRefTypeList } from "../../components/DocRefTypes/redux";
import { GlobalStoreState } from "../../startup/reducers";

const { resetAllUrls } = fetchActionCreators;

// Register the fetch adapter so its accessible by all future polly instances
Polly.register(FetchAdapter);

// Whats this?
// export const DevServerDecorator = (storyFn: RenderFunction) => (
//   {storyFn()}
// );

const testConfig: Config = {
  authenticationServiceUrl: "/authService/authentication/v1",
  authorisationServiceUrl: "/api/authorisation/v1",
  stroomBaseServiceUrl: "http://localhost:9001/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"
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 Netflix / pollyjs / tests / integration / persister-tests.js View on Github external
it('should have the correct metadata', async function() {
    const { recordingId, recordingName, persister } = this.polly;

    this.polly.record();
    await this.fetchRecord();
    await persister.persist();

    const har = await persister.find(recordingId);
    const { _recordingName, creator, entries } = har.log;
    const entry = entries[0];

    expect(_recordingName).to.equal(recordingName);

    expect(creator.name).to.equal('Polly.JS');
    expect(creator.version).to.equal(Polly.VERSION);
    expect(creator.comment).to.equal(
      `${persister.constructor.type}:${persister.constructor.name}`
    );

    expect(entry).to.be.an('object');
    expect(entry._id).to.a('string');
    expect(entry._order).to.equal(0);
  });
github DefinitelyTyped / DefinitelyTyped / types / pollyjs__core / pollyjs__core-tests.ts View on Github external
.removeHeader('Content-Length')
            .removeHeaders(['Content-Type', 'Content-Length']);

        req.removeHeaders(['Content-Type', 'Content-Length']);
        log(req.pathname + JSON.stringify(error));
    });

    await polly.flush();
}

setupMocha();
setupMocha({ recordFailedRequests: false });
setupMocha({ recordFailedRequests: false }, {});
setupMocha.beforeEach();
setupMocha.beforeEach({ recordFailedRequests: true });
setupMocha.afterEach();

setupQunit({});
setupQunit({}, { recordFailedRequests: false });
setupQunit.beforeEach({});
setupQunit.beforeEach({}, { recordFailedRequests: true });
setupQunit.afterEach({});