Skip to content

Commit c73f240

Browse files
committed
fix broken tests
1) mtime was not being modified when `--force` was set on command line This has now been fixed - the force option now overrides Jammit's mtime niceties 2) newlines for JSTs were improperly described in the tests - the JS file, including templates and the JST definition, have all literal newlines stripped, but newlines inside of strings (in the templates themselves) are not stripped. Since calling jammit on the CLI treats the whole output as a JS file, the fixture for the `pack_templates` unit test was not appropriate for the CLI test
1 parent 2930f18 commit c73f240

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

lib/jammit/command_line.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ def parse_options
8181

8282
end
8383

84-
end
84+
end

lib/jammit/dependencies.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# Jammit Core:
5050
require 'jsmin'
5151
require 'cssmin'
52+
require 'jammit/version'
5253
require 'jammit/jsmin_compressor'
5354
require 'jammit/cssmin_compressor'
5455
require 'jammit/compressor'

lib/jammit/packager.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ def initialize
3333
# changed since their last package build.
3434
def precache_all(output_dir=nil, base_url=nil)
3535
output_dir ||= File.join(Jammit.public_root, Jammit.package_path)
36-
cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }
36+
37+
mtime = @force ? Time.now : nil
38+
39+
cacheable(:js, output_dir).each do |p|
40+
cache(p, 'js', pack_javascripts(p), output_dir, nil, mtime)
41+
end
42+
3743
cacheable(:css, output_dir).each do |p|
38-
cache(p, 'css', pack_stylesheets(p), output_dir)
44+
cache(p, 'css', pack_stylesheets(p), output_dir, nil, mtime)
45+
3946
if Jammit.embed_assets
40-
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
47+
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri, mtime)
4148
if Jammit.mhtml_enabled
4249
raise MissingConfiguration, "A --base-url option is required in order to generate MHTML." unless base_url
43-
mtime = latest_mtime package_for(p, :css)[:paths]
50+
mtime = latest_mtime package_for(p, :css)[:paths] unless @force
4451
asset_url = "#{base_url}#{Jammit.asset_url(p, :css, :mhtml, mtime)}"
4552
cache(p, 'css', pack_stylesheets(p, :mhtml, asset_url), output_dir, :mhtml, mtime)
4653
end

test/fixtures/jammed/jst_test_from_cli.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/test_command_line.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_jammit_precaching
2828
File.read('test/fixtures/jammed/css_test-datauri.css')
2929

3030
assert_equal zlib_read('test/precache/jst_test.js.gz'),
31-
File.read('test/fixtures/jammed/jst_test.js')
31+
File.read('test/fixtures/jammed/jst_test_from_cli.js')
3232

3333
assert_equal zlib_read('test/precache/js_test_with_templates.js.gz'),
3434
File.read('test/fixtures/jammed/js_test_with_templates.js')
@@ -41,7 +41,9 @@ def test_lazy_precaching
4141
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
4242
assert_equal File.mtime(PRECACHED_FILES.first), mtime
4343
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com --force")
44-
assert File.mtime(PRECACHED_FILES.first) > mtime
44+
new_mtime = File.mtime(PRECACHED_FILES.first)
45+
assert new_mtime > mtime,
46+
"#{ PRECACHED_FILES.first } mtime - #{ new_mtime } - greater than #{ mtime }"
4547
end
4648

4749
def zlib_read(filename)

0 commit comments

Comments
 (0)