Class: NeetoCompliance::CypressConfigVerifier

Inherits:
Base
  • Object
show all
Defined in:
lib/neeto_compliance/verifiers/cypress_config_verifier.rb

Instance Method Summary collapse

Methods inherited from Base

#app_is_exception?, #app_name, #apps_exception_list, #audit, #error_message, #print_description, #process, #verifier_name

Instance Method Details

#auto_correct!Object



15
16
17
18
19
20
21
22
# File 'lib/neeto_compliance/verifiers/cypress_config_verifier.rb', line 15

def auto_correct!
  unless valid?
    @autofix_commands.each do |command|
      puts command
      system command
    end
  end
end

#autofix_suggestionObject



24
25
26
# File 'lib/neeto_compliance/verifiers/cypress_config_verifier.rb', line 24

def autofix_suggestion
  @autofix_commands.join("\n").yellow
end

#cypress_config_filesObject



5
6
7
8
9
10
11
12
13
# File 'lib/neeto_compliance/verifiers/cypress_config_verifier.rb', line 5

def cypress_config_files
  @_cypress_config_files ||= {
    "cypress-tests/package.json" => NeetoCompliance::NeetoCommons.path.join("cypress/package.json"),
    "cypress-tests/cypress/jsconfig.json" => NeetoCompliance::NeetoCommons.path.join("cypress/jsconfig.json"),
    "cypress-tests/cypress/webpack.config.js" => NeetoCompliance::NeetoCommons.path.join("cypress/webpack.config.js"),
    "cypress-tests/cypress/config/cypress.review.json" => NeetoCompliance::NeetoCommons.path.join("cypress/cypress.review.json"),
    "cypress-tests/cypress/resolve.js" => NeetoCompliance::NeetoCommons.path.join("cypress/resolve.js")
  }
end

#same_file?(local_file, common_file) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/neeto_compliance/verifiers/cypress_config_verifier.rb', line 41

def same_file?(local_file, common_file)
  File.exist?(local_file) &&
  `diff #{local_file} #{common_file.to_s}`.empty?
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/neeto_compliance/verifiers/cypress_config_verifier.rb', line 28

def valid?
  @autofix_commands = []

  cypress_config_files.each_pair do |local_file, common_file|
    unless same_file?(local_file, common_file)
      @autofix_commands << "cp #{common_file.to_s} #{local_file}"
      @autofix_commands << "cd cypress-tests && yarn" if local_file == "cypress-tests/package.json"
    end
  end

  @autofix_commands.length == 0
end