diff --git a/README.md b/README.md index 919e235..d6ee026 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,14 @@ end ``` ruby all_on_start: false # Run all specs after changed specs pass. keep_failed: true # Keep failed files until they pass (add them to new ones) -notification: true # Display notification always when jest completes. - # If you want to notify only on failure, set to :failure. cli: nil # Additional command-line options to pass to jest. # Don't use the '-f' or '--format' option here. command: 'jest' # Specify a custom path to the jest command. default_paths: ['**/*.js', '**/*.es6'] # The default paths that will be used for "all_on_start". +notification: true # Display notification always when jest completes. + # If you want to notify only on failure, set to :failed. +print_result: true # Print the output of the jest run. Set to :failed + # if you want to see only for the failed runs ``` ## Contributing diff --git a/lib/guard/jest_runner.rb b/lib/guard/jest_runner.rb index c1d5c0f..77c0084 100644 --- a/lib/guard/jest_runner.rb +++ b/lib/guard/jest_runner.rb @@ -21,10 +21,11 @@ def initialize(options = {}) @options = { all_on_start: false, keep_failed: true, - notification: true, cli: nil, command: 'jest', default_paths: ['**/*.js', '**/*.es6'], + notification: true, + print_result: true, }.merge(options) @failed_paths = [] diff --git a/lib/guard/jest_runner/runner.rb b/lib/guard/jest_runner/runner.rb index 0fa7b33..0fad131 100644 --- a/lib/guard/jest_runner/runner.rb +++ b/lib/guard/jest_runner/runner.rb @@ -17,15 +17,23 @@ def initialize(options) def run(paths) paths = options[:default_paths] unless paths - passed = run_for_check(paths) + run_passed = run_for_check(paths) + case options[:notification] when :failed - notify(passed) unless passed + notify(run_passed) unless run_passed + when true + notify(run_passed) + end + + case options[:print_result] + when :failed + puts @check_stderr unless run_passed when true - notify(passed) + puts @check_stderr end - passed + run_passed end def failed_paths @@ -39,9 +47,9 @@ def failed_paths def run_for_check(paths) command = command_for_check(paths) (stdout, stderr, status) = Open3.capture3(*command) - self.check_stdout = stdout - self.check_stderr = stderr - status + @check_stdout = stdout + @check_stderr = stderr + status.success? rescue SystemCallError => e fail "The jest command failed with #{e.message}: `#{command}`" end @@ -50,7 +58,7 @@ def command_for_check(paths) command = [options[:command]] command.concat(args_specified_by_user) - command.concat(['--json', "--outputFile=#{json_file_path}"]) + command.concat(['--json', '--colors', "--outputFile=#{json_file_path}"]) command.concat(paths) end @@ -94,8 +102,8 @@ def result fail "jest JSON output could not be parsed. Output from jest was:\n#{check_stderr}\n#{check_stdout}" end - def notify(passed) - image = passed ? :success : :failed + def notify(run_passed) + image = run_passed ? :success : :failed Notifier.notify(summary_text, title: 'Jest results', image: image) end diff --git a/lib/guard/jest_runner/version.rb b/lib/guard/jest_runner/version.rb index 1e52880..16de8f8 100644 --- a/lib/guard/jest_runner/version.rb +++ b/lib/guard/jest_runner/version.rb @@ -6,7 +6,7 @@ module Guard module JestRunnerVersion # http://semver.org/ MAJOR = 1 - MINOR = 1 + MINOR = 2 PATCH = 0 def self.to_s