Przeglądaj źródła

Updated dev-status and dev-update tests.

Szymon Kupś 10 lat temu
rodzic
commit
6769846922
4 zmienionych plików z 234 dodań i 73 usunięć
  1. 14 10
      dev/tasks/utils/dev-status.js
  2. 110 0
      dev/tests/dev-status.js
  3. 0 63
      dev/tests/dev-tasks.js
  4. 110 0
      dev/tests/dev-update.js

+ 14 - 10
dev/tasks/utils/dev-status.js

@@ -29,19 +29,23 @@ module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, writeErro
 	if ( dependencies ) {
 		const directories = tools.getCKE5Directories( workspaceAbsolutePath );
 
-		for ( let dependency in dependencies ) {
-			const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
-			let status;
+		if ( directories.length ) {
+			for ( let dependency in dependencies ) {
+				const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
+				let status;
 
-			// Check if repository's directory already exists.
-			if ( directories.indexOf( dependency ) > -1 ) {
-				try {
-					status = git.getStatus( repositoryAbsolutePath );
-					writeln( `\x1b[1m\x1b[36m${ dependency }\x1b[0m\n${ status.trim() }` );
-				} catch ( error ) {
-					writeError( error );
+				// Check if repository's directory already exists.
+				if ( directories.indexOf( dependency ) > -1 ) {
+					try {
+						status = git.getStatus( repositoryAbsolutePath );
+						writeln( `\x1b[1m\x1b[36m${ dependency }\x1b[0m\n${ status.trim() }` );
+					} catch ( error ) {
+						writeError( error );
+					}
 				}
 			}
+		} else {
+			writeln( 'No CKEditor5 plugins in development mode.' );
 		}
 	} else {
 		writeln( 'No CKEditor5 dependencies found in package.json file.' );

+ 110 - 0
dev/tests/dev-status.js

@@ -0,0 +1,110 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it */
+
+'use strict';
+
+const sinon = require( 'sinon' );
+const tools = require( '../tasks/utils/tools' );
+const git = require( '../tasks/utils/git' );
+const path = require( 'path' );
+
+describe( 'dev-status', () => {
+	const statusTask = require( '../tasks/utils/dev-status' );
+	const ckeditor5Path = 'path/to/ckeditor5';
+	const workspaceRoot = '..';
+	const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
+	const emptyFn = () => {};
+
+	it( 'should show status of dev repositories', () => {
+		const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
+		const statusStub = sinon.stub( git, 'getStatus' );
+		const json = {
+			dependencies: {
+				'ckeditor5-core': 'ckeditor/ckeditor5-core',
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		statusTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		statusStub.restore();
+
+		sinon.assert.calledTwice( statusStub );
+		sinon.assert.calledWithExactly( statusStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
+		sinon.assert.calledWithExactly( statusStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ) );
+	} );
+
+	it( 'should not get status when no dependencies are found', () => {
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
+		const statusStub = sinon.stub( git, 'getStatus' );
+		const json = {
+			dependencies: {
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		statusTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		statusStub.restore();
+
+		sinon.assert.notCalled( statusStub );
+	} );
+
+	it( 'should not get status when no plugins in dev mode', () => {
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
+		const statusStub = sinon.stub( git, 'getStatus' );
+		const json = {
+			dependencies: {
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		statusTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		statusStub.restore();
+
+		sinon.assert.notCalled( statusStub );
+	} );
+
+	it( 'should write error message when getStatus is unsuccessful', () => {
+		const dirs = [ 'ckeditor5-core' ];
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
+		const error = new Error( 'Error message.' );
+		const statusStub = sinon.stub( git, 'getStatus' ).throws( error );
+		const json = {
+			dependencies: {
+				'ckeditor5-core': 'ckeditor/ckeditor5-core',
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+		const writeErrorSpy = sinon.spy();
+
+		statusTask( ckeditor5Path, json, workspaceRoot, emptyFn, writeErrorSpy );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		statusStub.restore();
+
+		sinon.assert.calledOnce( statusStub );
+		sinon.assert.calledOnce( writeErrorSpy );
+		sinon.assert.calledWithExactly( writeErrorSpy, error );
+	} );
+} );

+ 0 - 63
dev/tests/dev-tasks.js

@@ -151,69 +151,6 @@ describe( 'dev-tasks', () => {
 		} );
 	} );
 
-	describe( 'dev-status', () => {
-		const devStatusTask = require( '../tasks/utils/dev-status' );
-
-		it( 'should exist', () => expect( devStatusTask ).to.be.a( 'function' ) );
-
-		it( 'should show repositories status', () => {
-			const packageJSON = {
-				dependencies: {
-					'ckeditor5-core': 'ckeditor/ckeditor5-core',
-					'ckeditor5-plugin-devtest': 'ckeditor/ckeditor5-plugin-devtest',
-					'non-ckeditor-plugin': 'other/plugin'
-				}
-			};
-
-			const dirs = [ 'ckeditor5-core', 'ckeditor5-plugin-devtest' ];
-			spies.getDirectories.restore();
-			spies.getDirectories = sinon.stub( tools, 'getCKE5Directories', () => dirs );
-
-			devStatusTask( mainRepositoryPath, packageJSON, workspaceRoot, emptyFn, emptyFn );
-
-			expect( spies.getDependencies.calledOnce ).to.equal( true );
-			expect( spies.getDependencies.firstCall.args[ 0 ] ).to.equal( packageJSON.dependencies );
-			expect( spies.getStatus.calledTwice ).to.equal( true );
-			expect( spies.getStatus.firstCall.args[ 0 ] ).to.equal( path.join( workspacePath, dirs[ 0 ] ) );
-			expect( spies.getStatus.secondCall.args[ 0 ] ).to.equal( path.join( workspacePath, dirs[ 1 ] ) );
-		} );
-	} );
-
-	describe( 'dev-update', () => {
-		const devUpdateTask = require( '../tasks/utils/dev-update' );
-
-		it( 'should exist', () => expect( devUpdateTask ).to.be.a( 'function' ) );
-
-		it( 'should show repositories status', () => {
-			const packageJSON = {
-				dependencies: {
-					'ckeditor5-core': 'ckeditor/ckeditor5-core',
-					'ckeditor5-plugin-devtest': 'ckeditor/ckeditor5-plugin-devtest',
-					'non-ckeditor-plugin': 'other/plugin'
-				}
-			};
-
-			const dirs = [ 'ckeditor5-core', 'ckeditor5-plugin-devtest' ];
-			spies.getDirectories.restore();
-			spies.getDirectories = sinon.stub( tools, 'getCKE5Directories', () => dirs );
-
-			devUpdateTask( mainRepositoryPath, packageJSON, workspaceRoot, emptyFn, emptyFn );
-
-			expect( spies.getDependencies.calledOnce ).to.equal( true );
-			expect( spies.getDependencies.firstCall.args[ 0 ] ).to.equal( packageJSON.dependencies );
-			expect( spies.parseRepositoryUrl.calledTwice ).to.equal( true );
-			expect( spies.pull.calledTwice ).to.equal( true );
-
-			let urlInfo = spies.parseRepositoryUrl.firstCall.returnValue;
-			expect( spies.pull.firstCall.args[ 0 ] ).to.equal( path.join( workspacePath, dirs[ 0 ] ) );
-			expect( spies.pull.firstCall.args[ 1 ] ).to.equal( urlInfo.branch );
-
-			urlInfo = spies.parseRepositoryUrl.secondCall.returnValue;
-			expect( spies.pull.secondCall.args[ 0 ] ).to.equal( path.join( workspacePath, dirs[ 1 ] ) );
-			expect( spies.pull.secondCall.args[ 1 ] ).to.equal( urlInfo.branch );
-		} );
-	} );
-
 	describe( 'dev-boilerplate-update', () => {
 		const devBoilerplateTask = require( '../tasks/utils/dev-boilerplate-update' );
 

+ 110 - 0
dev/tests/dev-update.js

@@ -0,0 +1,110 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it */
+
+'use strict';
+
+const sinon = require( 'sinon' );
+const tools = require( '../tasks/utils/tools' );
+const git = require( '../tasks/utils/git' );
+const path = require( 'path' );
+
+describe( 'dev-init', () => {
+	const updateTask = require( '../tasks/utils/dev-update' );
+	const ckeditor5Path = 'path/to/ckeditor5';
+	const workspaceRoot = '..';
+	const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
+	const emptyFn = () => {};
+
+	it( 'should update dev repositories', () => {
+		const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
+		const pullStub = sinon.stub( git, 'pull' );
+		const json = {
+			dependencies: {
+				'ckeditor5-core': 'ckeditor/ckeditor5-core',
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		pullStub.restore();
+
+		sinon.assert.calledTwice( pullStub );
+		sinon.assert.calledWithExactly( pullStub.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ), 'master' );
+		sinon.assert.calledWithExactly( pullStub.secondCall, path.join( workspaceAbsolutePath, dirs[ 1 ] ), 'new-branch' );
+	} );
+
+	it( 'should not update when no dependencies are found', () => {
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' );
+		const pullStub = sinon.stub( git, 'pull' );
+		const json = {
+			dependencies: {
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		pullStub.restore();
+
+		sinon.assert.notCalled( pullStub );
+	} );
+
+	it( 'should not update when no plugins in dev mode', () => {
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( [] );
+		const pullStub = sinon.stub( git, 'pull' );
+		const json = {
+			dependencies: {
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+
+		updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, emptyFn );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		pullStub.restore();
+
+		sinon.assert.notCalled( pullStub );
+	} );
+
+	it( 'should write error message when pulling is unsuccessful', () => {
+		const dirs = [ 'ckeditor5-core' ];
+		const getDependenciesSpy = sinon.spy( tools, 'getCKEditorDependencies' );
+		const getDirectoriesStub = sinon.stub( tools, 'getCKE5Directories' ).returns( dirs );
+		const error = new Error( 'Error message.' );
+		const pullStub = sinon.stub( git, 'pull' ).throws( error );
+		const json = {
+			dependencies: {
+				'ckeditor5-core': 'ckeditor/ckeditor5-core',
+				'ckeditor5-devtest': 'ckeditor/ckeditor5-devtest#new-branch',
+				'other-plugin': '1.2.3'
+			}
+		};
+		const writeErrorSpy = sinon.spy();
+
+		updateTask( ckeditor5Path, json, workspaceRoot, emptyFn, writeErrorSpy );
+
+		getDependenciesSpy.restore();
+		getDirectoriesStub.restore();
+		pullStub.restore();
+
+		sinon.assert.calledOnce( pullStub );
+		sinon.assert.calledOnce( writeErrorSpy );
+		sinon.assert.calledWithExactly( writeErrorSpy, error );
+	} );
+} );