How to use the mockttp.getLocal function in mockttp

To help you get started, we’ve selected a few mockttp 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 HAECHI-LABS / henesis-cli / src / rpc / integration.spec.ts View on Github external
describe('IntegrationRpc', () => {
  let integrationRpc: IntegrationRpc;
  const mockServer = mockhttp.getLocal();
  // Start your servers
  beforeEach(async () => {
    const url = baseUrl();
    integrationRpc = new IntegrationRpc(url, rpcVersion);
    await mockServer.start(8080);
  });

  afterEach(async () => {
    await mockServer.stop();
  });

  describe('#getIntegrations()', async () => {
    it('should get integration list', async () => {
      const integrations = [newMockIntegration(), newMockIntegration()];
      await mockServer.get('/integrations/v1').thenJson(200, integrations);
      const response: Integration[] = await integrationRpc.getIntegrations();
github dbelob / twitter-emulation / twitter-emulation-spring-boot-angular-web / e2e / src / app.e2e-spec.ts View on Github external
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';

const mockServer = require("mockttp").getLocal();

describe('App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  beforeEach(() => mockServer.start(8080));
  afterEach(() => mockServer.stop());

  it('should display login page', () => {
    mockServer.get("/api/authentication/user").thenReply(200);

    page.navigateTo();
    expect(page.getTitleText()).toEqual('Log in');
github dbelob / guess-game / guess-game-web / e2e / src / app.e2e-spec.ts View on Github external
import { AppPage } from './app.po';

const mockServer = require("mockttp").getLocal();

describe('App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  beforeEach(() => mockServer.start(8080));
  afterEach(() => mockServer.stop());

  it('should display welcome message', () => {
    mockServer.get("/api/state/state").thenReply(200, '"START_STATE"');
    mockServer.get("/api/question/sets").thenReply(200, '[{"id":0,"name":"Question Set 1"},{"id":1,"name":"Question Set 2"},{"id":2,"name":"Question Set 3"}]');
    mockServer.get("/api/question/quantities").withQuery({"questionSetId":"0"}).thenReply(200, '[5,10]');
github HAECHI-LABS / henesis-cli / src / rpc / user.spec.ts View on Github external
describe('UserRpc', (): void => {
  const mockServer = mockhttp.getLocal();
  let userRpc: UserRpc;

  beforeEach(
    async (): Promise => {
      const url = baseUrl();
      userRpc = new UserRpc(url, rpcVersion);
      await mockServer.start(8080);
    },
  );

  afterEach(
    async (): Promise => {
      await mockServer.stop();
    },
  );
github opticdev / optic / api-cli / src / lib / TransparentProxyCaptureSession.ts View on Github external
const certificateInfo = await mockttp.generateCACertificate({
      bits: 2048,
      commonName: 'Optic Labs Corp'
    })
    const certificatePath = path.join(configPath, '.optic', 'certificates')
    await fs.ensureDir(certificatePath);
    const certPath = path.join(certificatePath, 'ca.cert')
    const keyPath = path.join(certificatePath, 'ca.key')
    await fs.writeFile(certPath, certificateInfo.cert)
    await fs.writeFile(keyPath, certificateInfo.key)
    const https = {
      certPath,
      keyPath
    }

    const proxy = mockttp.getLocal({
      cors: true,
      debug: false,
      https,
      recordTraffic: false
    })
    this.proxy = proxy;
    proxy.addRules(
      {
        matchers: [
          new mockttp.matchers.WildcardMatcher()
        ],
        handler: new mockttp.handlers.PassThroughHandler()
      }
    )

    proxy.on('request', (req: mockttp.CompletedRequest) => {
github opticdev / optic / api-cli / src / commands / intercept.ts View on Github external
const certificateInfo = await mockttp.generateCACertificate({
      bits: 2048,
      commonName: 'Optic Labs Corp'
    })
    const certificatePath = path.join(configPath, '.optic', 'certificates')
    await fs.ensureDir(certificatePath)
    const certPath = path.join(certificatePath, 'ca.cert')
    const keyPath = path.join(certificatePath, 'ca.key')
    await fs.writeFile(certPath, certificateInfo.cert)
    await fs.writeFile(keyPath, certificateInfo.key)
    const https = {
      certPath,
      keyPath
    }

    const proxy = mockttp.getLocal({
      cors: true,
      debug: false,
      https,
      recordTraffic: false
    })
    this.proxy = proxy
    proxy.addRules(
      {
        matchers: [
          new mockttp.matchers.HostMatcher('amiusing.httptoolkit.tech')
        ],
        handler: new mockttp.handlers.CallbackHandler(request => {
          const response: CallbackResponseResult = {
            statusCode: 302,
            headers: {
              location: `https://${config.targetHost}`

mockttp

Mock HTTP server for testing HTTP clients and stubbing webservices

Apache-2.0
Latest version published 14 days ago

Package Health Score

83 / 100
Full package analysis