index.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /// <reference types="cypress" />
  2. // ***********************************************************
  3. // This example support/index.js is processed and
  4. // loaded automatically before your test files.
  5. //
  6. // This is a great place to put global configuration and
  7. // behavior that modifies Cypress.
  8. //
  9. // You can change the location of this file or turn off
  10. // automatically serving support files with the
  11. // 'supportFile' configuration option.
  12. //
  13. // You can read more here:
  14. // https://on.cypress.io/configuration
  15. // ***********************************************************
  16. // Import commands.js using ES2015 syntax:
  17. import './commands'
  18. Cypress.on('window:before:load', (win) => {
  19. win.handleFromCypress = function (request) {
  20. return fetch(request.url, {
  21. method: request.method,
  22. headers: request.requestHeaders,
  23. body: request.requestBody,
  24. }).then((res) => {
  25. const content =
  26. res.headers.map['content-type'] === 'application/json' ? res.json() : res.text()
  27. return new Promise((resolve) => {
  28. content.then((body) => resolve([res.status, res.headers, body]))
  29. })
  30. })
  31. }
  32. })