| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* global describe, it, beforeEach, afterEach */
- 'use strict';
- let sandbox;
- const git = require( '../../utils/git' );
- const chai = require( 'chai' );
- const sinon = require( 'sinon' );
- const tools = require( '../../utils/tools' );
- const expect = chai.expect;
- describe( 'utils', () => {
- beforeEach( () => {
- sandbox = sinon.sandbox.create();
- } );
- afterEach( () => {
- sandbox.restore();
- } );
- describe( 'git', () => {
- describe( 'parseRepositoryUrl', () => {
- it( 'should be defined', () => expect( git.parseRepositoryUrl ).to.be.a( 'function' ) );
- it( 'should parse short GitHub URL ', () => {
- const urlInfo = git.parseRepositoryUrl( 'ckeditor/ckeditor5-core' );
- expect( urlInfo.server ).to.equal( 'git@github.com:' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'master' );
- } );
- it( 'should parse short GitHub URL with provided branch ', () => {
- const urlInfo = git.parseRepositoryUrl( 'ckeditor/ckeditor5-core#experimental' );
- expect( urlInfo.server ).to.equal( 'git@github.com:' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'experimental' );
- } );
- it( 'should parse full GitHub URL (http)', () => {
- const urlInfo = git.parseRepositoryUrl( 'http://github.com/ckeditor/ckeditor5-core.git' );
- expect( urlInfo.server ).to.equal( 'http://github.com/' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'master' );
- } );
- it( 'should parse full GitHub URL (http) with provided branch', () => {
- const urlInfo = git.parseRepositoryUrl( 'http://github.com/ckeditor/ckeditor5-core.git#experimental' );
- expect( urlInfo.server ).to.equal( 'http://github.com/' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'experimental' );
- } );
- it( 'should parse full GitHub URL (https)', () => {
- const urlInfo = git.parseRepositoryUrl( 'https://github.com/ckeditor/ckeditor5-core.git' );
- expect( urlInfo.server ).to.equal( 'https://github.com/' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'master' );
- } );
- it( 'should parse full GitHub URL (https) with provided branch', () => {
- const urlInfo = git.parseRepositoryUrl( 'https://github.com/ckeditor/ckeditor5-core.git#t/122' );
- expect( urlInfo.server ).to.equal( 'https://github.com/' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 't/122' );
- } );
- it( 'should parse full GitHub URL (git)', () => {
- const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core.git' );
- expect( urlInfo.server ).to.equal( 'git@github.com:' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'master' );
- } );
- it( 'should parse full GitHub URL (git)', () => {
- const urlInfo = git.parseRepositoryUrl( 'git://github.com/ckeditor/ckeditor5-core.git' );
- expect( urlInfo.server ).to.equal( 'git://github.com/' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'master' );
- } );
- it( 'should parse full GitHub URL (git) with provided branch', () => {
- const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core.git#new-feature' );
- expect( urlInfo.server ).to.equal( 'git@github.com:' );
- expect( urlInfo.repository ).to.equal( 'ckeditor/ckeditor5-core.git' );
- expect( urlInfo.user ).to.equal( 'ckeditor' );
- expect( urlInfo.name ).to.equal( 'ckeditor5-core' );
- expect( urlInfo.branch ).to.equal( 'new-feature' );
- } );
- it( 'should return null if GitHub URL is not valid', () => {
- let urlInfo = git.parseRepositoryUrl( 'https://ckeditor.com' );
- expect( urlInfo ).to.equal( null );
- urlInfo = git.parseRepositoryUrl( 'https://github.com/info.html' );
- expect( urlInfo ).to.equal( null );
- } );
- } );
- describe( 'cloneRepository', () => {
- it( 'should be defined', () => expect( git.cloneRepository ).to.be.a( 'function' ) );
- it( 'should call clone commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const workspacePath = '/path/to/workspace/';
- const urlInfo = git.parseRepositoryUrl( 'git@github.com:ckeditor/ckeditor5-core#new-feature' );
- const cloneCommands = `cd ${ workspacePath } && git clone ${ urlInfo.server + urlInfo.repository }`;
- git.cloneRepository( urlInfo, workspacePath );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( cloneCommands );
- } );
- } );
- describe( 'checkout', () => {
- it( 'should be defined', () => expect( git.checkout ).to.be.a( 'function' ) );
- it( 'should call checkout commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const repositoryLocation = 'path/to/repository';
- const branchName = 'branch-to-checkout';
- const checkoutCommands = [
- `cd ${ repositoryLocation }`,
- `git checkout ${ branchName }`
- ].join( ' && ' );
- git.checkout( repositoryLocation, branchName );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( checkoutCommands );
- } );
- } );
- describe( 'pull', () => {
- it( 'should be defined', () => expect( git.pull ).to.be.a( 'function' ) );
- it( 'should call pull commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const repositoryLocation = 'path/to/repository';
- const branchName = 'branch-to-pull';
- const pullCommands = `cd ${ repositoryLocation } && git pull origin ${ branchName }`;
- git.pull( repositoryLocation, branchName );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( pullCommands );
- } );
- } );
- describe( 'fetchAll', () => {
- it( 'should be defined', () => expect( git.fetchAll ).to.be.a( 'function' ) );
- it( 'should call fetch commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const repositoryLocation = 'path/to/repository';
- const fetchCommands = `cd ${ repositoryLocation } && git fetch --all`;
- git.fetchAll( repositoryLocation );
- expect( shExecStub.calledOnce ).to.be.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.be.equal( fetchCommands );
- } );
- } );
- describe( 'initializeRepository', () => {
- it( 'should be defined', () => expect( git.initializeRepository ).to.be.a( 'function' ) );
- it( 'should call initialize commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const repositoryLocation = 'path/to/repository';
- const initializeCommands = [
- `git init ${ repositoryLocation }`
- ];
- git.initializeRepository( repositoryLocation );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( initializeCommands.join( ' && ' ) );
- } );
- } );
- describe( 'getStatus', () => {
- it( 'should be defined', () => expect( git.getStatus ).to.be.a( 'function' ) );
- it( 'should call status command', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const repositoryLocation = 'path/to/repository';
- const statusCommands = `cd ${ repositoryLocation } && git status --porcelain -sb`;
- git.getStatus( repositoryLocation );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( statusCommands );
- } );
- } );
- describe( 'initialCommit', () => {
- it( 'should be defined', () => expect( git.initialCommit ).to.be.a( 'function' ) );
- it( 'should execute commit commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const pluginName = 'ckeditor5-plugin-name';
- const repositoryPath = '/path/to/repo';
- const commitCommands = [
- `cd ${ repositoryPath }`,
- `git add .`,
- `git commit -m "Initial commit for ${ pluginName }."`
- ];
- git.initialCommit( pluginName, repositoryPath );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( commitCommands.join( ' && ' ) );
- } );
- } );
- describe( 'addRemote', () => {
- it( 'should be defined', () => expect( git.addRemote ).to.be.a( 'function' ) );
- it( 'should execute add remote commands', () => {
- const shExecStub = sandbox.stub( tools, 'shExec' );
- const gitHubPath = 'ckeditor5/ckeditor5-plugin-name';
- const repositoryPath = '/path/to/repo';
- const addRemoteCommands = [
- `cd ${ repositoryPath }`,
- `git remote add origin git@github.com:${ gitHubPath }.git`
- ];
- git.addRemote( repositoryPath, gitHubPath );
- expect( shExecStub.calledOnce ).to.equal( true );
- expect( shExecStub.firstCall.args[ 0 ] ).to.equal( addRemoteCommands.join( ' && ' ) );
- } );
- } );
- } );
- } );
|