8
0

dev-init.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @license Copyright (c) 2003-2015, 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 tools = require( '../utils/tools' );
  11. const git = require( '../utils/git' );
  12. const path = require( 'path' );
  13. const emptyFn = () => { };
  14. let spies;
  15. describe( 'dev-tasks', () => {
  16. describe( 'dev-init', () => {
  17. const initTask = require( '../utils/dev-init' );
  18. const mainRepositoryPath = '/path/to/repository';
  19. const workspaceRoot = '..';
  20. const workspacePath = path.join( mainRepositoryPath, workspaceRoot );
  21. beforeEach( () => createSpies() );
  22. afterEach( () => restoreSpies() );
  23. function createSpies() {
  24. spies = {
  25. getDependencies: sinon.spy( tools, 'getCKEditorDependencies' ),
  26. getDirectories: sinon.stub( tools, 'getCKE5Directories', () => [] ),
  27. parseRepositoryUrl: sinon.spy( git, 'parseRepositoryUrl' ),
  28. cloneRepository: sinon.stub( git, 'cloneRepository' ),
  29. linkDirectories: sinon.stub( tools, 'linkDirectories' ),
  30. pull: sinon.stub( git, 'pull' ),
  31. checkout: sinon.stub( git, 'checkout' ),
  32. npmInstall: sinon.stub( tools, 'npmInstall' ),
  33. installGitHooks: sinon.stub( tools, 'installGitHooks' )
  34. };
  35. }
  36. function restoreSpies() {
  37. for ( let spy in spies ) {
  38. spies[ spy ].restore();
  39. }
  40. }
  41. it( 'task should exists', () => expect( initTask ).to.be.a( 'function' ) );
  42. it( 'performs no action when no ckeditor dependencies are found', () => {
  43. const packageJSON = {
  44. dependencies: {
  45. 'non-ckeditor-plugin': 'other/plugin'
  46. }
  47. };
  48. initTask( mainRepositoryPath, packageJSON, workspaceRoot, emptyFn, emptyFn );
  49. expect( spies.getDependencies.calledOnce ).to.equal( true );
  50. expect( spies.getDependencies.firstCall.args[ 0 ] ).to.equal( packageJSON.dependencies );
  51. expect( spies.getDirectories.called ).to.equal( false );
  52. expect( spies.parseRepositoryUrl.called ).to.equal( false );
  53. expect( spies.cloneRepository.called ).to.equal( false );
  54. expect( spies.checkout.called ).to.equal( false );
  55. expect( spies.pull.called ).to.equal( false );
  56. expect( spies.npmInstall.called ).to.equal( false );
  57. expect( spies.installGitHooks.called ).to.equal( false );
  58. } );
  59. it( 'clones repositories if no directories are found', () => {
  60. const packageJSON = {
  61. dependencies: {
  62. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  63. 'ckeditor5-plugin-devtest': 'ckeditor/ckeditor5-plugin-devtest',
  64. 'non-ckeditor-plugin': 'other/plugin'
  65. }
  66. };
  67. initTask( mainRepositoryPath, packageJSON, workspaceRoot, emptyFn, emptyFn );
  68. expect( spies.getDependencies.calledOnce ).to.equal( true );
  69. expect( spies.getDependencies.firstCall.args[ 0 ] ).to.equal( packageJSON.dependencies );
  70. expect( spies.getDirectories.calledOnce ).to.equal( true );
  71. expect( spies.getDirectories.firstCall.args[ 0 ] ).to.equal( path.join( mainRepositoryPath, workspaceRoot ) );
  72. expect( spies.parseRepositoryUrl.calledTwice ).to.equal( true );
  73. expect( spies.cloneRepository.calledTwice ).to.equal( true );
  74. expect( spies.cloneRepository.firstCall.args[ 0 ] ).to.equal( spies.parseRepositoryUrl.firstCall.returnValue );
  75. expect( spies.cloneRepository.firstCall.args[ 1 ] ).to.equal( workspacePath );
  76. expect( spies.cloneRepository.secondCall.args[ 0 ] ).to.equal( spies.parseRepositoryUrl.secondCall.returnValue );
  77. expect( spies.cloneRepository.secondCall.args[ 1 ] ).to.equal( workspacePath );
  78. expect( spies.checkout.calledTwice ).to.equal( true );
  79. expect( spies.pull.calledTwice ).to.equal( true );
  80. expect( spies.linkDirectories.calledTwice ).to.equal( true );
  81. expect( spies.npmInstall.calledTwice ).to.equal( true );
  82. expect( spies.installGitHooks.calledTwice ).to.equal( true );
  83. } );
  84. it( 'only checks out repositories if directories are found', () => {
  85. const packageJSON = {
  86. dependencies: {
  87. 'ckeditor5-core': 'ckeditor/ckeditor5-core',
  88. 'ckeditor5-plugin-devtest': 'ckeditor/ckeditor5-plugin-devtest',
  89. 'non-ckeditor-plugin': 'other/plugin'
  90. }
  91. };
  92. spies.getDirectories.restore();
  93. spies.getDirectories = sinon.stub( tools, 'getCKE5Directories', () => [ 'ckeditor5-core', 'ckeditor5-plugin-devtest' ] );
  94. initTask( mainRepositoryPath, packageJSON, workspaceRoot, emptyFn, emptyFn );
  95. expect( spies.getDependencies.calledOnce ).to.equal( true );
  96. expect( spies.getDependencies.firstCall.args[ 0 ] ).to.equal( packageJSON.dependencies );
  97. expect( spies.getDirectories.calledOnce ).to.equal( true );
  98. expect( spies.getDirectories.firstCall.args[ 0 ] ).to.equal( path.join( mainRepositoryPath, workspaceRoot ) );
  99. expect( spies.parseRepositoryUrl.calledTwice ).to.equal( true );
  100. expect( spies.cloneRepository.called ).to.equal( false );
  101. expect( spies.checkout.calledTwice ).to.equal( true );
  102. expect( spies.pull.calledTwice ).to.equal( true );
  103. expect( spies.linkDirectories.calledTwice ).to.equal( true );
  104. expect( spies.npmInstall.calledTwice ).to.equal( true );
  105. expect( spies.installGitHooks.calledTwice ).to.equal( true );
  106. } );
  107. } );
  108. } );