How to use the @pact-foundation/pact-node.createServer function in @pact-foundation/pact-node

To help you get started, we’ve selected a few @pact-foundation/pact-node 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 pact-foundation / pact-js / src / httpPact.ts View on Github external
private createServer(config: PactOptions) {
    this.server = serviceFactory.createServer({
      consumer: this.opts.consumer,
      cors: this.opts.cors,
      dir: this.opts.dir,
      host: this.opts.host,
      log: this.opts.log,
      pactFileWriteMode: this.opts.pactfileWriteMode,
      port: config.port, // allow to be undefined
      provider: this.opts.provider,
      spec: this.opts.spec,
      ssl: this.opts.ssl,
      sslcert: this.opts.sslcert,
      sslkey: this.opts.sslkey,
    })
  }
}
github lucasmajerowicz / pact-node-example / app / client / spec / PostServiceClient.spec.js View on Github external
describe('Pact', () => {
    let provider;

    // Configure mock server
    const mockServer = wrapper.createServer({
        port: 1234,
        log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
        dir: path.resolve(process.cwd(), 'pacts'),
        spec: 2
    });

    // Define expected payloads
    const expectedBodyPostList = {
        posts: [
            {id: 1, date: '01/10/2016', contents: 'Bla bla bla'},
            {id: 2, date: '01/09/2016', contents: 'Microservice microservice'}
        ]
    };

    const expectedBodyPostGet = {
        post: {id: 1, date: '01/08/2016', contents: 'Bla'}
github pact-foundation / pact-js-mocha / test / specHelper.js View on Github external
'use strict'

var path = require('path')
var wrapper = require('@pact-foundation/pact-node')

var mockServer = wrapper.createServer({
  port: 1234,
  log: path.resolve(process.cwd(), 'logs', 'mockserver-ui.log'),
  dir: path.resolve(process.cwd(), 'pacts'),
  spec: 2
})

mockServer.start().then(function () {
  run()

  process.on('SIGINT', function () {
    wrapper.removeAllServers()
  })
})
github pact-foundation / pact-js / test / dsl / integration_default_port.spec.js View on Github external
describe('Pact default Port', () => {

  const MOCK_PORT = 1234
  const PORT = Math.floor(Math.random() * 999) + 9000
  const PROVIDER_URL = `http://localhost:${PORT}`
  const mockServer = wrapper.createServer({
    port: MOCK_PORT,
    log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
    dir: path.resolve(process.cwd(), 'pacts'),
    spec: 2
  })
  const interceptor = new Interceptor(`http://localhost:${MOCK_PORT}`)
  const EXPECTED_BODY = [{
    id: 1,
    name: 'Project 1',
    due: '2016-02-11T09:46:56.023Z',
    tasks: [
      {id: 1, name: 'Do the laundry', 'done': true},
      {id: 2, name: 'Do the dishes', 'done': false},
      {id: 3, name: 'Do the backyard', 'done': false},
      {id: 4, name: 'Do nothing', 'done': false}
    ]
github pact-foundation / pact-js / src / pact.ts View on Github external
constructor(config: PactOptions) {
    this.opts = Pact.createOptionsWithDefaults(config);

    if (isEmpty(this.opts.consumer)) {
      throw new Error("You must specify a Consumer for this pact.");
    }

    if (isEmpty(this.opts.provider)) {
      throw new Error("You must specify a Provider for this pact.");
    }

    this.server = serviceFactory.createServer({
      cors: this.opts.cors,
      dir: this.opts.dir,
      host: this.opts.host,
      log: this.opts.log,
      port: this.opts.port,
      spec: this.opts.spec,
      ssl: this.opts.ssl,
      sslcert: this.opts.sslcert,
      sslkey: this.opts.sslkey,
    });
    serviceFactory.logLevel(this.opts.logLevel);

    logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider "${this.opts.provider}"
   using mock service on Port: "${this.opts.port}"`);

    this.mockService = new MockService(this.opts.consumer, this.opts.provider, this.opts.port, this.opts.host,
github pact-foundation / pact-js / src / pact.js View on Github external
throw new Error('You must specify a Provider for this pact.')
  }

  const port = opts.port || 1234
  const host = opts.host || '127.0.0.1'
  const ssl = opts.ssl || false
  const sslcert = opts.sslcert || false
  const sslkey = opts.sslkey || false
  const dir = opts.dir || path.resolve(process.cwd(), 'pacts')
  const log = opts.log || path.resolve(process.cwd(), 'logs', 'pact.log')
  const logLevel = opts.logLevel || 'INFO'
  const spec = opts.spec || 2
  const cors = opts.cors || false
  const pactfileWriteMode = opts.pactfileWriteMode || 'overwrite'

  const server = serviceFactory.createServer({
    host: host,
    port: port,
    log: log,
    dir: dir,
    spec: spec,
    ssl: ssl,
    sslcert: sslcert,
    sslkey: sslkey,
    cors: cors
  })
  serviceFactory.logLevel(logLevel)

  logger.info(`Setting up Pact with Consumer "${consumer}" and Provider "${provider}" using mock service on Port: "${port}"`)

  const mockService = new MockService(consumer, provider, port, host, ssl, pactfileWriteMode)
github kununu / pact-cli / src / setupServers.js View on Github external
servers.forEach((specs) => {
    const filteredInteractions = interactions.filter((interaction) => specs.consumer === interaction.consumer &&
        specs.provider === interaction.provider);

    let sslkey = false;
    let sslcert = false;

    if (specs.sslcert && specs.sslkey) {
      sslkey = path.resolve(process.cwd(), specs.sslkey);
      sslcert = path.resolve(process.cwd(), specs.sslcert);
    }

    if (filteredInteractions.length > 0) {
      const mockserver = wrapper.createServer({
        port: specs.port,
        log: args.log_path,
        dir: args.contract_dir,
        spec: specs.spec,
        ssl: specs.ssl,
        sslcert,
        sslkey,
        consumer: specs.consumer,
        provider: specs.provider,
        host: specs.host,
      });

      mockserver.start().then(() => {
        log(`Server for ${specs.provider} -> ${specs.consumer} started on port:${specs.port}`);

        filteredInteractions.forEach((interaction) => {
github pact-foundation / pact-js / src / mocha / index.js View on Github external
var test = new Test(title, function (done) {
        var mockServer = wrapper.createServer({
          port: 1234,
          log: path.resolve(process.cwd(), 'logs', 'mockserver.log'),
          dir: path.resolve(process.cwd(), 'pacts'),
          spec: 2
        })

        mockServer.start()
          .then(function () {
            return pactSuite.pact.verify(pactFn)
          })
          .then(function (data) {
            fn(data, done)
          })
          .catch(function (err) { done(err) })
          .finally(function () {
            mockServer.stop()

@pact-foundation/pact-node

Core of @pact-foundation/pact. You almost certainly don't want to depend on this directly.

MIT
Latest version published 8 months ago

Package Health Score

74 / 100
Full package analysis