为什么`bin/rails test`每次都会触发yarn编译?

问题描述 投票:0回答:1

如果我使用

bin/rails test
运行测试,它会触发yarn运行两次,一次用于esbuild,一次用于css。如果我使用
bin/rails test test/**/**.rb
bin/rails test test/
运行所有相同的测试,测试会立即运行。

当我运行

bin/rails test
时(即当我不运行系统测试时),如何跳过纱线构建?

版本:Rails 7.1.1、Ruby 3.2.2、Minitest 5.20.0
使用

rails new my_app --javascript esbuild --css bootstrap

创建的应用程序

附加问题 - 下次我该如何自己解决这个问题?

我的测试助手似乎没有调用

rails test:prepare
或任何其他触发纱线的东西:

# test/test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"

module ActiveSupport
  class TestCase
    # Run tests in parallel with specified workers
    parallelize(workers: :number_of_processors)

    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
    fixtures :all

    # Add more helper methods to be used by all tests here...
  end
end

我尝试过检查

require
中的每个
test_helper.rb
d 文件,但找不到其他任何地方告诉要发生纱线/资产/预编译:

  • ../config/environment
    • config/application
      • config/boot
      • rails/all
        ❓(不知道从哪里开始)
  • rails/test_help
    ❓(通读来源,但只查看了它需要的其中一件事)
    • active_support/testing/autorun
      ❌(来源

我也尝试过

bundle open minitest
,以防万一在那里配置了一些东西,但我浏览了一下,但没有看到任何相关的东西。

为测试配置的纱线/资产编译“魔法”在哪里?

ruby-on-rails minitest
1个回答
0
投票

“我的测试助手似乎没有打电话来

rails test:prepare

当您不带任何参数调用

rails test
时,它会为您调用
test:prepare
Source

run_prepare_task if self.args.none?(EXACT_TEST_ARGUMENT_PATTERN)

来源

Rails::Command::RakeCommand.perform("test:prepare", [], {})

升级指南

中所述

通过 bin/rails test 运行测试时,rake test:prepare 任务将在测试运行之前运行。如果您增强了 test:prepare 任务,您的增强功能将在测试之前运行。

tailwindcss-rails
jsbundling-rails
cssbundling-rails
增强了此任务,其他第三方宝石也是如此。

您可以看到这确实构建了

yarn
Cssbundling nad Jsbundling

© www.soinside.com 2019 - 2024. All rights reserved.