A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.model import Expando
  8. from hyde.generator import Generator
  9. from hyde.site import Site
  10. from fswrap import File, Folder
  11. from util import assert_no_diff
  12. UGLIFY_SOURCE = File(__file__).parent.child_folder('uglify')
  13. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  14. class TestUglify(object):
  15. def setUp(self):
  16. TEST_SITE.make()
  17. TEST_SITE.parent.child_folder(
  18. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  19. JS = TEST_SITE.child_folder('content/media/js')
  20. JS.make()
  21. UGLIFY_SOURCE.copy_contents_to(JS)
  22. def tearDown(self):
  23. TEST_SITE.delete()
  24. def test_can_uglify(self):
  25. s = Site(TEST_SITE)
  26. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  27. s.config.mode = "production"
  28. source = TEST_SITE.child('content/media/js/jquery.js')
  29. target = File(
  30. Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  31. gen = Generator(s)
  32. gen.generate_resource_at_path(source)
  33. assert target.exists
  34. expected = UGLIFY_SOURCE.child_file('expected-jquery.js').read_all()
  35. # TODO: Very fragile. Better comparison needed.
  36. text = target.read_all()
  37. assert_no_diff(expected, text)
  38. def test_uglify_with_extra_options(self):
  39. s = Site(TEST_SITE)
  40. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  41. s.config.mode = "production"
  42. s.config.uglify = Expando(
  43. dict(args={"comments": "/http\:\/\/jquery.org\/license/"}))
  44. source = TEST_SITE.child('content/media/js/jquery.js')
  45. target = File(
  46. Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  47. gen = Generator(s)
  48. gen.generate_resource_at_path(source)
  49. assert target.exists
  50. expected = UGLIFY_SOURCE.child_file('expected-jquery-nc.js').read_all()
  51. # TODO: Very fragile. Better comparison needed.
  52. text = target.read_all()
  53. assert_no_diff(expected, text)
  54. def test_no_uglify_in_dev_mode(self):
  55. s = Site(TEST_SITE)
  56. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  57. s.config.mode = "dev"
  58. source = TEST_SITE.child('content/media/js/jquery.js')
  59. target = File(
  60. Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  61. gen = Generator(s)
  62. gen.generate_resource_at_path(source)
  63. assert target.exists
  64. expected = UGLIFY_SOURCE.child_file('jquery.js').read_all()
  65. # TODO: Very fragile. Better comparison needed.
  66. text = target.read_all()
  67. assert_no_diff(expected, text)