Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Dangerfile « qa_selector « danger - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57f992ec16035fc37a37619156e969626f2232a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

return if helper.stable_branch?

data_testids = /testid|data-testid|find_by_testid|within_testid/

deprecated_qa_selectors = /(?=qa_selector|data-qa-selector)|(?!.*\bdata-qa-)(?=class=.*qa-.*|class: .*qa-.*)/

def filter_changed_lines(files, pattern)
  lines = []
  files.each do |file|
    testid_changed_lines = helper.changed_lines(file).select { |line| line =~ pattern }
    next unless testid_changed_lines.any?

    lines += ["file `#{file}`:", testid_changed_lines]
  end
  lines
end

changed_code_files = helper.changed_files(/\.(vue|haml|js|rb)$/)

return if changed_code_files.empty?

lines_with_testids = filter_changed_lines(changed_code_files, data_testids)

deprecated_qa_class = filter_changed_lines(changed_code_files, deprecated_qa_selectors)

return if (lines_with_testids + deprecated_qa_class).empty?

markdown(<<~MARKDOWN)
  ## Testid Selectors

MARKDOWN

if lines_with_testids.any?
  markdown(<<~MARKDOWN)
    The following changed lines in this MR contain testid selectors:

    * #{lines_with_testids.join("\n* ")}

    If the `e2e:package-and-test` job in the `qa` stage has run automatically, please ensure the tests are passing.
    If the job has not run, please start the `trigger-omnibus-and-follow-up-e2e` job in the `qa` stage and ensure the tests in `follow-up-e2e:package-and-test-ee` pipeline are passing.

    For the list of known failures please refer to [the latest pipeline triage issue](https://gitlab.com/gitlab-org/quality/pipeline-triage/-/issues).

    If your changes are under a feature flag, please check our [Testing with feature flags](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/feature_flags.html#automatic-test-execution-when-a-feature-flag-definition-changes) documentation for instructions.

  MARKDOWN

  warn "This merge request contains lines with testid selectors. Please ensure `e2e:package-and-test` job is run."
end

if deprecated_qa_class.any?
  markdown(<<~MARKDOWN)
    ### Deprecated data-qa-selector

    The following lines in this MR contain deprecated data-qa-selector selectors:

    * #{deprecated_qa_class.join("\n* ")}

    Please ensure all deprecated data-qa-selector attributes are replaced with data-testid attributes in accordance with our [Testing Guide](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/page_objects.html#data-testid-vs-data-qa-selector).

  MARKDOWN

  warn "This merge request contains deprecated data-qa-selector attribute. Please use data-testid attribute instead."
end