dev-update.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it, beforeEach, afterEach */
  6. 'use strict';
  7. const sinon = require( 'sinon' );
  8. const tools = require( '../tasks/utils/tools' );
  9. const git = require( '../tasks/utils/git' );
  10. const path = require( 'path' );
  11. describe( 'dev-update', () => {
  12. const updateTask = require( '../tasks/utils/dev-update' );
  13. const ckeditor5Path = 'path/to/ckeditor5';
  14. const workspaceRoot = '..';
  15. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  16. const emptyFn = () => {};
  17. const spies = {};
  18. beforeEach( () => {
  19. spies.getDependencies = sinon.spy( tools, 'getCKEditorDependencies' );
  20. spies.checkout = sinon.stub( git, 'checkout' );
  21. spies.pull = sinon.stub( git, 'pull' );
  22. spies.npmUpdate = sinon.stub( tools, 'npmUpdate' );
  23. } );
  24. afterEach( () => {
  25. Object.keys( spies ).forEach( ( spy ) => spies[ spy ].restore() );
  26. } );
  27. it( 'should update dev repositories', () => {
  28. const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
  29. spies.getDirectories = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  30. const json = {
  31. dependencies: {
  32. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  33. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  34. 'other-plugin': '1.2.3'
  35. }
  36. };
  37. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, true );
  38. sinon.assert.calledTwice( spies.pull );
  39. sinon.assert.calledWithExactly( spies.pull.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), 'master' );
  40. sinon.assert.calledWithExactly( spies.pull.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ), 'new-branch' );
  41. sinon.assert.calledThrice( spies.npmUpdate );
  42. sinon.assert.calledWithExactly( spies.npmUpdate.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
  43. sinon.assert.calledWithExactly( spies.npmUpdate.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ) );
  44. sinon.assert.calledWithExactly( spies.npmUpdate.thirdCall, ckeditor5Path );
  45. } );
  46. it( 'should update dev repositories without running npm update', () => {
  47. const dirs = [ 'ckeditor5-core' ];
  48. spies.getDirectories = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  49. const json = {
  50. dependencies: {
  51. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  52. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  53. 'other-plugin': '1.2.3'
  54. }
  55. };
  56. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, false );
  57. sinon.assert.calledWithExactly( spies.pull.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), 'master' );
  58. sinon.assert.notCalled( spies.npmUpdate );
  59. } );
  60. it( 'should not update when no dependencies are found', () => {
  61. spies.getDirectories = sinon.stub( tools, 'getCKE5Directories' );
  62. const json = {
  63. dependencies: {
  64. 'other-plugin': '1.2.3'
  65. }
  66. };
  67. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, false );
  68. sinon.assert.notCalled( spies.pull );
  69. sinon.assert.notCalled( spies.npmUpdate );
  70. } );
  71. it( 'should not update when no plugins in dev mode', () => {
  72. spies.getDirectories = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
  73. const json = {
  74. dependencies: {
  75. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  76. 'other-plugin': '1.2.3'
  77. }
  78. };
  79. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, false );
  80. sinon.assert.notCalled( spies.pull );
  81. sinon.assert.notCalled( spies.npmUpdate );
  82. } );
  83. } );