Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option print_result is added + tiny bugfixes #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/guard/jest_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
28 changes: 18 additions & 10 deletions lib/guard/jest_runner/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/jest_runner/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Guard
module JestRunnerVersion
# http://semver.org/
MAJOR = 1
MINOR = 1
MINOR = 2
PATCH = 0

def self.to_s
Expand Down