spec/source_map_spec.rb in uglifier-2.5.3 vs spec/source_map_spec.rb in uglifier-2.6.0

- old
+ new

@@ -1,29 +1,31 @@ # encoding: UTF-8 require 'stringio' require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Uglifier" do - it "generates source maps" do - source = File.open("lib/uglify.js", "r:UTF-8").read - minified, map = Uglifier.new.compile_with_map(source) - expect(minified.length).to be < source.length - expect(map.length).to be > 0 - expect { JSON.parse(map) }.not_to raise_error - end - - it "generates source maps with the correct meta-data" do - source = <<-JS + let(:source) do + <<-JS function hello () { function world () { return 2; }; return world() + world(); }; JS + end + it "generates source maps" do + source = File.open("lib/uglify.js", "r:UTF-8").read + minified, map = Uglifier.new.compile_with_map(source) + expect(minified.length).to be < source.length + expect(map.length).to be > 0 + expect { JSON.parse(map) }.not_to raise_error + end + + it "generates source maps with the correct meta-data" do _, map = Uglifier.compile_with_map(source, :source_filename => "ahoy.js", :output_filename => "ahoy.min.js", :source_root => "http://localhost/") @@ -80,7 +82,29 @@ map = SourceMap.from_s(map2) expect(map.sources).to eq(["http://localhost/ahoy.js"]) expect(map.mappings.first[:source_line]).to eq(1) expect(map.mappings.last[:source_line]).to eq(6) + end + + it "appens source map url" do + minified, _ = Uglifier.compile_with_map( + source, + :source_filename => "ahoy.js", + :output_filename => "ahoy.min.js", + :source_root => "http://localhost/", + :source_map_url => "http://example.com/map" + ) + expect(minified).to include("\n//# sourceMappingURL=http://example.com/map") + end + + it "appens source url" do + minified, _ = Uglifier.compile_with_map( + source, + :source_filename => "ahoy.js", + :output_filename => "ahoy.min.js", + :source_root => "http://localhost/", + :source_url => "http://example.com/source" + ) + expect(minified).to include("\n//# sourceURL=http://example.com/source") end end