DEV: Add a spec for `assets:precompile:js_processor` (#23220)

This commit is contained in:
Jarek Radosz 2023-08-25 11:44:30 +02:00 committed by GitHub
parent 5d5e919530
commit 3ce3c2ff81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View File

@ -6,9 +6,6 @@ class DiscourseJsProcessor
class TranspileError < StandardError
end
JS_PROCESSOR_PATH =
Rails.env.production? ? "tmp/js-processor.js" : "tmp/js-processor/#{Process.pid}.js"
# To generate a list of babel plugins used by ember-cli, set
# babel: { debug: true } in ember-cli-build.js, then run `yarn ember build -prod`
DISCOURSE_COMMON_BABEL_PLUGINS = [
@ -101,6 +98,9 @@ class DiscourseJsProcessor
end
class Transpiler
JS_PROCESSOR_PATH =
Rails.env.production? ? "tmp/js-processor.js" : "tmp/js-processor/#{Process.pid}.js"
@mutex = Mutex.new
@ctx_init = Mutex.new
@processor_mutex = Mutex.new
@ -121,6 +121,7 @@ class DiscourseJsProcessor
"app/assets/javascripts/js-processor.js",
"--outfile=#{JS_PROCESSOR_PATH}",
)
JS_PROCESSOR_PATH
end
def self.create_new_context

View File

@ -301,7 +301,8 @@ task "assets:precompile:compress_js": "environment" do
end
task "assets:precompile:js_processor": "environment" do
DiscourseJsProcessor::Transpiler.generate_js_processor
path = DiscourseJsProcessor::Transpiler.generate_js_processor
puts "Compiled js-processor: #{path}"
end
# Run these tasks **before** Rails' "assets:precompile" task

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
RSpec.describe "assets:precompile" do
before do
Rake::Task.clear
Discourse::Application.load_tasks
end
describe "assets:precompile:js_processor" do
it "compiles the js processor" do
out = capture_stdout { Rake::Task["assets:precompile:js_processor"].invoke }
expect(out).to match(%r{Compiled js-processor: tmp/js-processor})
path = out.match(/: (.+)/)[1]
expect(File.exist?(path)).to eq(true)
end
end
end