Chore: Initialize Cypress tests (#1078)
Addresses: #412 Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
22
spec/cypress/app_commands/activerecord_fixtures.rb
Normal file
22
spec/cypress/app_commands/activerecord_fixtures.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# you can delete this file if you don't use Rails Test Fixtures
|
||||
|
||||
fixtures_dir = command_options.try(:[], 'fixtures_dir')
|
||||
fixture_files = command_options.try(:[], 'fixtures')
|
||||
|
||||
if defined?(ActiveRecord)
|
||||
require 'active_record/fixtures'
|
||||
|
||||
fixtures_dir ||= ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
||||
fixture_files ||= Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] }
|
||||
|
||||
logger.debug "loading fixtures: { dir: #{fixtures_dir}, files: #{fixture_files} }"
|
||||
ActiveRecord::FixtureSet.reset_cache
|
||||
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
||||
'Fixtures Done' # this gets returned
|
||||
else # this else part can be removed
|
||||
logger.error 'Looks like activerecord_fixtures has to be modified to suite your need'
|
||||
Post.create(title: 'MyCypressFixtures')
|
||||
Post.create(title: 'MyCypressFixtures2')
|
||||
Post.create(title: 'MyRailsFixtures')
|
||||
Post.create(title: 'MyRailsFixtures2')
|
||||
end
|
||||
10
spec/cypress/app_commands/clean.rb
Normal file
10
spec/cypress/app_commands/clean.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
if defined?(DatabaseCleaner)
|
||||
# cleaning the database using database_cleaner
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
DatabaseCleaner.clean
|
||||
else
|
||||
logger.warn 'add database_cleaner or update cypress/app_commands/clean.rb'
|
||||
Post.delete_all if defined?(Post)
|
||||
end
|
||||
|
||||
Rails.logger.info 'APPCLEANED' # used by log_fail.rb
|
||||
1
spec/cypress/app_commands/eval.rb
Normal file
1
spec/cypress/app_commands/eval.rb
Normal file
@@ -0,0 +1 @@
|
||||
Kernel.eval(command_options) unless command_options.nil?
|
||||
12
spec/cypress/app_commands/factory_bot.rb
Normal file
12
spec/cypress/app_commands/factory_bot.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
Array.wrap(command_options).map do |factory_options|
|
||||
factory_method = factory_options.shift
|
||||
begin
|
||||
logger.debug "running #{factory_method}, #{factory_options}"
|
||||
CypressOnRails::SmartFactoryWrapper.public_send(factory_method, *factory_options)
|
||||
rescue StandardError => e
|
||||
logger.error "#{e.class}: #{e.message}"
|
||||
logger.error e.backtrace.join("\n")
|
||||
logger.error e.record.inspect.to_s if e.is_a?(ActiveRecord::RecordInvalid)
|
||||
raise e
|
||||
end
|
||||
end
|
||||
1
spec/cypress/app_commands/load_seed.rb
Normal file
1
spec/cypress/app_commands/load_seed.rb
Normal file
@@ -0,0 +1 @@
|
||||
Rails.application.load_seed
|
||||
23
spec/cypress/app_commands/log_fail.rb
Normal file
23
spec/cypress/app_commands/log_fail.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# This file is called when a cypress spec fails and allows for extra logging to be captured
|
||||
filename = command_options.fetch('runnable_full_title', 'no title').gsub(/[^[:print:]]/, '')
|
||||
|
||||
# grab last lines until "APPCLEANED" (Make sure in clean.rb to log the text "APPCLEANED")
|
||||
system "tail -n 10000 -r log/#{Rails.env}.log | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'"
|
||||
|
||||
# create a json debug file for server debugging
|
||||
json_result = {}
|
||||
json_result['error'] = command_options.fetch('error_message', 'no error message')
|
||||
|
||||
if defined?(ActiveRecord::Base)
|
||||
json_result['records'] =
|
||||
ActiveRecord::Base.descendants.each_with_object({}) do |record_class, records|
|
||||
records[record_class.to_s] = record_class.limit(100).map(&:attributes)
|
||||
rescue StandardError => e
|
||||
Rails.logger.info e.message
|
||||
end
|
||||
end
|
||||
|
||||
filename = command_options.fetch('runnable_full_title', 'no title').gsub(/[^[:print:]]/, '')
|
||||
File.open(Rails.root.join("log/#{filename}.json"), 'w+') do |file|
|
||||
file << JSON.pretty_generate(json_result)
|
||||
end
|
||||
1
spec/cypress/app_commands/scenarios/default.rb
Normal file
1
spec/cypress/app_commands/scenarios/default.rb
Normal file
@@ -0,0 +1 @@
|
||||
Rails.application.load_seed
|
||||
Reference in New Issue
Block a user