8
0
Просмотр исходного кода

Added tests for execOnRepositories function in exec/tasks module.

Maksymilian Barnaś 9 лет назад
Родитель
Сommit
0d4947986a
1 измененных файлов с 113 добавлено и 0 удалено
  1. 113 0
      dev/tests/exec/tasks.js

+ 113 - 0
dev/tests/exec/tasks.js

@@ -0,0 +1,113 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it, beforeEach, afterEach */
+
+'use strict';
+
+const mockery = require( 'mockery' );
+const sinon = require( 'sinon' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+
+describe( 'exec-tasks', () => {
+	let sandbox;
+	const config = {
+		WORKSPACE_DIR: '/path/exec/'
+	};
+
+	beforeEach( () => {
+		mockery.enable( {
+			useCleanCache: true,
+			warnOnReplace: false,
+			warnOnUnregistered: false
+		} );
+		sandbox = sinon.sandbox.create();
+	} );
+
+	afterEach( () => {
+		mockery.disable();
+		sandbox.restore();
+	} );
+
+	describe( 'execOnRepositories', () => {
+		it( 'should throw error when there is no specified task', () => {
+			const errorMessage = 'Missing task parameter: --task task-name';
+			const log = require( '../../utils/log' );
+			const logErrSpy = sandbox.spy( log, 'err' );
+
+			mockery.registerMock( 'minimist', () => {
+				return { };
+			} );
+			const tasks = require( '../../tasks/exec/tasks' )( config );
+
+			tasks.execOnRepositories();
+
+			sinon.assert.calledOnce( logErrSpy );
+			expect( logErrSpy.firstCall.args[ 0 ] ).to.be.an( 'error' );
+			expect( logErrSpy.firstCall.args[ 0 ].message ).to.equal( errorMessage );
+		} );
+
+		it( 'should throw error when task cannot be found', () => {
+			const log = require( '../../utils/log' );
+			const logErrSpy = sandbox.spy( log, 'err' );
+
+			mockery.registerMock( 'minimist', () => {
+				return { task: 'task-to-run' };
+			} );
+			const tasks = require( '../../tasks/exec/tasks' )( config );
+
+			tasks.execOnRepositories();
+
+			sinon.assert.calledOnce( logErrSpy );
+			expect( logErrSpy.firstCall.args[ 0 ] ).to.be.an( 'error' );
+			expect( logErrSpy.firstCall.args[ 0 ].code ).to.equal( 'MODULE_NOT_FOUND' );
+		} );
+
+		it( 'should load task module', () => {
+			const ckeditor5Dirs = require( '../../utils/ckeditor5-dirs' );
+			const log = require( '../../utils/log' );
+			const logErrSpy = sandbox.spy( log, 'err' );
+
+			sandbox.stub( ckeditor5Dirs, 'getDevDirectories' ).returns( [] );
+			mockery.registerMock( 'minimist', () => {
+				return { task: 'task-to-run' };
+			} );
+			mockery.registerMock( './functions/task-to-run', () => {} );
+			const tasks = require( '../../tasks/exec/tasks' )( config );
+
+			tasks.execOnRepositories();
+
+			sinon.assert.notCalled( logErrSpy );
+		} );
+
+		it( 'should execute task over directories', () => {
+			const ckeditor5Dirs = require( '../../utils/ckeditor5-dirs' );
+			const taskStub = sinon.stub();
+
+			mockery.registerMock( 'minimist', () => {
+				return { task: 'task-to-run' };
+			} );
+			sandbox.stub( ckeditor5Dirs, 'getDevDirectories' ).returns( [
+				{
+					repositoryPath: '/path/1',
+					repositoryURL: 'repo/test1'
+				},
+				{
+					repositoryPath: '/path/2',
+					repositoryURL: 'repo/test2'
+				}
+			] );
+			mockery.registerMock( './functions/task-to-run', taskStub );
+			const tasks = require( '../../tasks/exec/tasks' )( config );
+
+			tasks.execOnRepositories();
+
+			sinon.assert.calledTwice( taskStub );
+			sinon.assert.calledWith( taskStub, '/path/1', { task: 'task-to-run' } );
+			sinon.assert.calledWith( taskStub, '/path/2', { task: 'task-to-run' } );
+		} );
+	} );
+} );