Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

webpack - How to suppress a js pack in test environment in Rails?

I have one js pack file that is causing a problem in the test environment: packs/smooth-scroller

In app/javascript/packs/application.js

require("packs/smooth-scroller") 

Tried changing to application.js.erb and using:

require("packs/smooth-scroller") unless Rails.environment.test?

And updated webpack.yml to include

  extensions:
    - .erb

But this raised errors:

Failure/Error:
   respond_to do |format|
     format.js { render '/pages/waitlist_submissions' }
   end

 ActionController::UnknownFormat:
   ActionController::UnknownFormat

And, injecting unless Rails.environment.test? is pretty stinky.

So, what is a good way to suppress a js require, or replace the file with a blank file, in the test environment?

Rails 6

question from:https://stackoverflow.com/questions/65876065/how-to-suppress-a-js-pack-in-test-environment-in-rails

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...