pactflow / pact-cypress-adapter

Cypress Pact Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cypress `12.3.0` usage example

teone opened this issue · comments

Hi there,
thanks for creating this plugin!

As per https://docs.cypress.io/guides/tooling/plugins-guide#Using-a-plugin the cypress/plugins/index.js is deprecated after v10, is there an example on how to import this in a later version?

Thanks in advance!

We're using Cypress 12.4.0, here is an example cypress.config.ts file:

import fs from 'fs'
import pactCypressPlugin from '@pactflow/pact-cypress-adapter/dist/plugin'
const { defineConfig } = require('cypress')

export default defineConfig({
  morgan: false,
  chromeWebSecurity: false,
  defaultCommandTimeout: 10000,
  viewportWidth: 1280,
  viewportHeight: 720,
  downloadsFolder: './downloads',
  fixturesFolder: './fixtures',
  screenshotsFolder: './screenshots',
  videosFolder: './videos',
  e2e: {
    specPattern: './e2e/**/*.cy.{js,jsx,ts,tsx}',
    supportFile: './support/e2e.{js,jsx,ts,tsx}',
    screenshotOnRunFailure: false,
    experimentalRunAllSpecs: true,
    video: false,
    setupNodeEvents (on, config) {
      pactCypressPlugin(on, config, fs)

      return config
    },
  },
})

In our /support/index.ts file we have:

import '@pactflow/pact-cypress-adapter'

before(() => {
  cy.setupPact('frontend-e2e', 'api')
  cy.intercept('{BACKEND-API-URL-HERE}**').as('api')
})

after(() => {
  cy.usePactWait(['api'])
})

Seems to work for us. Good luck!

nice @tomardern

we have an open pr to add a cypress 10 example here

#31