|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "minitest/autorun" |
| 4 | +require "yaml" |
| 5 | + |
| 6 | +class BitrisePipelineTest < Minitest::Test |
| 7 | + def test_e2e_pipeline_uses_expected_graph |
| 8 | + config = load_bitrise_config |
| 9 | + workflows = config.fetch("pipelines").fetch("e2e").fetch("workflows") |
| 10 | + |
| 11 | + assert_equal({}, workflows.fetch("e2e-package-suite")) |
| 12 | + assert_equal({}, workflows.fetch("e2e-build-react-native-ios")) |
| 13 | + assert_equal({}, workflows.fetch("e2e-build-react-native-android")) |
| 14 | + assert_equal [ |
| 15 | + "e2e-package-suite", |
| 16 | + "e2e-build-react-native-ios", |
| 17 | + "e2e-build-react-native-android" |
| 18 | + ], workflows.fetch("e2e-run-browserstack").fetch("depends_on") |
| 19 | + assert_equal "$E2E_RUN_COUNT", workflows.fetch("e2e-run-browserstack").fetch("parallel") |
| 20 | + assert_equal ["e2e-run-browserstack"], workflows.fetch("e2e-report").fetch("depends_on") |
| 21 | + assert_equal "workflow", workflows.fetch("e2e-report").fetch("should_always_run") |
| 22 | + end |
| 23 | + |
| 24 | + def test_e2e_workflows_exist |
| 25 | + config = load_bitrise_config |
| 26 | + workflows = config.fetch("workflows") |
| 27 | + |
| 28 | + expected_workflows.each do |workflow| |
| 29 | + assert workflows.key?(workflow), "missing workflow #{workflow}" |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + def test_pipeline_skeleton_does_not_call_browserstack_yet |
| 34 | + bitrise_yml = File.read("bitrise.yml") |
| 35 | + |
| 36 | + refute_includes bitrise_yml, "api-cloud.browserstack.com" |
| 37 | + refute_includes bitrise_yml, "BROWSERSTACK_USERNAME" |
| 38 | + refute_includes bitrise_yml, "BROWSERSTACK_ACCESS_KEY" |
| 39 | + end |
| 40 | + |
| 41 | + def test_pipeline_uses_intermediate_file_sharing_placeholders |
| 42 | + config = load_bitrise_config |
| 43 | + |
| 44 | + assert_workflow_has_step(config, "e2e-package-suite", "deploy-to-bitrise-io") |
| 45 | + assert_workflow_has_step(config, "e2e-build-react-native-ios", "deploy-to-bitrise-io") |
| 46 | + assert_workflow_has_step(config, "e2e-build-react-native-android", "deploy-to-bitrise-io") |
| 47 | + assert_workflow_has_step(config, "e2e-run-browserstack", "pull-intermediate-files") |
| 48 | + assert_workflow_has_step(config, "e2e-report", "pull-intermediate-files") |
| 49 | + end |
| 50 | + |
| 51 | + def test_dev_up_installs_bitrise_cli |
| 52 | + packages = YAML.safe_load_file("dev.yml").fetch("up").find { |entry| entry.key?("packages") }.fetch("packages") |
| 53 | + |
| 54 | + assert_includes packages, "bitrise" |
| 55 | + end |
| 56 | + |
| 57 | + def test_bitrise_setup_docs_exist |
| 58 | + assert File.exist?("e2e/BITRISE.md") |
| 59 | + end |
| 60 | + |
| 61 | + private |
| 62 | + |
| 63 | + def load_bitrise_config |
| 64 | + YAML.safe_load_file("bitrise.yml") |
| 65 | + end |
| 66 | + |
| 67 | + def expected_workflows |
| 68 | + [ |
| 69 | + "e2e-package-suite", |
| 70 | + "e2e-build-react-native-ios", |
| 71 | + "e2e-build-react-native-android", |
| 72 | + "e2e-run-browserstack", |
| 73 | + "e2e-report" |
| 74 | + ] |
| 75 | + end |
| 76 | + |
| 77 | + def assert_workflow_has_step(config, workflow, step_name) |
| 78 | + steps = config.fetch("workflows").fetch(workflow).fetch("steps") |
| 79 | + step_names = steps.flat_map(&:keys) |
| 80 | + |
| 81 | + assert step_names.any? { |name| name.start_with?(step_name) }, "expected #{workflow} to include #{step_name}" |
| 82 | + end |
| 83 | +end |
0 commit comments