8
0

status.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 ckeditor5Dirs = require( '../../utils/ckeditor5-dirs' );
  9. const git = require( '../../utils/git' );
  10. const path = require( 'path' );
  11. const chai = require( 'chai' );
  12. const expect = chai.expect;
  13. const gulp = require( 'gulp' );
  14. describe( 'dev-status', () => {
  15. const statusTask = require( '../../tasks/dev/tasks/status' );
  16. const ckeditor5Path = 'path/to/ckeditor5';
  17. const workspaceRoot = '..';
  18. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  19. it( 'should show status of dev repositories', () => {
  20. const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
  21. const getDependenciesSpy = sinon.spy( ckeditor5Dirs, 'getDependencies' );
  22. const getDirectoriesStub = sinon.stub( ckeditor5Dirs, 'getDirectories' ).returns( dirs );
  23. const statusStub = sinon.stub( git, 'getStatus' );
  24. const json = {
  25. dependencies: {
  26. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  27. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  28. 'other-plugin': '1.2.3'
  29. }
  30. };
  31. statusTask( ckeditor5Path, json, workspaceRoot );
  32. getDependenciesSpy.restore();
  33. getDirectoriesStub.restore();
  34. statusStub.restore();
  35. sinon.assert.calledTwice( statusStub );
  36. sinon.assert.calledWithExactly( statusStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
  37. sinon.assert.calledWithExactly( statusStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ) );
  38. } );
  39. it( 'should not get status when no dependencies are found', () => {
  40. const getDependenciesSpy = sinon.spy( ckeditor5Dirs, 'getDependencies' );
  41. const getDirectoriesStub = sinon.stub( ckeditor5Dirs, 'getDirectories' );
  42. const statusStub = sinon.stub( git, 'getStatus' );
  43. const json = {
  44. dependencies: {
  45. 'other-plugin': '1.2.3'
  46. }
  47. };
  48. statusTask( ckeditor5Path, json, workspaceRoot );
  49. getDependenciesSpy.restore();
  50. getDirectoriesStub.restore();
  51. statusStub.restore();
  52. sinon.assert.notCalled( statusStub );
  53. } );
  54. it( 'should not get status when no plugins in dev mode', () => {
  55. const getDependenciesSpy = sinon.spy( ckeditor5Dirs, 'getDependencies' );
  56. const getDirectoriesStub = sinon.stub( ckeditor5Dirs, 'getDirectories' ).returns( [] );
  57. const statusStub = sinon.stub( git, 'getStatus' );
  58. const json = {
  59. dependencies: {
  60. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  61. 'other-plugin': '1.2.3'
  62. }
  63. };
  64. statusTask( ckeditor5Path, json, workspaceRoot );
  65. getDependenciesSpy.restore();
  66. getDirectoriesStub.restore();
  67. statusStub.restore();
  68. sinon.assert.notCalled( statusStub );
  69. } );
  70. it( 'should write error message when getStatus is unsuccessful', () => {
  71. const dirs = [ 'ckeditor5-core' ];
  72. const getDependenciesSpy = sinon.spy( ckeditor5Dirs, 'getDependencies' );
  73. const getDirectoriesStub = sinon.stub( ckeditor5Dirs, 'getDirectories' ).returns( dirs );
  74. const error = new Error( 'Error message.' );
  75. const statusStub = sinon.stub( git, 'getStatus' ).throws( error );
  76. const json = {
  77. dependencies: {
  78. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  79. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  80. 'other-plugin': '1.2.3'
  81. }
  82. };
  83. const writeErrorSpy = sinon.spy();
  84. const log = require( '../../utils/log' );
  85. log.configure( () => {}, writeErrorSpy );
  86. statusTask( ckeditor5Path, json, workspaceRoot );
  87. getDependenciesSpy.restore();
  88. getDirectoriesStub.restore();
  89. statusStub.restore();
  90. sinon.assert.calledOnce( statusStub );
  91. sinon.assert.calledOnce( writeErrorSpy );
  92. sinon.assert.calledWithExactly( writeErrorSpy, error );
  93. } );
  94. } );
  95. describe( 'gulp task status', () => {
  96. const tasks = gulp.tasks;
  97. it( 'should be available', () => {
  98. expect( tasks ).to.have.property( 'status' );
  99. expect( tasks.status.fn ).to.be.a( 'function' );
  100. } );
  101. it( 'should have an alias', () => {
  102. expect( tasks ).to.have.property( 'st' );
  103. expect( tasks.st.fn ).to.be.a( 'function' );
  104. expect( tasks.st.fn ).to.equal( tasks.status.fn );
  105. } );
  106. } );