|
|
@@ -4,14 +4,25 @@
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
-/* global describe, it */
|
|
|
+/* global describe, it, beforeEach, afterEach */
|
|
|
|
|
|
var chai = require( 'chai' );
|
|
|
var sinon = require( 'sinon' );
|
|
|
var expect = chai.expect;
|
|
|
var tools = require( '../utils/tools' );
|
|
|
+var toRestore;
|
|
|
|
|
|
describe( 'utils', function() {
|
|
|
+ beforeEach( function() {
|
|
|
+ toRestore = [];
|
|
|
+ } );
|
|
|
+
|
|
|
+ afterEach( function() {
|
|
|
+ toRestore.forEach( function( item ) {
|
|
|
+ item.restore();
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'tools', function() {
|
|
|
describe( 'cloneRepository', function() {
|
|
|
it( 'should be defined', function() {
|
|
|
@@ -23,10 +34,9 @@ describe( 'utils', function() {
|
|
|
var name = 'test';
|
|
|
var gitHubUrl = 'ckeditor/test';
|
|
|
var destination = '/destination/dir';
|
|
|
+ toRestore.push( shExecStub );
|
|
|
|
|
|
tools.cloneRepository( name, gitHubUrl, destination );
|
|
|
- shExecStub.restore();
|
|
|
-
|
|
|
expect( shExecStub.calledOnce ).to.equal( true );
|
|
|
expect( shExecStub.firstCall.args[ 0 ] ).to.equal( 'cd ' + destination + ' && git clone git@github.com:' + gitHubUrl );
|
|
|
} );
|
|
|
@@ -38,10 +48,9 @@ describe( 'utils', function() {
|
|
|
var branch = 'branch';
|
|
|
var gitHubUrl = url + '#' + branch;
|
|
|
var destination = '/destination/dir';
|
|
|
+ toRestore.push( shExecStub );
|
|
|
|
|
|
tools.cloneRepository( name, gitHubUrl, destination );
|
|
|
- shExecStub.restore();
|
|
|
-
|
|
|
expect( shExecStub.calledOnce ).to.equal( true );
|
|
|
expect( shExecStub.firstCall.args[ 0 ] ).to.equal(
|
|
|
'cd ' + destination + ' && ' +
|
|
|
@@ -69,10 +78,9 @@ describe( 'utils', function() {
|
|
|
'cd ' + destination,
|
|
|
'npm link ' + pluginName
|
|
|
];
|
|
|
+ toRestore.push( shExecStub );
|
|
|
|
|
|
tools.npmLink( source, destination, pluginName );
|
|
|
- shExecStub.restore();
|
|
|
-
|
|
|
expect( shExecStub.calledOnce ).to.equal( true );
|
|
|
expect( shExecStub.firstCall.args[ 0 ] ).to.equal( linkCommands.join( ' && ' ) );
|
|
|
} );
|
|
|
@@ -109,5 +117,87 @@ describe( 'utils', function() {
|
|
|
expect( ckeditorDependencies[ 'ckeditor5-core' ] ).to.be.a( 'string' );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'getCKE5Directories', function() {
|
|
|
+ it( 'should return only ckeditor5 directories', function() {
|
|
|
+ var workspacePath = '/workspace/path';
|
|
|
+ var getDirectoriesStub = sinon.stub( tools, 'getDirectories', function() {
|
|
|
+ return [ 'tools', 'ckeditor5', 'ckeditor5-core', '.bin', 'ckeditor5-plugin-image' ];
|
|
|
+ } );
|
|
|
+ toRestore.push( getDirectoriesStub );
|
|
|
+ var directories = tools.getCKE5Directories( workspacePath );
|
|
|
+
|
|
|
+ expect( directories.length ).equal( 3 );
|
|
|
+ expect( directories[ 0 ] ).equal( 'ckeditor5' );
|
|
|
+ expect( directories[ 1 ] ).equal( 'ckeditor5-core' );
|
|
|
+ expect( directories[ 2 ] ).equal( 'ckeditor5-plugin-image' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'initDevWorkspace', function() {
|
|
|
+ it( 'should get ckeditor5- dependencies, clone repositories and link them', function() {
|
|
|
+ var path = require( 'path' );
|
|
|
+ var getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
|
|
|
+ var cloneRepositoryStub = sinon.stub( tools, 'cloneRepository' );
|
|
|
+ var npmLinkStub = sinon.stub( tools, 'npmLink' );
|
|
|
+ var ckeditor5Path = process.cwd();
|
|
|
+ var workspacePath = path.join( ckeditor5Path, '..' );
|
|
|
+ var dependencies, keys;
|
|
|
+ toRestore.push( getDependenciesSpy, cloneRepositoryStub, npmLinkStub );
|
|
|
+
|
|
|
+ tools.initDevWorkspace( workspacePath, ckeditor5Path, function() {} );
|
|
|
+ expect( getDependenciesSpy.calledOnce ).to.equal( true );
|
|
|
+ dependencies = getDependenciesSpy.firstCall.returnValue;
|
|
|
+
|
|
|
+ if ( dependencies ) {
|
|
|
+ keys = Object.keys( dependencies );
|
|
|
+
|
|
|
+ // All repositories were cloned.
|
|
|
+ expect( cloneRepositoryStub.callCount ).to.equal( keys.length );
|
|
|
+
|
|
|
+ // All repositories were linked.
|
|
|
+ expect( npmLinkStub.callCount ).to.equal( keys.length );
|
|
|
+
|
|
|
+ // Check clone and link parameters.
|
|
|
+ keys.forEach( function( key, i ) {
|
|
|
+ expect( cloneRepositoryStub.getCall( i ).args[0] ).equal( key );
|
|
|
+ expect( cloneRepositoryStub.getCall( i ).args[1] ).equal( dependencies[ key ] );
|
|
|
+ expect( cloneRepositoryStub.getCall( i ).args[2] ).equal( workspacePath );
|
|
|
+
|
|
|
+ expect( npmLinkStub.getCall( i ).args[0] ).equal( path.join( workspacePath, key ) );
|
|
|
+ expect( npmLinkStub.getCall( i ).args[1] ).equal( ckeditor5Path );
|
|
|
+ expect( npmLinkStub.getCall( i ).args[2] ).equal( key );
|
|
|
+ } );
|
|
|
+ }
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'getWorkspaceStatus', function() {
|
|
|
+ it( 'should get all repositories status', function() {
|
|
|
+ var path = require( 'path' );
|
|
|
+ var workspacePath = '/workspace/path/';
|
|
|
+ var directories = [ 'ckeditor5', 'ckeditor5-core' ];
|
|
|
+ var log = sinon.spy();
|
|
|
+
|
|
|
+ // Stub methods for test purposes.
|
|
|
+ var getCKE5DirectoriesStub = sinon.stub( tools, 'getCKE5Directories', function() {
|
|
|
+ return directories;
|
|
|
+ } );
|
|
|
+ var getGitStatusStub = sinon.stub( tools, 'getGitStatus', function() {
|
|
|
+ return 'status';
|
|
|
+ } );
|
|
|
+ toRestore.push( getCKE5DirectoriesStub, getGitStatusStub );
|
|
|
+
|
|
|
+ tools.getWorkspaceStatus( workspacePath, log );
|
|
|
+ expect( getCKE5DirectoriesStub.calledOnce ).equal( true );
|
|
|
+ expect( log.callCount ).equal( directories.length );
|
|
|
+ expect( getGitStatusStub.callCount ).equal( directories.length );
|
|
|
+
|
|
|
+ // Check if status was called for proper directory.
|
|
|
+ for ( var i = 0; i < getGitStatusStub.callCount; i++ ) {
|
|
|
+ expect( getGitStatusStub.getCall( i ).args[0] ).equals( path.join( workspacePath, directories[ i ] ) );
|
|
|
+ }
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|