1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Install JavaScript packages before run test

Some tests are running yarn install during the test.
The directory used for isolation test is not subject to yarn workspace,
and it occurs because the required package is not installed.
In order to avoid this, I fixed all necessary packages to be installed
before run test and use symlink to `node_modules`.

This is a bit complicated, as `yarn install` needs to be run in a specific
directory before running the test.
However, running `yarn install` every time run the test is expensive
when testing locally and should be avoided.
This commit is contained in:
yuuji.yaginuma 2019-02-07 10:10:27 +09:00
parent 9cc463ed7b
commit cd34f00627
10 changed files with 38 additions and 16 deletions

View file

@ -47,6 +47,8 @@ before_script:
# Decodes to e.g. `export VARIABLE=VALUE` # Decodes to e.g. `export VARIABLE=VALUE`
- $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX0FDQ0VTU19LRVk9YTAzNTM0M2YtZTkyMi00MGIzLWFhM2MtMDZiM2VhNjM1YzQ4") - $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX0FDQ0VTU19LRVk9YTAzNTM0M2YtZTkyMi00MGIzLWFhM2MtMDZiM2VhNjM1YzQ4")
- $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX1VTRVJOQU1FPXJ1YnlvbnJhaWxz") - $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX1VTRVJOQU1FPXJ1YnlvbnJhaWxz")
- "[[ $GEM != 'railties' ]] || (cd actionview && yarn build)"
- "[[ $GEM != 'railties' ]] || (cd railties/test/isolation/assets && yarn install)"
script: 'ci/travis.rb' script: 'ci/travis.rb'

View file

@ -4,10 +4,7 @@
"actioncable", "actioncable",
"actiontext", "actiontext",
"activestorage", "activestorage",
"actionview", "actionview"
"tmp/templates/app_template",
"railties/test/fixtures/tmp/bukkits/**/test/dummy",
"railties/test/fixtures/tmp/bukkits/**/spec/dummy"
], ],
"dependencies": { "dependencies": {
"webpack": "^4.17.1" "webpack": "^4.17.1"

1
railties/.gitignore vendored
View file

@ -2,4 +2,5 @@
/test/500.html /test/500.html
/test/fixtures/tmp/ /test/fixtures/tmp/
/test/initializer/root/log/ /test/initializer/root/log/
/test/isolation/assets/yarn.lock
/tmp/ /tmp/

View file

@ -38,7 +38,7 @@ namespace :test do
test_patterns = dirs.map { |dir| "test/#{dir}/*_test.rb" } test_patterns = dirs.map { |dir| "test/#{dir}/*_test.rb" }
test_files = Dir[*test_patterns].select do |file| test_files = Dir[*test_patterns].select do |file|
!file.start_with?("test/fixtures/") !file.start_with?("test/fixtures/") && !file.start_with?("test/isolation/assets/")
end.sort end.sort
if ENV["BUILDKITE_PARALLEL_JOB_COUNT"] if ENV["BUILDKITE_PARALLEL_JOB_COUNT"]

View file

@ -472,21 +472,17 @@ Module.new do
FileUtils.rm_rf(app_template_path) FileUtils.rm_rf(app_template_path)
FileUtils.mkdir_p(app_template_path) FileUtils.mkdir_p(app_template_path)
Dir.chdir "#{RAILS_FRAMEWORK_ROOT}/actionview" do `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install`
`yarn build`
end
`#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc`
File.open("#{app_template_path}/config/boot.rb", "w") do |f| File.open("#{app_template_path}/config/boot.rb", "w") do |f|
f.puts "require 'rails/all'" f.puts "require 'rails/all'"
end end
Dir.chdir(app_template_path) { `yarn add https://github.com/rails/webpacker.git` } # Use the latest version. assets_path = "#{RAILS_FRAMEWORK_ROOT}/railties/test/isolation/assets"
FileUtils.cp("#{assets_path}/package.json", "#{app_template_path}/package.json")
# Manually install `webpack` as bin symlinks are not created for sub dependencies FileUtils.cp("#{assets_path}/config/webpacker.yml", "#{app_template_path}/config/webpacker.yml")
# in workspaces. See https://github.com/yarnpkg/yarn/issues/4964 FileUtils.cp_r("#{assets_path}/config/webpack", "#{app_template_path}/config/webpack")
Dir.chdir(app_template_path) { `yarn add webpack@4.17.1 --tilde` } FileUtils.ln_s("#{assets_path}/node_modules", "#{app_template_path}/node_modules")
Dir.chdir(app_template_path) { `yarn add webpack-cli` } FileUtils.chdir(app_template_path) { `bin/rails webpacker:binstubs` }
# Fake 'Bundler.require' -- we run using the repo's Gemfile, not an # Fake 'Bundler.require' -- we run using the repo's Gemfile, not an
# app-specific one: we don't want to require every gem that lists. # app-specific one: we don't want to require every gem that lists.

View file

@ -0,0 +1,3 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const { environment } = require('@rails/webpacker')
module.exports = environment.toWebpackConfig()

View file

@ -0,0 +1,3 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const { environment } = require('@rails/webpacker')
module.exports = environment.toWebpackConfig()

View file

@ -0,0 +1,3 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const { environment } = require('@rails/webpacker')
module.exports = environment.toWebpackConfig()

View file

@ -0,0 +1,8 @@
default: &default
check_yarn_integrity: false
development:
<<: *default
test:
<<: *default
production:
<<: *default

View file

@ -0,0 +1,9 @@
{
"name": "dummy",
"private": true,
"dependencies": {
"@rails/ujs": "file:../../../../actionview",
"@rails/webpacker": "https://github.com/rails/webpacker.git",
"turbolinks": "^5.2.0"
}
}