Sha256: 8814f893c9160a8a3f1d4ffa4f810c8e4478d3765e629f67143954320b9368a5

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

require "test_helper"
require "webpacker/webpack_runner"

class WebpackRunnerTest < 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", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]

    verify_command(cmd, use_node_modules: true)
  end

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

    verify_command(cmd, use_node_modules: false)
  end

  def test_run_cmd_argv
    cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"]

    verify_command(cmd, argv: ["--watch"])
  end

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

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

      klass = Webpacker::WebpackRunner
      instance = klass.new(argv)
      mock = Minitest::Mock.new
      mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])

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

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shakapacker-6.5.5 test/webpack_runner_test.rb
shakapacker-6.5.4 test/webpack_runner_test.rb
shakapacker-6.5.3 test/webpack_runner_test.rb
shakapacker-6.5.2 test/webpack_runner_test.rb
shakapacker-6.5.1 test/webpack_runner_test.rb
shakapacker-6.5.0 test/webpack_runner_test.rb
shakapacker-6.4.1 test/webpack_runner_test.rb
shakapacker-6.4.0 test/webpack_runner_test.rb
shakapacker-6.3.0 test/webpack_runner_test.rb
shakapacker-6.3.0.pre.rc.1 test/webpack_runner_test.rb
shakapacker-6.2.1 test/webpack_runner_test.rb
shakapacker-6.2.0 test/webpack_runner_test.rb
shakapacker-6.1.1 test/webpack_runner_test.rb
shakapacker-6.1.0 test/webpack_runner_test.rb
shakapacker-6.1.0.beta.0 test/webpack_runner_test.rb
shakapacker-6.0.2 test/webpack_runner_test.rb
shakapacker-6.0.1 test/webpack_runner_test.rb
shakapacker-6.0.0 test/webpack_runner_test.rb
shakapacker-6.0.0.rc.14 test/webpack_runner_test.rb
shakapacker-6.0.0.rc.13 test/webpack_runner_test.rb