diff --git a/test/custom_importer_test.rb b/test/custom_importer_test.rb index dfb556c..1e4ce52 100644 --- a/test/custom_importer_test.rb +++ b/test/custom_importer_test.rb @@ -37,6 +37,16 @@ def imports(_path, parent_path) end end + class ParentDirImporter < Importer + def imports(path, parent_path) + if path.include?('path') + Import.new('path.scss', source: "a { from: #{File.basename(File.dirname(parent_path))}; }") + else + Import.new(path) + end + end + end + def test_custom_importer_works temp_file('styles2.scss', '.hi { color: $var1; }') temp_file('fonts.scss', '.font { color: $var1; }') @@ -87,6 +97,33 @@ def test_custom_importer_works_for_file_in_parent_dir CSS end + # regression test for https://github.com/sass/dart-sass/issues/2208 + def test_custom_importer_works_for_imports_with_same_name + temp_dir('sub1') + temp_dir('sub1/sub2') + temp_file('sub1/test.scss', '@import "path";') + temp_file('sub1/sub2/test.scss', '@import "path";') + + data = <<~SCSS + @import "sub1/test"; + @import "sub1/sub2/test"; + SCSS + + engine = Engine.new(data, { + importer: ParentDirImporter + }) + + assert_equal <<~CSS, engine.render + a { + from: sub1; + } + + a { + from: sub2; + } + CSS + end + def test_dependency_list base = Dir.pwd