dev-relink.js 3.6 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 path = require( 'path' );
  10. describe( 'dev-relink', () => {
  11. const task = require( '../tasks/utils/dev-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. const emptyFn = () => {};
  17. it( 'should link 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 linkStub = sinon.stub( tools, 'linkDirectories' );
  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. linkStub.restore();
  33. sinon.assert.calledTwice( linkStub );
  34. sinon.assert.calledWithExactly( linkStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), path.join( modulesPath, dirs[ 0 ] ) );
  35. sinon.assert.calledWithExactly( linkStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ), path.join( modulesPath, dirs[ 1 ] ) );
  36. } );
  37. it( 'should not link when no dependencies are found', () => {
  38. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  39. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
  40. const linkStub = sinon.stub( tools, 'linkDirectories' );
  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. linkStub.restore();
  50. sinon.assert.notCalled( linkStub );
  51. } );
  52. it( 'should not link when no plugins in dev mode', () => {
  53. const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  54. const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
  55. const linkStub = sinon.stub( tools, 'linkDirectories' );
  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. linkStub.restore();
  66. sinon.assert.notCalled( linkStub );
  67. } );
  68. it( 'should write error message when linking 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 linkStub = sinon.stub( tools, 'linkDirectories' ).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. linkStub.restore();
  86. sinon.assert.calledOnce( linkStub );
  87. sinon.assert.calledOnce( writeErrorSpy );
  88. sinon.assert.calledWithExactly( writeErrorSpy, error );
  89. } );
  90. } );