tools.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. /* global describe, it */
  7. var chai = require( 'chai' );
  8. var sinon = require( 'sinon' );
  9. var expect = chai.expect;
  10. var tools = require( '../utils/tools' );
  11. describe( 'utils', function() {
  12. describe( 'tools', function() {
  13. describe( 'cloneRepository', function() {
  14. it( 'should be defined', function() {
  15. expect( tools.cloneRepository ).to.be.a( 'function' );
  16. } );
  17. it( 'should run clone repository commands', function( ) {
  18. var shExecStub = sinon.stub( tools, 'shExec' );
  19. var gitHubUrl = '/cksource/test';
  20. var destination = '/destination/dir';
  21. tools.cloneRepository( gitHubUrl, destination );
  22. shExecStub.restore();
  23. expect( shExecStub.calledOnce ).to.equal( true );
  24. expect( shExecStub.firstCall.args[ 0 ] ).to.equal( 'cd ' + destination + ' && git clone git@github.com:' + gitHubUrl );
  25. } );
  26. } );
  27. describe( 'npmLink', function() {
  28. it( 'should be defined', function() {
  29. expect( tools.cloneRepository ).to.be.a( 'function' );
  30. } );
  31. it( 'should run npm link commands', function( ) {
  32. var shExecStub = sinon.stub( tools, 'shExec' );
  33. var source = '/source/dir';
  34. var destination = '/destination/dir';
  35. var pluginName = 'ckeditor5-plugin-name';
  36. var isWin = process.platform == 'win32';
  37. var linkCommands = [
  38. 'cd ' + source,
  39. ( !isWin ? 'sudo ' : '' ) + 'npm link',
  40. 'cd ' + destination,
  41. 'npm link ' + pluginName
  42. ];
  43. tools.npmLink( source, destination, pluginName );
  44. shExecStub.restore();
  45. expect( shExecStub.calledOnce ).to.equal( true );
  46. expect( shExecStub.firstCall.args[ 0 ] ).to.equal( linkCommands.join( ' && ' ) );
  47. } );
  48. } );
  49. describe( 'getCKEditorDependencies', function() {
  50. it( 'should be defined', function() {
  51. expect( tools.getCKEditorDependencies ).to.be.a( 'function' );
  52. } );
  53. it( 'should return null if no CKEditor5 repository is found', function() {
  54. var dependencies = {
  55. 'plugin1': '',
  56. 'plugin2': '',
  57. 'plugin3': ''
  58. };
  59. expect( tools.getCKEditorDependencies( dependencies ) ).to.equal( null );
  60. } );
  61. it( 'should return only ckeditor5- dependencies', function() {
  62. var dependencies = {
  63. 'plugin1': '',
  64. 'ckeditor5-plugin-image': '',
  65. 'plugin2': '',
  66. 'ckeditor5-core': ''
  67. };
  68. var ckeditorDependencies = tools.getCKEditorDependencies( dependencies );
  69. expect( ckeditorDependencies ).to.be.an( 'object' );
  70. expect( ckeditorDependencies.plugin1 ).to.be.a( 'undefined' );
  71. expect( ckeditorDependencies.plugin2 ).to.be.a( 'undefined' );
  72. expect( ckeditorDependencies[ 'ckeditor5-plugin-image' ] ).to.be.a( 'string' );
  73. expect( ckeditorDependencies[ 'ckeditor5-core' ] ).to.be.a( 'string' );
  74. } );
  75. } );
  76. } );
  77. } );