Skip to content

Commit

Permalink
DEV: Skip prettier in single plugin test if patterns aren't found
Browse files Browse the repository at this point in the history
This reverts d06ca90
It didn't work because yarn doesn't return the original exit code of the failed command.
  • Loading branch information
gschlager committed Jan 2, 2019
1 parent 2fc7d2c commit a474bf9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/tasks/docker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@
# Run tests for a specific plugin (with a plugin mounted from host filesystem):
# docker run -e SKIP_CORE=1 SINGLE_PLUGIN='my-awesome-plugin' -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release

def run_or_fail(command, allowed_exit_codes: [0])
def run_or_fail(command)
pid = Process.spawn(command)
Process.wait(pid)
allowed_exit_codes.include?($?.exitstatus)
$?.exitstatus == 0
end

def run_or_fail_prettier(*patterns)
if patterns.any? { |p| Dir[p].any? }
patterns = patterns.map { |p| "'#{p}'" }.join(' ')
run_or_fail("yarn prettier --list-different #{patterns}")
else
puts "Skipping prettier. Pattern not found."
true
end
end

desc 'Run all tests (JS and code in a standalone environment)'
Expand All @@ -49,7 +59,7 @@ task 'docker:test' do
@good &&= run_or_fail("yarn eslint --ext .es6 plugins/#{ENV['SINGLE_PLUGIN']}")

puts "Listing prettier offenses in #{ENV['SINGLE_PLUGIN']}:"
@good &&= run_or_fail("yarn prettier --list-different 'plugins/#{ENV['SINGLE_PLUGIN']}/**/*.scss' 'plugins/#{ENV['SINGLE_PLUGIN']}/**/*.es6'", allowed_exit_codes: [0, 2])
@good &&= run_or_fail_prettier("plugins/#{ENV['SINGLE_PLUGIN']}/**/*.scss", "plugins/#{ENV['SINGLE_PLUGIN']}/**/*.es6")
else
@good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
@good &&= run_or_fail("yarn eslint app/assets/javascripts test/javascripts") unless ENV["SKIP_CORE"]
Expand All @@ -62,7 +72,7 @@ task 'docker:test' do

unless ENV["SKIP_PLUGINS"]
puts "Listing prettier offenses in plugins:"
@good &&= run_or_fail('yarn prettier --list-different "plugins/**/*.scss" "plugins/**/*.es6"', allowed_exit_codes: [0, 2])
@good &&= run_or_fail('yarn prettier --list-different "plugins/**/*.scss" "plugins/**/*.es6"')
end
end
puts "travis_fold:end:lint" if ENV["TRAVIS"]
Expand Down

0 comments on commit a474bf9

Please sign in to comment.