Selaa lähdekoodia

Tests for jshint/jscs tasks.

Szymon Kupś 10 vuotta sitten
vanhempi
commit
7b2456b1c0
4 muutettua tiedostoa jossa 105 lisäystä ja 3 poistoa
  1. 1 1
      .jshintrc
  2. 2 2
      dev/tasks/lint/tasks.js
  3. 100 0
      dev/tests/lint.js
  4. 2 0
      package.json

+ 1 - 1
.jshintrc

@@ -11,5 +11,5 @@
 	"strict": true,
 	"varstmt": true,
 
-	"globalstrict": true
+	"strict": "global"
 }

+ 2 - 2
dev/tasks/lint/tasks.js

@@ -80,9 +80,9 @@ module.exports = ( config ) => {
 	 * @returns { Stream }
 	 */
 	function lint() {
-		const stream = jscs();
+		const stream = jshint();
 		stream
-			.pipe( jshint() )
+			.pipe( jscs() )
 			.pipe( jscs.reporter() )
 			.pipe( jshint.reporter( 'jshint-reporter-jscs' ) );
 

+ 100 - 0
dev/tests/lint.js

@@ -0,0 +1,100 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it, beforeEach, afterEach */
+
+const sinon = require( 'sinon' );
+const gulp = require( 'gulp' );
+const stream = require( 'stream' );
+const Vinyl = require( 'vinyl' );
+const jshint = require( 'gulp-jshint' );
+const jscs = require( 'gulp-jscs' );
+const guppy = require( 'git-guppy' )( gulp );
+const concat = require( 'concat-stream' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+
+describe( 'lint', () => {
+	'use strict';
+
+	const config = {
+		ROOT_DIR: '.',
+		DIST_DIR: 'dist',
+		IGNORED_FILES: [ 'lib/**' ]
+	};
+	const tasks = require( '../tasks/lint/tasks' )( config );
+	let sandbox;
+
+	beforeEach( () => {
+		sandbox = sinon.sandbox.create();
+	} );
+
+	afterEach( () => {
+		sandbox.restore();
+	} );
+
+	describe( 'lint()', () => {
+		it( 'should use jshint and jscs on source files', ( done ) => {
+			const PassThrough = stream.PassThrough;
+			const files = [
+				new Vinyl( {
+					cwd: './',
+					path: './ckeditor.js',
+					contents: new Buffer( 'function test () {};var a;' )
+				} )
+			];
+
+			sandbox.stub( gulp, 'src', () => {
+				const fakeInputStream = new stream.Readable( { objectMode: true } );
+				fakeInputStream._read = () => {
+					fakeInputStream.push( files.pop() || null );
+				};
+
+				return fakeInputStream;
+			} );
+
+			sandbox.stub( jscs, 'reporter', () => new PassThrough( { objectMode: true } ) );
+			sandbox.stub( jshint, 'reporter', () => new PassThrough( { objectMode: true } ) );
+
+			tasks.lint().pipe( concat( ( data ) => {
+				expect( data.length ).to.equal( 1 );
+				const file = data[ 0 ];
+				expect( typeof file.jscs ).to.equal( 'object' );
+				expect( typeof file.jshint ).to.equal( 'object' );
+				expect( file.jscs.success ).to.equal( false );
+				expect( file.jshint.success ).to.equal( false );
+				done();
+			} ) );
+		} );
+	} );
+
+	describe( 'pre-commit', () => {
+		it( 'should throw error when linting fails', ( done ) => {
+			//////const PassThrough = stream.PassThrough;
+			const files = [
+				new Vinyl( {
+					cwd: './',
+					path: './ckeditor.js',
+					contents: new Buffer( 'function test () {};var a;' )
+				} )
+			];
+
+			sandbox.stub( guppy, 'stream', () => {
+				console.log( 'guppy stream' );
+				const fakeInputStream = new stream.Readable( { objectMode: true } );
+				fakeInputStream._read = () => {
+					fakeInputStream.push( files.pop() || null );
+				};
+
+				return fakeInputStream;
+			} );
+
+			tasks.preCommit().pipe( concat( ( d ) => {
+				console.log( d.length );
+				done();
+			} ) );
+		} );
+	} );
+} );

+ 2 - 0
package.json

@@ -23,6 +23,7 @@
     "benderjs-promise": "^0.1.0",
     "benderjs-sinon": "^0.3.0",
     "chai": "^3.4.0",
+    "concat-stream": "^1.5.1",
     "del": "^2.0.2",
     "git-guppy": "^1.0.1",
     "gulp": "^3.9.0",
@@ -38,6 +39,7 @@
     "guppy-pre-commit": "^0.3.0",
     "inquirer": "^0.11.0",
     "istanbul": "^0.4.1",
+    "jshint": "^2.9.1",
     "jshint-reporter-jscs": "^0.1.0",
     "jshint-stylish": "^2.1.0",
     "merge-stream": "^1.0.0",