8
0

lint.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it, beforeEach, afterEach */
  6. const sinon = require( 'sinon' );
  7. const gulp = require( 'gulp' );
  8. const stream = require( 'stream' );
  9. const Vinyl = require( 'vinyl' );
  10. const jshint = require( 'gulp-jshint' );
  11. const jscs = require( 'gulp-jscs' );
  12. const guppy = require( 'git-guppy' )( gulp );
  13. const concat = require( 'concat-stream' );
  14. const chai = require( 'chai' );
  15. const expect = chai.expect;
  16. describe( 'lint', () => {
  17. 'use strict';
  18. const config = {
  19. ROOT_DIR: '.',
  20. DIST_DIR: 'dist',
  21. IGNORED_FILES: [ 'lib/**' ]
  22. };
  23. const tasks = require( '../tasks/lint/tasks' )( config );
  24. let sandbox;
  25. beforeEach( () => {
  26. sandbox = sinon.sandbox.create();
  27. } );
  28. afterEach( () => {
  29. sandbox.restore();
  30. } );
  31. describe( 'lint()', () => {
  32. it( 'should use jshint and jscs on source files', ( done ) => {
  33. const PassThrough = stream.PassThrough;
  34. const files = [
  35. new Vinyl( {
  36. cwd: './',
  37. path: './ckeditor.js',
  38. contents: new Buffer( 'function test () {};var a;' )
  39. } )
  40. ];
  41. sandbox.stub( gulp, 'src', () => {
  42. const fakeInputStream = new stream.Readable( { objectMode: true } );
  43. fakeInputStream._read = () => {
  44. fakeInputStream.push( files.pop() || null );
  45. };
  46. return fakeInputStream;
  47. } );
  48. sandbox.stub( jscs, 'reporter', () => new PassThrough( { objectMode: true } ) );
  49. sandbox.stub( jshint, 'reporter', () => new PassThrough( { objectMode: true } ) );
  50. tasks.lint().pipe( concat( ( data ) => {
  51. expect( data.length ).to.equal( 1 );
  52. const file = data[ 0 ];
  53. expect( typeof file.jscs ).to.equal( 'object' );
  54. expect( typeof file.jshint ).to.equal( 'object' );
  55. expect( file.jscs.success ).to.equal( false );
  56. expect( file.jshint.success ).to.equal( false );
  57. done();
  58. } ) );
  59. } );
  60. } );
  61. describe( 'pre-commit', () => {
  62. it( 'should throw error when linting fails', ( done ) => {
  63. //////const PassThrough = stream.PassThrough;
  64. const files = [
  65. new Vinyl( {
  66. cwd: './',
  67. path: './ckeditor.js',
  68. contents: new Buffer( 'function test () {};var a;' )
  69. } )
  70. ];
  71. sandbox.stub( guppy, 'stream', () => {
  72. console.log( 'guppy stream' );
  73. const fakeInputStream = new stream.Readable( { objectMode: true } );
  74. fakeInputStream._read = () => {
  75. fakeInputStream.push( files.pop() || null );
  76. };
  77. return fakeInputStream;
  78. } );
  79. tasks.preCommit().pipe( concat( ( d ) => {
  80. console.log( d.length );
  81. done();
  82. } ) );
  83. } );
  84. } );
  85. } );