relink.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/dev/utils/tools' );
  9. const path = require( 'path' );
  10. describe( 'dev-relink', () => {
  11. const task = require( '../../tasks/dev/tasks/relink' );
  12. const ckeditor5Path = 'path/to/ckeditor5';
  13. const modulesPath = path.join( ckeditor5Path, 'node_modules' );
  14. const workspaceRoot = '..';
  15. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  16. it( 'should link dev repositories', () => {
  17. const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
  18. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  19. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  20. const linkStub = sinon.stub( tools, 'linkDirectories' );
  21. const json = {
  22. dependencies: {
  23. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  24. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  25. 'other-plugin': '1.2.3'
  26. }
  27. };
  28. task( ckeditor5Path, json, workspaceRoot );
  29. getDependenciesSpy.restore();
  30. getDirectoriesStub.restore();
  31. linkStub.restore();
  32. sinon.assert.calledTwice( linkStub );
  33. sinon.assert.calledWithExactly( linkStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), path.join( modulesPath, dirs[ 0 ] ) );
  34. sinon.assert.calledWithExactly( linkStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ), path.join( modulesPath, dirs[ 1 ] ) );
  35. } );
  36. it( 'should not link when no dependencies are found', () => {
  37. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  38. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
  39. const linkStub = sinon.stub( tools, 'linkDirectories' );
  40. const json = {
  41. dependencies: {
  42. 'other-plugin': '1.2.3'
  43. }
  44. };
  45. task( ckeditor5Path, json, workspaceRoot );
  46. getDependenciesSpy.restore();
  47. getDirectoriesStub.restore();
  48. linkStub.restore();
  49. sinon.assert.notCalled( linkStub );
  50. } );
  51. it( 'should not link when no plugins in dev mode', () => {
  52. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  53. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
  54. const linkStub = sinon.stub( tools, 'linkDirectories' );
  55. const json = {
  56. dependencies: {
  57. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  58. 'other-plugin': '1.2.3'
  59. }
  60. };
  61. task( ckeditor5Path, json, workspaceRoot );
  62. getDependenciesSpy.restore();
  63. getDirectoriesStub.restore();
  64. linkStub.restore();
  65. sinon.assert.notCalled( linkStub );
  66. } );
  67. it( 'should write error message when linking is unsuccessful', () => {
  68. const dirs = [ 'ckeditor5-core' ];
  69. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  70. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
  71. const error = new Error( 'Error message.' );
  72. const linkStub = sinon.stub( tools, 'linkDirectories' ).throws( error );
  73. const json = {
  74. dependencies: {
  75. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  76. 'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
  77. 'other-plugin': '1.2.3'
  78. }
  79. };
  80. const writeErrorSpy = sinon.spy();
  81. const log = require( '../../tasks/dev/utils/log' );
  82. log.configure( () => {}, writeErrorSpy );
  83. task( ckeditor5Path, json, workspaceRoot );
  84. getDependenciesSpy.restore();
  85. getDirectoriesStub.restore();
  86. linkStub.restore();
  87. sinon.assert.calledOnce( linkStub );
  88. sinon.assert.calledOnce( writeErrorSpy );
  89. sinon.assert.calledWithExactly( writeErrorSpy, error );
  90. } );
  91. } );