class Guard::Jest

The Jest guard that gets notifications about the following Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_modifications`.

Constants

DEFAULT_OPTIONS
IGNORED_LINES
VERSION

Attributes

logger[W]
runner[R]
server[R]

Public Class Methods

logger() click to toggle source
# File lib/guard/jest.rb, line 16
def logger
    @logger ||= ( l = Logger.new(STDOUT); l.level = Logger::INFO; l )
end
new(options = {}) click to toggle source

Initialize Guard::Jest

@param [Hash] options the options for the Guard @option options [String] :config_file the location of a Jest configuration file @option options [String] :jest_cmd path to jest application that should be executed

Calls superclass method
# File lib/guard/jest.rb, line 34
def initialize(options = {})
    options = DEFAULT_OPTIONS.merge(options)
    options[:server] = @server = options[:server] || Server.new(options)
    Jest.logger = options[:logger] if options[:logger]
    @runner = options[:runner] || Runner.new(options)
    super(options)
end

Public Instance Methods

reload() click to toggle source

Called when `reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

@raise [:task_has_failed] when reload has failed @return [Object] the task result

# File lib/guard/jest.rb, line 76
def reload
    server_success = server.reload(options)
    runner_success = runner.reload(options)
    throw :task_has_failed unless server_success && runner_success
end
run_all() click to toggle source

Called when just `enter` is pressed This method should be principally used for long action like running all specs/tests/…

@raise [:task_has_failed] when run_all has failed @return [Object] the task result

# File lib/guard/jest.rb, line 88
def run_all
    results = runner.test_all
    throw :task_has_failed if results.failed?
end
run_on_additions(paths) click to toggle source

Called on file(s) additions that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_additions has failed @return [Object] the task result

# File lib/guard/jest.rb, line 99
def run_on_additions(paths)
    run_on_modifications(paths)
end
run_on_modifications(paths) click to toggle source

Called on file(s) modifications that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_modifications has failed @return [Object] the task result

# File lib/guard/jest.rb, line 109
def run_on_modifications(paths)
    results = runner.test_paths(paths)
    throw :task_has_failed if results.failed?
end
run_on_removals(paths) click to toggle source

Called on file(s) removals that the Guard plugin watches.

@param [Array<String>] paths the changes files or paths @raise [:task_has_failed] when run_on_removals has failed @return [Object] the task result

# File lib/guard/jest.rb, line 120
def run_on_removals(paths)
    runner.remove_paths(paths)
end
start() click to toggle source

Called once when Guard starts. Please override initialize method to init stuff.

@raise [:task_has_failed] when start has failed @return [Object] the task result

# File lib/guard/jest.rb, line 47
def start
    throw :task_has_failed unless server.start
    run_all if options[:all_on_start]
    Pry::Commands.block_command "j", "Update Jest snapshots" do | cmd |
        server = Guard.state.session.plugins.all(:jest).first.runner.server
        case cmd
        when 'u' then server.update_snapshots
        else
            Formatter.error("unknown command #{cmd}")
        end

    end
end
stop() click to toggle source

Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).

@raise [:task_has_failed] when stop has failed @return [Object] the task result

# File lib/guard/jest.rb, line 66
def stop
    throw :task_has_failed unless server.stop
end