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.

163 lines
4.0 KiB

  1. 'use strict';
  2. var path = require('path');
  3. var grunt = require('grunt');
  4. var EventEmitter = require('events').EventEmitter;
  5. var BowerAssets = require('../tasks/lib/bower_assets');
  6. /*
  7. ======== A Handy Little Nodeunit Reference ========
  8. https://github.com/caolan/nodeunit
  9. Test methods:
  10. test.expect(numAssertions)
  11. test.done()
  12. Test assertions:
  13. test.ok(value, [message])
  14. test.equal(actual, expected, [message])
  15. test.notEqual(actual, expected, [message])
  16. test.deepEqual(actual, expected, [message])
  17. test.notDeepEqual(actual, expected, [message])
  18. test.strictEqual(actual, expected, [message])
  19. test.notStrictEqual(actual, expected, [message])
  20. test.throws(block, [error], [message])
  21. test.doesNotThrow(block, [error], [message])
  22. test.ifError(value)
  23. */
  24. function verify(name, message, expected, test, bower) {
  25. function setupBowerConfig(name) {
  26. return new BowerAssets(bower, path.join(__dirname, 'fixtures', name));
  27. }
  28. var bowerAssets = setupBowerConfig(name);
  29. bowerAssets.get()
  30. .on('data', function(actual) {
  31. test.deepEqual(actual, expected, message);
  32. test.done();
  33. })
  34. .on('error', function(err) {
  35. test.ok(false, err);
  36. test.done();
  37. });
  38. }
  39. exports.bower_assets = {
  40. setUp: function(done) {
  41. var bowerCommands = {
  42. list: new EventEmitter()
  43. };
  44. this.bowerCommands = bowerCommands;
  45. this.bower = {
  46. commands: {
  47. list: function() {
  48. return bowerCommands.list;
  49. }
  50. },
  51. config: {
  52. json: 'component.json',
  53. directory: 'components'
  54. }
  55. };
  56. done();
  57. },
  58. tearDown: function(done) {
  59. delete this.bowerCommands;
  60. delete this.bower;
  61. done();
  62. },
  63. currentStateOfBower: function(test) {
  64. test.expect(1);
  65. var expected = {
  66. "__untyped__": {
  67. "jquery": [path.normalize("components/jquery/jquery.js")]
  68. }
  69. };
  70. verify(
  71. 'current_state_of_bower',
  72. 'should return all main paths in "__untyped__" group',
  73. expected,
  74. test,
  75. this.bower);
  76. this.bowerCommands.list.emit('data', {"jquery": path.normalize("components/jquery/jquery.js")});
  77. },
  78. extendedComponentJson: function(test) {
  79. test.expect(1);
  80. var expected = {
  81. "__untyped__": {
  82. "jquery": [ path.normalize("components/jquery/jquery.js") ]
  83. },
  84. "js": {
  85. "bootstrap-sass": [
  86. path.normalize("components/bootstrap-sass/js/bootstrap-affix.js"),
  87. path.normalize("components/bootstrap-sass/js/bootstrap-modal.js")
  88. ]
  89. },
  90. "scss": {
  91. "bootstrap-sass": [ path.normalize("components/bootstrap-sass/lib/_mixins.scss") ]
  92. }
  93. };
  94. verify(
  95. 'extended_component_json',
  96. 'should return extended set of paths in "js" and "scss" groups',
  97. expected,
  98. test,
  99. this.bower);
  100. this.bowerCommands.list.emit('data', {
  101. "bootstrap-sass": [
  102. path.normalize("components/bootstrap-sass/docs/assets/js/bootstrap.js"),
  103. path.normalize("components/bootstrap-sass/docs/assets/css/bootstrap.css")
  104. ],
  105. "jquery": path.normalize("components/jquery/jquery.js")
  106. });
  107. },
  108. overrideHonoringNativeBowerConfiguration: function(test) {
  109. test.expect(1);
  110. var expected = {
  111. "__untyped__": {
  112. "jquery": [ path.normalize("bo_co/jquery/jquery.js") ]
  113. },
  114. "js": {
  115. "bootstrap": [
  116. path.normalize("bo_co/bootstrap/js/bootstrap-affix.js")
  117. ]
  118. },
  119. "scss": {
  120. "bootstrap": [ path.normalize("bo_co/bootstrap/lib/_mixins.scss") ]
  121. }
  122. };
  123. this.bower.config.directory = 'bo_co';
  124. verify(
  125. 'honor_bowerrc',
  126. 'should honor native Bower configuration while overriding packages',
  127. expected,
  128. test,
  129. this.bower);
  130. this.bowerCommands.list.emit('data', {
  131. "bootstrap": [
  132. path.normalize("bo_co/bootstrap/docs/assets/js/bootstrap.js"),
  133. path.normalize("bo_co/bootstrap/docs/assets/css/bootstrap.css")
  134. ],
  135. "jquery": path.normalize("bo_co/jquery/jquery.js")
  136. });
  137. }
  138. };