class Cavendish::Commands::AddTesting

Public Instance Methods

perform() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 4
def perform
  install_dependencies
  add_config_to_package
  @config.use_enzyme? ? add_enzyme_options : add_rn_testing_library_options
  add_example_test_file
end

Private Instance Methods

add_config_to_package() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 17
def add_config_to_package
  inject_to_json_file('package.json', package_configuration)
end
add_enzyme_options() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 21
def add_enzyme_options
  run_in_project("yarn add -D #{enzyme_dependencies.join(' ')}")
  inject_to_json_file('package.json', enzyme_configuration)
end
add_example_test_file() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 30
def add_example_test_file
  copy_template(
    'src/screens/__specs__/HomeScreen.spec.js',
    'src/screens/__specs__/HomeScreen.spec.js'
  )
end
add_rn_testing_library_options() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 26
def add_rn_testing_library_options
  run_in_project("yarn add -D #{rn_testing_library_dependencies.join(' ')}")
end
enzyme_configuration() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 71
def enzyme_configuration
  {
    jest: {
      setupFilesAfterEnv: ['jest-enzyme'],
      testEnvironment: 'enzyme'
    }
  }
end
enzyme_dependencies() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 52
def enzyme_dependencies
  %w[
    enzyme
    enzyme-adapter-react-16
    jest-enzyme
    jest-environment-enzyme
  ]
end
install_dependencies() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 13
def install_dependencies
  run_in_project("yarn add -D #{jest_dependencies.join(' ')}")
end
jest_dependencies() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 37
def jest_dependencies
  %w[
    jest
    fishery
    jest-expo
  ]
end
package_configuration() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 61
def package_configuration
  {
    scripts: { test: 'jest' },
    jest: {
      preset: 'jest-expo',
      transform: { '^.+\\.[jt]sx?$': 'babel-jest' }
    }
  }
end
rn_testing_library_dependencies() click to toggle source
# File lib/cavendish/commands/add_testing.rb, line 45
def rn_testing_library_dependencies
  %w[
    @testing-library/jest-dom
    @testing-library/react-native
  ]
end