123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- var expect = require('expect.js');
- var object = require('mout').object;
- var helpers = require('../helpers');
- var commands = helpers.require('lib/index').commands;
- describe('bower update', function () {
- var tempDir = new helpers.TempDir();
- var gitPackage = new helpers.TempDir();
- gitPackage.prepareGit({
- '1.0.0': {
- 'bower.json': {
- name: 'package'
- },
- 'version.txt': '1.0.0'
- },
- '1.0.1': {
- 'bower.json': {
- name: 'package'
- },
- 'version.txt': '1.0.1'
- }
- });
- var package = new helpers.TempDir({
- 'bower.json': {
- name: 'package'
- }
- }).prepare();
- var updateLogger = function(packages, options, config) {
- config = object.merge(config || {}, {
- cwd: tempDir.path
- });
- return commands.update(packages, options, config);
- };
- var update = function(packages, options, config) {
- var logger = updateLogger(packages, options, config);
- return helpers.expectEvent(logger, 'end');
- };
- var install = function(packages, options, config) {
- config = object.merge(config || {}, {
- cwd: tempDir.path
- });
- var logger = commands.install(
- packages, options, config
- );
- return helpers.expectEvent(logger, 'end');
- };
- it('install missing packages', function () {
- package.prepare();
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: package.path
- }
- }
- });
- return update().then(function() {
- expect(tempDir.exists('bower_components/package/bower.json')).to.equal(true);
- expect(tempDir.read('bower_components/package/bower.json')).to.contain('"name": "package"');
- });
- });
- it('runs preinstall hook when installing missing package', function () {
- package.prepare();
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: package.path
- }
- },
- '.bowerrc': {
- scripts: {
- preinstall: 'bash -c "echo -n % > preinstall.txt"'
- }
- }
- });
- return update().then(function() {
- expect(tempDir.read('preinstall.txt')).to.be('package');
- });
- });
- it('runs postinstall hook when installing missing package', function () {
- package.prepare();
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: package.path
- }
- },
- '.bowerrc': {
- scripts: {
- postinstall: 'bash -c "echo -n % > postinstall.txt"'
- }
- }
- });
- return update().then(function() {
- expect(tempDir.read('postinstall.txt')).to.be('package');
- });
- });
- it('doesn\'t runs postinstall when no package is update', function () {
- package.prepare();
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: package.path
- }
- },
- '.bowerrc': {
- scripts: {
- postinstall: 'bash -c "echo -n % > postinstall.txt"'
- }
- }
- });
- return install().then(function() {
- tempDir.prepare();
- return update().then(function() {
- expect(tempDir.exists('postinstall.txt')).to.be(false);
- });
- });
- });
- it('updates a package', function () {
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.0'
- }
- }
- });
- return install().then(function() {
- expect(tempDir.read('bower_components/package/version.txt')).to.contain('1.0.0');
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.1'
- }
- }
- });
- return update().then(function() {
- expect(tempDir.read('bower_components/package/version.txt')).to.contain('1.0.1');
- });
- });
- });
- it('runs preinstall hook when updating a package', function () {
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.0'
- }
- },
- '.bowerrc': {
- scripts: {
- preinstall: 'bash -c "echo -n % > preinstall.txt"'
- }
- }
- });
- return install().then(function() {
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.1'
- }
- }
- });
- expect(tempDir.exists('preinstall.txt')).to.be(false);
- return update().then(function() {
- expect(tempDir.read('preinstall.txt')).to.be('package');
- });
- });
- });
- it('runs postinstall hook when updating a package', function () {
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.0'
- }
- },
- '.bowerrc': {
- scripts: {
- postinstall: 'bash -c "echo -n % > postinstall.txt"'
- }
- }
- });
- return install().then(function() {
- tempDir.prepare({
- 'bower.json': {
- name: 'test',
- dependencies: {
- package: gitPackage.path + '#1.0.1'
- }
- }
- });
- expect(tempDir.exists('postinstall.txt')).to.be(false);
- return update().then(function() {
- expect(tempDir.read('postinstall.txt')).to.be('package');
- });
- });
- });
- });
|