2022-05-11 04:23:32 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
require "discourse_sourcemapping_url_processor"
|
2022-05-11 04:23:32 -05:00
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe DiscourseSourcemappingUrlProcessor do
|
2022-05-11 04:23:32 -05:00
|
|
|
def process(input)
|
|
|
|
env = Sprockets::Environment.new
|
|
|
|
env.context_class.class_eval do
|
|
|
|
def resolve(path, **kargs)
|
|
|
|
"/assets/mapped.js.map"
|
|
|
|
end
|
|
|
|
|
|
|
|
def asset_path(path, options = {})
|
|
|
|
"/assets/mapped-HEXGOESHERE.js.map"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
input = { environment: env, data: input, name: "mapped", filename: "mapped.js", metadata: {} }
|
2022-05-11 04:23:32 -05:00
|
|
|
DiscourseSourcemappingUrlProcessor.call(input)[:data]
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "maintains relative paths" do
|
2022-05-11 04:23:32 -05:00
|
|
|
output = process "var mapped;\n//# sourceMappingURL=mapped.js.map"
|
|
|
|
expect(output).to eq("var mapped;\n//# sourceMappingURL=mapped-HEXGOESHERE.js.map\n//!\n")
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "uses default behaviour for non-adjacent relative paths" do
|
2022-05-11 04:23:32 -05:00
|
|
|
output = process "var mapped;\n//# sourceMappingURL=/assets/mapped.js.map"
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(output).to eq(
|
|
|
|
"var mapped;\n//# sourceMappingURL=/assets/mapped-HEXGOESHERE.js.map\n//!\n",
|
|
|
|
)
|
2022-05-11 04:23:32 -05:00
|
|
|
end
|
|
|
|
end
|