Sha256: ceaf251fadf52fb4e0383335b463a1acacc7256fd4812683ebceda659b2e8a32

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

require_relative "spec_helper_initializer"
# Requiring from webpacker directory to ensure old ./bin/webpacker-dev-server works fine
require "webpacker/webpack_runner"

describe "WebpackRunner" do
  before :all do
    @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
    @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
  end

  after :all do
    ENV["NODE_ENV"] = @original_node_env
    ENV["RAILS_ENV"] = @original_rails_env
  end

  it "runs cmd via node_modules" do
    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

  it "runs cmd via yarn" do
    cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]

    verify_command(cmd, use_node_modules: false)
  end

  it "runs cmd argv" do
    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("webpacker_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)

      allow(klass).to receive(:new).and_return(instance)
      allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
      allow(Kernel).to receive(:exec)

      klass.run(argv)

      expect(Kernel).to have_received(:exec).with(Webpacker::Compiler.env, *cmd)
    ensure
      Dir.chdir(cwd)
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shakapacker-7.0.3 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.2 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.1 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.0 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.0.rc.2 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.0.rc.1 spec/backward_compatibility_specs/webpack_runner_spec.rb
shakapacker-7.0.0.rc.0 spec/backward_compatibility_specs/webpack_runner_spec_bc.rb