-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add a test helper #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add a test helper #341
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
WEBPACKER_APP_TEMPLATE_PATH = File.expand_path("../../install/template.rb", __dir__) | ||
install_template_path = File.expand_path("../../install/template.rb", __dir__) | ||
|
||
namespace :webpacker do | ||
desc "Install webpacker in this application" | ||
task install: [:check_node, :check_yarn] do | ||
if Rails::VERSION::MAJOR >= 5 | ||
exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}" | ||
exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{install_template_path}" | ||
else | ||
exec "#{RbConfig.ruby} ./bin/rake rails:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}" | ||
exec "#{RbConfig.ruby} ./bin/rake rails:template LOCATION=#{install_template_path}" | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "rake" | ||
require "webpacker" | ||
|
||
module Webpacker::TestHelper | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
setup :compile_webpack_assets | ||
end | ||
|
||
def compile_webpack_assets | ||
Rails.cache.fetch(["webpacker", "manifest", checksum]) do | ||
@load_rakefile ||= Rake.load_rakefile(Rails.root.join("Rakefile")) | ||
Rake::Task["webpacker:compile"].invoke | ||
Rake::Task["webpacker:compile"].reenable | ||
end | ||
end | ||
|
||
private | ||
|
||
def checksum | ||
files = Dir["#{Webpacker::Configuration.source}/**/*", "package.json", "yarn.lock"].reject { |f| File.directory?(f) } | ||
files.map { |f| File.mtime(f).utc.to_i }.max.to_s | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cache key will only be invalidated when your files change, right? What if, for example, you bump the version of a dependency in package.json? I think it'd be best to avoid caching unless we can use the same digests provided by webpack.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javan Yepp that's right. Good point 👍 Perhaps we should watch
package.json
andyarn.lock
for changes too? The compile task slows down the tests so it's best to cache because we won't be able to get new digests from webpack until it's compiled (which is same thing as re-compiling) unless I am missing something??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added yarn.lock and package.json to watch list