DEV: Add a spec for `assets:precompile:js_processor` (#23220)
This commit is contained in:
parent
5d5e919530
commit
3ce3c2ff81
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue