dev-plugin-create.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 inquiries = require( '../utils/inquiries' );
  12. const git = require( '../utils/git' );
  13. const path = require( 'path' );
  14. const emptyFn = () => { };
  15. let spies;
  16. describe( 'dev-tasks', () => {
  17. describe( 'dev-plugin-create', () => {
  18. const pluginCreateTask = require( '../utils/dev-plugin-create' );
  19. const mainRepositoryPath = '/path/to/repository/CKEditor5';
  20. const workspaceRoot = '..';
  21. const workspacePath = path.join( mainRepositoryPath, workspaceRoot );
  22. const pluginName = 'plugin-name';
  23. const pluginVersion = '0.0.1';
  24. const gitHubUrl = 'ckeditor5/plugin-name';
  25. const repositoryPath = path.join( workspacePath, pluginName );
  26. beforeEach( () => createSpies() );
  27. afterEach( () => restoreSpies() );
  28. function createSpies() {
  29. spies = {
  30. getPluginName: sinon.stub( inquiries, 'getPluginName' ).returns( new Promise( ( r ) => r( pluginName ) ) ),
  31. getPluginVersion: sinon.stub( inquiries, 'getPluginVersion' ).returns( new Promise( ( r ) => r( pluginVersion ) ) ),
  32. getPluginGitHubUrl: sinon.stub( inquiries, 'getPluginGitHubUrl' ).returns( new Promise( ( r ) => r( gitHubUrl ) ) ),
  33. initializeRepository: sinon.stub( git, 'initializeRepository' ),
  34. updateJSONFile: sinon.stub( tools, 'updateJSONFile' ),
  35. linkDirectories: sinon.stub( tools, 'linkDirectories' ),
  36. npmInstall: sinon.stub( tools, 'npmInstall' ),
  37. installGitHooks: sinon.stub( tools, 'installGitHooks' )
  38. };
  39. }
  40. function restoreSpies() {
  41. for ( let spy in spies ) {
  42. spies[ spy ].restore();
  43. }
  44. }
  45. it( 'task should exists', () => expect( pluginCreateTask ).to.be.a( 'function' ) );
  46. it( 'should create a plugin', () => {
  47. return pluginCreateTask( mainRepositoryPath, workspaceRoot, emptyFn ).then( () => {
  48. expect( spies.getPluginName.calledOnce ).to.equal( true );
  49. expect( spies.getPluginVersion.calledOnce ).to.equal( true );
  50. expect( spies.getPluginGitHubUrl.calledOnce ).to.equal( true );
  51. expect( spies.initializeRepository.calledOnce ).to.equal( true );
  52. expect( spies.initializeRepository.firstCall.args[ 0 ] ).to.equal( repositoryPath );
  53. expect( spies.updateJSONFile.calledTwice ).to.equal( true );
  54. expect( spies.updateJSONFile.firstCall.args[ 0 ] ).to.equal( path.join( repositoryPath, 'package.json' ) );
  55. expect( spies.updateJSONFile.secondCall.args[ 0 ] ).to.equal( path.join( mainRepositoryPath, 'package.json' ) );
  56. expect( spies.linkDirectories.calledOnce ).to.equal( true );
  57. expect( spies.linkDirectories.firstCall.args[ 0 ] ).to.equal( repositoryPath );
  58. expect( spies.linkDirectories.firstCall.args[ 1 ] ).to.equal( path.join( mainRepositoryPath, 'node_modules', pluginName ) );
  59. expect( spies.npmInstall.calledOnce ).to.equal( true );
  60. expect( spies.npmInstall.firstCall.args[ 0 ] ).to.equal( repositoryPath );
  61. expect( spies.installGitHooks.calledOnce ).to.equal( true );
  62. expect( spies.installGitHooks.firstCall.args[ 0 ] ).to.equal( repositoryPath );
  63. } );
  64. } );
  65. } );
  66. } );