8
0

dev.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 tools = require( '../utils/tools' );
  9. var sinon = require( 'sinon' );
  10. var path = require( 'path' );
  11. var expect = chai.expect;
  12. var dev = require( './../dev' );
  13. var grunt = {
  14. tasks: {},
  15. registerTask: function( taskName, fn ) {
  16. this.tasks[ taskName ] = fn;
  17. },
  18. log: {
  19. writeln: function() {}
  20. }
  21. };
  22. dev( grunt );
  23. describe( 'tasks', function() {
  24. describe( 'dev:init', function() {
  25. it( 'should get ckeditor5- dependencies, clone repositories and link them', function() {
  26. var getDepsSpy = sinon.spy( tools, 'getCKEditorDependencies' );
  27. var cloneRepositoryStub = sinon.stub( tools, 'cloneRepository' );
  28. var npmLinkStub = sinon.stub( tools, 'npmLink' );
  29. var regexp = /^ckeditor\//;
  30. var ckeditor5Path = process.cwd();
  31. var location = path.join( ckeditor5Path, '..' );
  32. var dependencies, keys;
  33. grunt.tasks.dev( 'init' );
  34. getDepsSpy.restore();
  35. cloneRepositoryStub.restore();
  36. npmLinkStub.restore();
  37. expect( getDepsSpy.calledOnce ).to.equal( true );
  38. dependencies = getDepsSpy.firstCall.returnValue;
  39. if ( dependencies ) {
  40. keys = Object.keys( dependencies ).filter( key => regexp.test( dependencies[ key ] ) );
  41. expect( cloneRepositoryStub.callCount ).to.equal( keys.length );
  42. expect( npmLinkStub.callCount ).to.equal( keys.length );
  43. keys.forEach( function( key, i ) {
  44. expect( cloneRepositoryStub.getCall( i ).args[0] ).equal( dependencies[ key ] );
  45. expect( cloneRepositoryStub.getCall( i ).args[1] ).equal( location );
  46. expect( npmLinkStub.getCall( i ).args[0] ).equal( path.join( location, key ) );
  47. expect( npmLinkStub.getCall( i ).args[1] ).equal( ckeditor5Path );
  48. expect( npmLinkStub.getCall( i ).args[2] ).equal( key );
  49. } );
  50. }
  51. } );
  52. } );
  53. } );