ckeditor5-dirs.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it, beforeEach, afterEach */
  6. 'use strict';
  7. const chai = require( 'chai' );
  8. const sinon = require( 'sinon' );
  9. const expect = chai.expect;
  10. const ckeditor5Dirs = require( '../../utils/ckeditor5-dirs' );
  11. const tools = require( '../../utils/tools' );
  12. let sandbox;
  13. describe( 'utils', () => {
  14. beforeEach( () => {
  15. sandbox = sinon.sandbox.create();
  16. } );
  17. afterEach( () => {
  18. sandbox.restore();
  19. } );
  20. describe( 'ckeditor5dirs', () => {
  21. describe( 'getDependencies', () => {
  22. it( 'should be defined', () => expect( ckeditor5Dirs.getDependencies ).to.be.a( 'function' ) );
  23. it( 'should return null if no CKEditor5 repository is found', () => {
  24. const dependencies = {
  25. 'plugin1': '',
  26. 'plugin2': '',
  27. 'plugin3': ''
  28. };
  29. expect( ckeditor5Dirs.getDependencies( dependencies ) ).to.equal( null );
  30. expect( ckeditor5Dirs.getDependencies() ).to.equal( null );
  31. } );
  32. it( 'should return only ckeditor5- dependencies', () => {
  33. const dependencies = {
  34. 'plugin1': '',
  35. 'ckeditor5-plugin-image': 'ckeditor/ckeditor5-plugin-image',
  36. 'plugin2': '',
  37. 'ckeditor5-core': 'ckeditor/ckeditor5-core'
  38. };
  39. const ckeditorDependencies = ckeditor5Dirs.getDependencies( dependencies );
  40. expect( ckeditorDependencies ).to.be.an( 'object' );
  41. expect( ckeditorDependencies.plugin1 ).to.be.a( 'undefined' );
  42. expect( ckeditorDependencies.plugin2 ).to.be.a( 'undefined' );
  43. expect( ckeditorDependencies[ 'ckeditor5-plugin-image' ] ).to.be.a( 'string' );
  44. expect( ckeditorDependencies[ 'ckeditor5-core' ] ).to.be.a( 'string' );
  45. } );
  46. } );
  47. describe( 'getDirectories', () => {
  48. it( 'should be defined', () => expect( ckeditor5Dirs.getDirectories ).to.be.a( 'function' ) );
  49. it( 'should return only ckeditor5 directories', () => {
  50. const workspacePath = '/workspace/path';
  51. const sourceDirectories = [ 'tools', 'ckeditor5', 'ckeditor5-core', '.bin', 'ckeditor5-plugin-image' ];
  52. sandbox.stub( tools, 'getDirectories', () => sourceDirectories );
  53. const directories = ckeditor5Dirs.getDirectories( workspacePath );
  54. expect( directories.length ).equal( 2 );
  55. expect( directories[ 0 ] ).equal( 'ckeditor5-core' );
  56. expect( directories[ 1 ] ).equal( 'ckeditor5-plugin-image' );
  57. } );
  58. } );
  59. describe( 'getSymlinks', () => {
  60. it( 'should return CKE5 symlinks from provided path', () => {
  61. const fs = require( 'fs' );
  62. const path = 'path/to/dir';
  63. sandbox.stub( fs, 'readdirSync' ).returns( [ 'ckeditor5-core', 'ckeditor5-image', 'other-dependency' ] );
  64. sandbox.stub( tools, 'isSymlink' ).returns( true );
  65. const symlinks = ckeditor5Dirs.getSymlinks( path );
  66. expect( symlinks.length ).to.equal( 2 );
  67. expect( symlinks[ 0 ] ).to.equal( 'ckeditor5-core' );
  68. expect( symlinks[ 1 ] ).to.equal( 'ckeditor5-image' );
  69. } );
  70. } );
  71. } );
  72. } );