Travis 因 webpacker 问题而失败 (Rspec) rails 5.2

Travis failing with webpacker issue (Rspec) rails 5.2

我刚刚开始使用 RSpec 在我的 rails 5.2 应用程序中进行测试。我正在将我的应用程序部署到我的远程 Github 存储库,然后在部署到 Heroku 之前由 Travis 对其进行测试。

我已经创建了一些非常简单的测试,这些测试已经通过了,但是我刚刚添加了一个新模型 distilleries 而 Travis 现在构建失败了。

Travis 似乎在抱怨无法在我的 Webpack 清单中找到文件。我的应用程序在本地完美运行。

当我在控制台中 运行 rspec spec/models/distillery_spec.rb 时,我得到 0 个错误。

我是 Rails 中测试的新手,所以如果我在某个地方犯了菜鸟错误,请多多包涵。

特拉维斯日志

...    
Failures:

  1) Distilleries GET /distilleries works! (now write some real specs)
     Failure/Error: <%= javascript_pack_tag 'application' %> 

     ActionView::Template::Error:
       Webpacker can't find application.js in /home/travis/build/sfcooper/GD/public/packs-test/manifest.json. Possible causes:
       1. You want to set webpacker.yml value of compile to true for your environment
          unless you are using the `webpack -w` or the webpack-dev-server.
       2. webpack has not yet re-run to reflect updates.
       3. You have misconfigured Webpacker's config/webpacker.yml file.
       4. Your webpack configuration is not creating a manifest.
       Your manifest contains:
       {
       }
     # ./app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb___92036987216695529_24174260'
     # ./spec/requests/distilleries_spec.rb:6:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Webpacker::Manifest::MissingEntryError:
     #   Webpacker can't find application.js in /home/travis/build/sfcooper/GD/public/packs-test/manifest.json. Possible causes:
     #   1. You want to set webpacker.yml value of compile to true for your environment
     #      unless you are using the `webpack -w` or the webpack-dev-server.
     #   2. webpack has not yet re-run to reflect updates.
     #   3. You have misconfigured Webpacker's config/webpacker.yml file.
     #   4. Your webpack configuration is not creating a manifest.
     #   Your manifest contains:
     #   {
     #   }
     #   ./app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb___92036987216695529_24174260'
Finished in 1.04 seconds (files took 2.32 seconds to load)
9 examples, 1 failure
Failed examples:
rspec ./spec/requests/distilleries_spec.rb:5 # Distilleries GET /distilleries works! (now write some real specs)

...

distillery_spec.rb

require 'rails_helper'

    RSpec.describe Distillery, type: :model do
      context 'validations' do
        it { should validate_presence_of(:name) }
        it { should validate_presence_of(:snippet) }
      end
      context 'associations' do
        it { should have_many(:gins) }
      end
    end

factories/distilleries.rb

FactoryGirl.define do
  factory :distillery do

  end
end

travis.yml

language: ruby
rvm:
- 2.4.0
before_script:
- bundle exec rake db:create --all
- bundle exec rake db:migrate
script:
  - bundle exec rake ci:tests
services:
- postgresql
notifications:
  email: false
deploy:
  provider: heroku
  api_key:
    secure: ******
  app:
    master: thegd
  on:
    repo: sfcooper/GD
  run:
  - rails db:migrate

更新

我现在删除了整个 distilleries_spec.rb 文件,但仍然存在同样的问题。我只是看不出 Travis 在哪里发现清单文件的问题。

public/packs/manifest.json {

"application.css": "/packs/application-25e3a7ac7f3afb6db64c457a591257f8.css",
  "application.css.map": "/packs/application-25e3a7ac7f3afb6db64c457a591257f8.css.map",
  "application.js": "/packs/application-135f3e8e200516e9e3cd.js",
  "application.js.map": "/packs/application-135f3e8e200516e9e3cd.js.map",
  "botanicalselector.js": "/packs/botanicalselector-c06eacfbeb4820a881b6.js",
  "botanicalselector.js.map": "/packs/botanicalselector-c06eacfbeb4820a881b6.js.map",
  "countryselector.js": "/packs/countryselector-9f4de505e0d165ed7721.js",
  "countryselector.js.map": "/packs/countryselector-9f4de505e0d165ed7721.js.map"
}

同时牢记错误:

Webpacker can't find application.js in /home/travis/build/sfcooper/GD/public/packs-test/manifest.json

我已确保此路径不在 .gitignore.

解决了

感谢这个 - https://github.com/rails/webpacker/issues/1494

我花了一点时间才注意到 Travis 在 /public/packs-test/ 中寻找 manifest.json 而不仅仅是 /public/packs.

运行之后:

RAILS_ENV=test bundle exec rails webpacker:compile

Travis 现在通过构建。