pipeline.test.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { beforeEach, describe, expect, test } from "bun:test";
  2. import { generatePipelines } from "./pipeline";
  3. import { setBwcVersionsPath, setSnapshotBwcVersionsPath } from "./bwc-versions";
  4. describe("generatePipelines", () => {
  5. beforeEach(() => {
  6. setBwcVersionsPath(`${import.meta.dir}/mocks/bwcVersions`);
  7. setSnapshotBwcVersionsPath(`${import.meta.dir}/mocks/snapshotBwcVersions`);
  8. process.env["GITHUB_PR_TARGET_BRANCH"] = "test-branch";
  9. process.env["GITHUB_PR_LABELS"] = "test-label-1,test-label-2";
  10. process.env["GITHUB_PR_TRIGGER_COMMENT"] = "";
  11. });
  12. // Helper for testing pipeline generations that should be the same when using the overall ci trigger comment "buildkite test this"
  13. const testWithTriggerCheck = (directory: string, changedFiles?: string[], comment = "buildkite test this") => {
  14. const pipelines = generatePipelines(directory, changedFiles);
  15. expect(pipelines).toMatchSnapshot();
  16. process.env["GITHUB_PR_TRIGGER_COMMENT"] = comment;
  17. const pipelinesWithTriggerComment = generatePipelines(directory, changedFiles);
  18. expect(pipelinesWithTriggerComment).toEqual(pipelines);
  19. };
  20. test("should generate correct pipelines with a non-docs change", () => {
  21. testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
  22. });
  23. test("should generate correct pipelines with only docs changes", () => {
  24. testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["docs/README.asciidoc"]);
  25. });
  26. test("should generate correct pipelines with full BWC expansion", () => {
  27. process.env["GITHUB_PR_LABELS"] = "test-full-bwc";
  28. testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
  29. });
  30. test("should generate correct pipelines with a different branch that is not skipped", () => {
  31. process.env["GITHUB_PR_TARGET_BRANCH"] = "main";
  32. testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
  33. });
  34. test("should generate correct pipeline when using a trigger comment for it", () => {
  35. process.env["GITHUB_PR_TRIGGER_COMMENT"] = "run elasticsearch-ci/using-defaults";
  36. const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
  37. expect(pipelines).toMatchSnapshot();
  38. });
  39. test("should generate correct pipelines with a non-docs change and @elasticmachine", () => {
  40. testWithTriggerCheck(
  41. `${import.meta.dir}/mocks/pipelines`,
  42. ["build.gradle", "docs/README.asciidoc"],
  43. "@elasticmachine test this please"
  44. );
  45. });
  46. test("should generate correct pipelines with a non-docs change and @elasticsearchmachine", () => {
  47. testWithTriggerCheck(
  48. `${import.meta.dir}/mocks/pipelines`,
  49. ["build.gradle", "docs/README.asciidoc"],
  50. "@elasticsearchmachine test this please"
  51. );
  52. });
  53. });