index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /// <reference types="cypress" />
  2. // ***********************************************************
  3. // This example plugins/index.js can be used to load plugins
  4. //
  5. // You can change the location of this file or turn off loading
  6. // the plugins file with the 'pluginsFile' configuration option.
  7. //
  8. // You can read more here:
  9. // https://on.cypress.io/plugins-guide
  10. // ***********************************************************
  11. // This function is called when a project is opened or re-opened (e.g. due to
  12. // the project's config changing)
  13. const fs = require('fs');
  14. /**
  15. * @type {Cypress.PluginConfig}
  16. */
  17. // eslint-disable-next-line no-unused-vars
  18. module.exports = (on, config) => {
  19. // `on` is used to hook into various events Cypress emits
  20. // `config` is the resolved Cypress config
  21. // cypress/plugins/index.ts
  22. on('task', {
  23. async 'file:delete'(filename) {
  24. // seed database with test data
  25. fs.unlinkSync(filename);
  26. return true;
  27. },
  28. async 'file:rename'({ oldPath, newPath }) {
  29. fs.renameSync(oldPath, newPath);
  30. return true;
  31. },
  32. async 'file:exist'(filename) {
  33. return fs.existsSync(filename);
  34. },
  35. async 'file:listdir'(path) {
  36. return fs.readdirSync(path);
  37. },
  38. });
  39. // ..
  40. };