dev-boilerplate-update.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @license Copyright (c) 2003-2016, 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-boilerplate-update', () => {
  12. const task = require( '../tasks/utils/dev-boilerplate-update' );
  13. const ckeditor5Path = 'path/to/ckeditor5';
  14. const workspaceRoot = '..';
  15. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  16. const emptyFn = () => {};
  17. it( 'should update boilerplate in 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 updateStub = sinon.stub( git, 'updateBoilerplate' );
  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. task( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  30. getDependenciesSpy.restore();
  31. getDirectoriesStub.restore();
  32. updateStub.restore();
  33. sinon.assert.calledTwice( updateStub );
  34. sinon.assert.calledWithExactly( updateStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
  35. sinon.assert.calledWithExactly( updateStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ) );
  36. } );
  37. it( 'should not update boilerplate when no dependencies are found', () => {
  38. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  39. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
  40. const updateStub = sinon.stub( git, 'updateBoilerplate' );
  41. const json = {
  42. dependencies: {
  43. 'other-plugin': '1.2.3'
  44. }
  45. };
  46. task( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  47. getDependenciesSpy.restore();
  48. getDirectoriesStub.restore();
  49. updateStub.restore();
  50. sinon.assert.notCalled( updateStub );
  51. } );
  52. it( 'should not update boilerplate when no plugins in dev mode', () => {
  53. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  54. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
  55. const updateStub = sinon.stub( git, 'updateBoilerplate' );
  56. const json = {
  57. dependencies: {
  58. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  59. 'other-plugin': '1.2.3'
  60. }
  61. };
  62. task( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
  63. getDependenciesSpy.restore();
  64. getDirectoriesStub.restore();
  65. updateStub.restore();
  66. sinon.assert.notCalled( updateStub );
  67. } );
  68. it( 'should write error message when updating boilerplate 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 updateStub = sinon.stub( git, 'updateBoilerplate' ).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. task( ckeditor5Path, json, workspaceRoot, emptyFn, writeErrorSpy );
  83. getDependenciesSpy.restore();
  84. getDirectoriesStub.restore();
  85. updateStub.restore();
  86. sinon.assert.calledOnce( updateStub );
  87. sinon.assert.calledOnce( writeErrorSpy );
  88. sinon.assert.calledWithExactly( writeErrorSpy, error );
  89. } );
  90. } );