0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
Dieser Commit ist enthalten in:
Faizaan Gagan 2021-05-03 03:42:26 +05:30
Ursprung fb8cdab0fd
Commit 13eabe0695
6 geänderte Dateien mit 63 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -97,6 +97,8 @@ after_initialize do
end end
add_to_class(::Sprockets::DirectiveProcessor, :process_require_tree_discourse_directive) do |path = "."| add_to_class(::Sprockets::DirectiveProcessor, :process_require_tree_discourse_directive) do |path = "."|
raise ArgumentError, "path cannot be empty" if path == "."
discourse_asset_path = "#{Rails.root}/app/assets/javascripts/" discourse_asset_path = "#{Rails.root}/app/assets/javascripts/"
path = File.expand_path(path, discourse_asset_path) path = File.expand_path(path, discourse_asset_path)
stat = @environment.stat(path) stat = @environment.stat(path)

Datei anzeigen

@ -0,0 +1,55 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe "Sprockets: require_tree_discourse directive" do
let(:discourse_asset_path) {
"#{Rails.root}/app/assets/javascripts/"
}
let(:fixture_asset_path) {
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/sprockets/"
}
let(:test_file_contents) {
"console.log('hello')"
}
let(:resolved_file_contents) {
File.read(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/sprockets/resolved_js_file_contents.txt"
)
}
before do
@env ||= Sprockets::Environment.new
discourse_asset_path = "#{Rails.root}/app/assets/javascripts/"
fixture_asset_path = "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/sprockets/"
@env.append_path(discourse_asset_path)
@env.append_path(fixture_asset_path)
@env.cache = {}
end
def create_tmp_folder_and_run(path, file_contents, &block)
dir = File.dirname(path)
unless File.directory?(dir)
FileUtils.mkdir_p(dir)
end
File.new(path, 'w')
File.write(path, file_contents)
yield block if block_given?
File.delete(path)
end
it "includes assets from the discourse core" do
create_tmp_folder_and_run("#{discourse_asset_path}/sptest/test.js", test_file_contents) do
expect(@env.find_asset("require_tree_discourse_test.js").to_s).to eq(resolved_file_contents)
end
end
it "throws ArgumentError if path is empty" do
expect { @env.find_asset("require_tree_discourse_empty.js") }.to raise_error(ArgumentError).with_message("path cannot be empty")
end
it "throws ArgumentError if path is non non-existent" do
expect { @env.find_asset("require_tree_discourse_non_existant.js") }.to raise_error(ArgumentError)
end
end

Datei anzeigen

@ -0,0 +1 @@
//= require_tree_discourse

Datei anzeigen

@ -0,0 +1 @@
//= require_tree_discourse dummy_path

Datei anzeigen

@ -0,0 +1 @@
//= require_tree_discourse sptest

Datei anzeigen

@ -0,0 +1,3 @@
eval("define(\"sptest/test\", [], function () {\n \"use strict\";\n\n console.log('hello');\n});" + "\n//# sourceURL=sptest/test");
;
eval("" + "\n//# sourceURL=require_tree_discourse_test");