added specs
Dieser Commit ist enthalten in:
Ursprung
fb8cdab0fd
Commit
13eabe0695
6 geänderte Dateien mit 63 neuen und 0 gelöschten Zeilen
|
@ -97,6 +97,8 @@ after_initialize do
|
|||
end
|
||||
|
||||
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/"
|
||||
path = File.expand_path(path, discourse_asset_path)
|
||||
stat = @environment.stat(path)
|
||||
|
|
55
spec/extensions/sprockets_directive_spec.rb
Normale Datei
55
spec/extensions/sprockets_directive_spec.rb
Normale Datei
|
@ -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
|
1
spec/fixtures/sprockets/require_tree_discourse_empty.js
gevendort
Normale Datei
1
spec/fixtures/sprockets/require_tree_discourse_empty.js
gevendort
Normale Datei
|
@ -0,0 +1 @@
|
|||
//= require_tree_discourse
|
1
spec/fixtures/sprockets/require_tree_discourse_non_existant.js
gevendort
Normale Datei
1
spec/fixtures/sprockets/require_tree_discourse_non_existant.js
gevendort
Normale Datei
|
@ -0,0 +1 @@
|
|||
//= require_tree_discourse dummy_path
|
1
spec/fixtures/sprockets/require_tree_discourse_test.js
gevendort
Normale Datei
1
spec/fixtures/sprockets/require_tree_discourse_test.js
gevendort
Normale Datei
|
@ -0,0 +1 @@
|
|||
//= require_tree_discourse sptest
|
3
spec/fixtures/sprockets/resolved_js_file_contents.txt
gevendort
Normale Datei
3
spec/fixtures/sprockets/resolved_js_file_contents.txt
gevendort
Normale Datei
|
@ -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");
|
Laden …
In neuem Issue referenzieren