update.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. var expect = require('expect.js');
  2. var object = require('mout').object;
  3. var helpers = require('../helpers');
  4. var commands = helpers.require('lib/index').commands;
  5. describe('bower update', function () {
  6. var tempDir = new helpers.TempDir();
  7. var gitPackage = new helpers.TempDir();
  8. gitPackage.prepareGit({
  9. '1.0.0': {
  10. 'bower.json': {
  11. name: 'package'
  12. },
  13. 'version.txt': '1.0.0'
  14. },
  15. '1.0.1': {
  16. 'bower.json': {
  17. name: 'package'
  18. },
  19. 'version.txt': '1.0.1'
  20. }
  21. });
  22. var package = new helpers.TempDir({
  23. 'bower.json': {
  24. name: 'package'
  25. }
  26. }).prepare();
  27. var updateLogger = function(packages, options, config) {
  28. config = object.merge(config || {}, {
  29. cwd: tempDir.path
  30. });
  31. return commands.update(packages, options, config);
  32. };
  33. var update = function(packages, options, config) {
  34. var logger = updateLogger(packages, options, config);
  35. return helpers.expectEvent(logger, 'end');
  36. };
  37. var install = function(packages, options, config) {
  38. config = object.merge(config || {}, {
  39. cwd: tempDir.path
  40. });
  41. var logger = commands.install(
  42. packages, options, config
  43. );
  44. return helpers.expectEvent(logger, 'end');
  45. };
  46. it('install missing packages', function () {
  47. package.prepare();
  48. tempDir.prepare({
  49. 'bower.json': {
  50. name: 'test',
  51. dependencies: {
  52. package: package.path
  53. }
  54. }
  55. });
  56. return update().then(function() {
  57. expect(tempDir.exists('bower_components/package/bower.json')).to.equal(true);
  58. expect(tempDir.read('bower_components/package/bower.json')).to.contain('"name": "package"');
  59. });
  60. });
  61. it('runs preinstall hook when installing missing package', function () {
  62. package.prepare();
  63. tempDir.prepare({
  64. 'bower.json': {
  65. name: 'test',
  66. dependencies: {
  67. package: package.path
  68. }
  69. },
  70. '.bowerrc': {
  71. scripts: {
  72. preinstall: 'bash -c "echo -n % > preinstall.txt"'
  73. }
  74. }
  75. });
  76. return update().then(function() {
  77. expect(tempDir.read('preinstall.txt')).to.be('package');
  78. });
  79. });
  80. it('runs postinstall hook when installing missing package', function () {
  81. package.prepare();
  82. tempDir.prepare({
  83. 'bower.json': {
  84. name: 'test',
  85. dependencies: {
  86. package: package.path
  87. }
  88. },
  89. '.bowerrc': {
  90. scripts: {
  91. postinstall: 'bash -c "echo -n % > postinstall.txt"'
  92. }
  93. }
  94. });
  95. return update().then(function() {
  96. expect(tempDir.read('postinstall.txt')).to.be('package');
  97. });
  98. });
  99. it('doesn\'t runs postinstall when no package is update', function () {
  100. package.prepare();
  101. tempDir.prepare({
  102. 'bower.json': {
  103. name: 'test',
  104. dependencies: {
  105. package: package.path
  106. }
  107. },
  108. '.bowerrc': {
  109. scripts: {
  110. postinstall: 'bash -c "echo -n % > postinstall.txt"'
  111. }
  112. }
  113. });
  114. return install().then(function() {
  115. tempDir.prepare();
  116. return update().then(function() {
  117. expect(tempDir.exists('postinstall.txt')).to.be(false);
  118. });
  119. });
  120. });
  121. it('updates a package', function () {
  122. tempDir.prepare({
  123. 'bower.json': {
  124. name: 'test',
  125. dependencies: {
  126. package: gitPackage.path + '#1.0.0'
  127. }
  128. }
  129. });
  130. return install().then(function() {
  131. expect(tempDir.read('bower_components/package/version.txt')).to.contain('1.0.0');
  132. tempDir.prepare({
  133. 'bower.json': {
  134. name: 'test',
  135. dependencies: {
  136. package: gitPackage.path + '#1.0.1'
  137. }
  138. }
  139. });
  140. return update().then(function() {
  141. expect(tempDir.read('bower_components/package/version.txt')).to.contain('1.0.1');
  142. });
  143. });
  144. });
  145. it('runs preinstall hook when updating a package', function () {
  146. tempDir.prepare({
  147. 'bower.json': {
  148. name: 'test',
  149. dependencies: {
  150. package: gitPackage.path + '#1.0.0'
  151. }
  152. },
  153. '.bowerrc': {
  154. scripts: {
  155. preinstall: 'bash -c "echo -n % > preinstall.txt"'
  156. }
  157. }
  158. });
  159. return install().then(function() {
  160. tempDir.prepare({
  161. 'bower.json': {
  162. name: 'test',
  163. dependencies: {
  164. package: gitPackage.path + '#1.0.1'
  165. }
  166. }
  167. });
  168. expect(tempDir.exists('preinstall.txt')).to.be(false);
  169. return update().then(function() {
  170. expect(tempDir.read('preinstall.txt')).to.be('package');
  171. });
  172. });
  173. });
  174. it('runs postinstall hook when updating a package', function () {
  175. tempDir.prepare({
  176. 'bower.json': {
  177. name: 'test',
  178. dependencies: {
  179. package: gitPackage.path + '#1.0.0'
  180. }
  181. },
  182. '.bowerrc': {
  183. scripts: {
  184. postinstall: 'bash -c "echo -n % > postinstall.txt"'
  185. }
  186. }
  187. });
  188. return install().then(function() {
  189. tempDir.prepare({
  190. 'bower.json': {
  191. name: 'test',
  192. dependencies: {
  193. package: gitPackage.path + '#1.0.1'
  194. }
  195. }
  196. });
  197. expect(tempDir.exists('postinstall.txt')).to.be(false);
  198. return update().then(function() {
  199. expect(tempDir.read('postinstall.txt')).to.be('package');
  200. });
  201. });
  202. });
  203. });