example-page.cy.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { checkErrors } from '../support';
  2. const PLUGIN_TEMPLATE_NAME = 'console-plugin-template';
  3. const PLUGIN_TEMPLATE_PULL_SPEC = Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC');
  4. export const isLocalDevEnvironment =
  5. Cypress.config('baseUrl').includes('localhost');
  6. const installHelmChart = (path: string) => {
  7. cy.exec(
  8. `cd ../../console-plugin-template && ${path} upgrade -i ${PLUGIN_TEMPLATE_NAME} charts/openshift-console-plugin -n ${PLUGIN_TEMPLATE_NAME} --create-namespace --set plugin.image=${PLUGIN_TEMPLATE_PULL_SPEC}`,
  9. {
  10. failOnNonZeroExit: false,
  11. timeout: 300000,
  12. },
  13. ).then((result) => {
  14. cy.visit(`/example`);
  15. cy.log('Error installing helm chart: ', result.stderr);
  16. cy.log('Successfully installed helm chart: ', result.stdout);
  17. });
  18. };
  19. const deleteHelmChart = (path: string) => {
  20. cy.exec(
  21. `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  22. {
  23. failOnNonZeroExit: false,
  24. },
  25. ).then((result) => {
  26. cy.log('Error uninstalling helm chart: ', result.stderr);
  27. cy.log('Successfully uninstalled helm chart: ', result.stdout);
  28. });
  29. };
  30. // Adding this to further debug the failing test issues in CI
  31. describe('My First Test without installing hel chart', () => {
  32. it('Does not do much! Should pass', () => {
  33. expect(true).to.equal(true);
  34. });
  35. it('Does not do much! Should fail', () => {
  36. expect(true).to.equal(false);
  37. });
  38. });
  39. if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC')) {
  40. describe('Console plugin template test', () => {
  41. before(() => {
  42. cy.login();
  43. if (!isLocalDevEnvironment) {
  44. console.log('this is not a local env, installig helm');
  45. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  46. failOnNonZeroExit: false,
  47. }).then((result) => {
  48. cy.log('Error installing helm binary: ', result.stderr);
  49. cy.log(
  50. 'Successfully installed helm binary in "/tmp" directory: ',
  51. result.stdout,
  52. );
  53. installHelmChart('/tmp/helm');
  54. });
  55. } else {
  56. console.log('this is a local env, not installing helm');
  57. installHelmChart('helm');
  58. }
  59. });
  60. afterEach(() => {
  61. checkErrors();
  62. cy.logout();
  63. });
  64. after(() => {
  65. cy.logout();
  66. if (!isLocalDevEnvironment) {
  67. deleteHelmChart('/tmp/helm');
  68. } else {
  69. deleteHelmChart('helm');
  70. }
  71. });
  72. it('Does not do much! Should pass', () => {
  73. expect(true).to.equal(true);
  74. });
  75. it('Verify the example page title', () => {
  76. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  77. cy.get('[data-test="nav"]').contains('Plugin Example').click();
  78. cy.url().should('include', '/example');
  79. cy.get('[data-test="example-page-title"]').should(
  80. 'contain',
  81. 'Hello, Plugin!',
  82. );
  83. });
  84. it('Does not do much! Should fail', () => {
  85. expect(true).to.equal(false);
  86. });
  87. });
  88. }