8
0

dev-update.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it */
  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-init', () => {
  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. it( 'should update dev repositories', () => {
  18. const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
  19. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  20. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  21. const pullStub = sinon.stub( git, 'pull' );
  22. const json = {
  23. dependencies: {
  24. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  25. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  26. 'other-plugin': '1.2.3'
  27. }
  28. };
  29. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  30. getDependenciesSpy.restore();
  31. getDirectoriesStub.restore();
  32. pullStub.restore();
  33. sinon.assert.calledTwice( pullStub );
  34. sinon.assert.calledWithExactly( pullStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), 'master' );
  35. sinon.assert.calledWithExactly( pullStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ), 'new-branch' );
  36. } );
  37. it( 'should not update when no dependencies are found', () => {
  38. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  39. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
  40. const pullStub = sinon.stub( git, 'pull' );
  41. const json = {
  42. dependencies: {
  43. 'other-plugin': '1.2.3'
  44. }
  45. };
  46. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  47. getDependenciesSpy.restore();
  48. getDirectoriesStub.restore();
  49. pullStub.restore();
  50. sinon.assert.notCalled( pullStub );
  51. } );
  52. it( 'should not update when no plugins in dev mode', () => {
  53. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  54. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
  55. const pullStub = sinon.stub( git, 'pull' );
  56. const json = {
  57. dependencies: {
  58. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  59. 'other-plugin': '1.2.3'
  60. }
  61. };
  62. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  63. getDependenciesSpy.restore();
  64. getDirectoriesStub.restore();
  65. pullStub.restore();
  66. sinon.assert.notCalled( pullStub );
  67. } );
  68. it( 'should write error message when pulling is unsuccessful', () => {
  69. const dirs = [ 'ckeditor5-core' ];
  70. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  71. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  72. const error = new Error( 'Error message.' );
  73. const pullStub = sinon.stub( git, 'pull' ).throws( error );
  74. const json = {
  75. dependencies: {
  76. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  77. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  78. 'other-plugin': '1.2.3'
  79. }
  80. };
  81. const writeErrorSpy = sinon.spy();
  82. updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, writeErrorSpy );
  83. getDependenciesSpy.restore();
  84. getDirectoriesStub.restore();
  85. pullStub.restore();
  86. sinon.assert.calledOnce( pullStub );
  87. sinon.assert.calledOnce( writeErrorSpy );
  88. sinon.assert.calledWithExactly( writeErrorSpy, error );
  89. } );
  90. } );