example-page.spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { execSync } from 'child_process';
  2. import { test, expect } from '@playwright/test';
  3. import { checkErrors } from '../support';
  4. const PLUGIN_TEMPLATE_NAME = 'console-plugin-template';
  5. // Defined in openshift/release ci-operator config as CYPRESS_PLUGIN_TEMPLATE_PULL_SPEC
  6. const PLUGIN_TEMPLATE_PULL_SPEC =
  7. process.env.PLUGIN_TEMPLATE_PULL_SPEC ?? process.env.CYPRESS_PLUGIN_TEMPLATE_PULL_SPEC;
  8. const isLocalDevEnvironment = (process.env.BRIDGE_BASE_ADDRESS ?? 'http://localhost:9000').includes(
  9. 'localhost',
  10. );
  11. function exec(command: string, timeoutMs = 360000) {
  12. try {
  13. return execSync(command, { timeout: timeoutMs, encoding: 'utf-8' });
  14. } catch (e) {
  15. console.error('Command failed:', command, e);
  16. return '';
  17. }
  18. }
  19. function installHelmChart(helmPath: string) {
  20. const result = exec(
  21. `${helmPath} upgrade -i ${PLUGIN_TEMPLATE_NAME} charts/openshift-console-plugin -n ${PLUGIN_TEMPLATE_NAME} --create-namespace --set plugin.image=${PLUGIN_TEMPLATE_PULL_SPEC}`,
  22. );
  23. console.log('Helm install:', result);
  24. exec(
  25. `oc rollout status -n ${PLUGIN_TEMPLATE_NAME} deploy/${PLUGIN_TEMPLATE_NAME} -w --timeout=300s`,
  26. );
  27. exec('oc rollout status -w deploy/console -n openshift-console --timeout=300s');
  28. }
  29. function deleteHelmChart(helmPath: string) {
  30. const result = exec(
  31. `${helmPath} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  32. );
  33. console.log('Helm uninstall:', result);
  34. }
  35. test.describe('Console plugin template test', () => {
  36. test.beforeAll(() => {
  37. if (!isLocalDevEnvironment) {
  38. console.log('this is not a local env, installing helm');
  39. exec('./install_helm.sh');
  40. installHelmChart('/tmp/helm');
  41. } else {
  42. console.log('this is a local env, not installing helm');
  43. installHelmChart('helm');
  44. }
  45. });
  46. test.afterEach(async ({ page }) => {
  47. await checkErrors(page);
  48. });
  49. test.afterAll(() => {
  50. if (!isLocalDevEnvironment) {
  51. deleteHelmChart('/tmp/helm');
  52. } else {
  53. deleteHelmChart('helm');
  54. }
  55. });
  56. test('Verify the example page title', async ({ page }) => {
  57. await page.goto('/');
  58. await page.locator('[data-quickstart-id="qs-nav-home"]').click();
  59. await page.getByTestId('nav').getByText('Plugin example').click();
  60. await expect(page).toHaveURL(/\/example/);
  61. await expect(page).toHaveTitle(/Hello, plugin!/);
  62. });
  63. });