How to use the k6.check function in k6

To help you get started, we’ve selected a few k6 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 vendure-ecommerce / vendure / packages / dev-server / load-testing / scripts / search-and-checkout.js View on Github external
function setShippingAddressAndCustomer() {
    const result = setShippingAddressMutation.post({
        address: {
            countryCode: 'GB',
            streetLine1: '123 Test Street',
        },
        customer: {
            emailAddress: `test-user-${Math.random().toString(32).substr(3)}@mail.com`,
            firstName: `Test`,
            lastName: `User`,
        },
    });
    check(result.data, {
        'Address set': r => r.setOrderShippingAddress.shippingAddress.country === 'United Kingdom',
    });
}
github vendure-ecommerce / vendure / packages / dev-server / load-testing / scripts / search-and-checkout.js View on Github external
export default function() {
    const itemsToAdd = Math.ceil(Math.random() * 10);

    for (let i = 0; i < itemsToAdd; i ++) {
        searchProducts();
        const product = findAndLoadProduct();
        addToCart(randomItem(product.variants).id);
    }
    setShippingAddressAndCustomer();
    const data = getShippingMethodsQuery.post().data;
    const result = completeOrderMutation.post({ id: data.eligibleShippingMethods[0].id }).data;
    check(result, {
        'Order completed': r => r.addPaymentToOrder.state === 'PaymentAuthorized',
    });
}
github vendure-ecommerce / vendure / packages / dev-server / load-testing / scripts / search-and-checkout.js View on Github external
function addToCart(variantId) {
    const qty = Math.ceil(Math.random() * 4);
    const result = addItemToOrderMutation.post({ id: variantId, qty });
    check(result.data, {
        'Product added to cart': r => !!r.addItemToOrder.lines
            .find(l => l.productVariant.id === variantId && l.quantity >= qty),
    });
}
github poetapp / node / tests / stress / createWorks.js View on Github external
export default () => {

  const requestClaim = http.get(`${CLAIM_HOST}`)

  const url = `${NODE_HOST}/works`
  const payload = requestClaim.body
  const params =  { headers: { 'Content-Type': 'application/json' } }
  const work = http.post(url, payload, params)

  check(work, {
    'status 202': (r) => r.status === 202
  })

  sleep(1 + parseInt(DELAY_GET_WORK))

  const id = JSON.parse(work.request.body).id
  const urlGetWork = `${NODE_HOST}/works/${id}`
  const res = http.get(urlGetWork)

  check(res, {
    'status 200': (r) => r.status === 200
  })

  sleep(1)
}
github h5bp / server-configs-test / lib / benchmark.js View on Github external
export default function () {
  check(http.get('http://server.localhost/test.html'), {
    'is status 200': (r) => r.status === 200
  })
}
github loadimpact / postman-to-k6 / lib / shim / core.js View on Github external
test (name, logic) {
    if (state.test) {
      throw new Error('Nested pm.test calls not allowed')
    }
    try {
      enterTest()
      logic()
      k6.check(store.response, { [name]: response => {
        for (const test of store.test) {
          if (!test(response)) {
            return false
          }
        }
        return true
      } })
    } catch (error) {
      const AssertionError = postman[Extend].AssertionError
      if (AssertionError && error instanceof AssertionError) {
        k6.check(null, { [name]: () => false })
      } else {
        throw error
      }
    } finally {
      exitTest()
github jembi / hearth / performance / volume.js View on Github external
const makeGetRequest = () => {
  const response = http.get(`${BASE_URL}${RESOURCE_PATH}`,
    {
      headers: {
        Accept: 'application/json'
      },
      tags: {
        name: 'Get resource request'
      }
    })

  check(response, {
    'status code is 200': r => r.status === 200
  })
}
github jembi / hearth / performance / patient-create-stress.js View on Github external
const makePostRequest = () => {
  const response = http.post(`${BASE_URL}${RESOURCE_PATH}`,
    patient,
    {
      headers: {
        'Content-Type': 'application/json'
      },
      tags: {
        name: `Create Patient Stress Test`
      }
    })
  check(response, {
    'status code is 201': r => r.status === 201
  })
}
github jembi / openhim-core-js / performance / transactionsWithFilters.js View on Github external
function makeGetRequestWithDateRangeFilter () {
  const query = encodeURIComponent(`{"request.timestamp":"{\\"$gte\\":${startDate},\\"$lte\\":${endDate}}"}`)
  const response = http.get(
    `${BASE_URL}/transactions?filterLimit=100&filters=${query}`,
    {
      headers: Object.assign(getTestAuthHeaders(), {
        Accept: 'application/json',
        'Content-Type': 'apllication/json'
      }),
      tags: {
        name: 'Transactions with Date Range Filter'
      }
    }
  )
  check(response, {
    'status code is 200': r => r.status === 200
  })
}
github jembi / openhim-core-js / performance / metrics.js View on Github external
function getMetricsByMonth() {
  const res = http.get(
    `${BASE_URL}/metrics/timeseries/month?startDate=2017-01-01&endDate=2017-12-31`,
    {
      headers: Object.assign(getTestAuthHeaders(), {
        Accept: 'application/json'
      }),
      tags: {
        name: 'All metrics by month'
      }
    }
  )
  check(res, {
    'status code is 200': r => r.status === 200
  })
}