Sha256: 92a146153cf042b980ae1d7213f9e30adae7de45d15bb37a9a1f862a6430543e

Contents?: true

Size: 1.34 KB

Versions: 32

Compression:

Stored size: 1.34 KB

Contents

require "test_helper"
require "webpacker/dev_server_runner"

class DevServerRunnerTest < Webpacker::Test
  def setup
    @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
    @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
  end

  def teardown
    ENV["NODE_ENV"] = @original_node_env
    ENV["RAILS_ENV"] = @original_rails_env
  end

  def test_run_cmd_via_node_modules
    cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]

    verify_command(cmd, use_node_modules: true)
  end

  def test_run_cmd_via_yarn
    cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]

    verify_command(cmd, use_node_modules: false)
  end

  private
    def test_app_path
      File.expand_path("test_app", __dir__)
    end

    def verify_command(cmd, use_node_modules: true)
      cwd = Dir.pwd
      Dir.chdir(test_app_path)

      klass = Webpacker::DevServerRunner
      instance = klass.new([])
      mock = Minitest::Mock.new
      mock.expect(:call, nil, [{}, *cmd])

      klass.stub(:new, instance) do
        instance.stub(:node_modules_bin_exist?, use_node_modules) do
          Kernel.stub(:exec, mock) { klass.run([]) }
        end
      end

      mock.verify
    ensure
      Dir.chdir(cwd)
    end
end

Version data entries

32 entries across 32 versions & 3 rubygems

Version Path
webpacker-4.3.0 test/dev_server_runner_test.rb
webpacker-5.1.1 test/dev_server_runner_test.rb
webpacker-5.1.0 test/dev_server_runner_test.rb
webpacker-5.0.1 test/dev_server_runner_test.rb
webpacker-5.0.0 test/dev_server_runner_test.rb
jetpacker-0.4.2 test/dev_server_runner_test.rb
jetpacker-0.4.1 test/dev_server_runner_test.rb
jetpacker-0.4.0 test/dev_server_runner_test.rb
jetpacker-0.3.0 test/dev_server_runner_test.rb
jetpacker-0.2.0 test/dev_server_runner_test.rb
webpacker-4.2.2 test/dev_server_runner_test.rb
webpacker-4.2.1 test/dev_server_runner_test.rb
webpacker-4.2.0 test/dev_server_runner_test.rb
webpacker-4.1.0 test/dev_server_runner_test.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/test/dev_server_runner_test.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/test/dev_server_runner_test.rb
webpacker-4.0.7 test/dev_server_runner_test.rb
webpacker-4.0.6 test/dev_server_runner_test.rb
webpacker-4.0.5 test/dev_server_runner_test.rb
webpacker-4.0.4 test/dev_server_runner_test.rb