UNPKG

pipeline-validate-js

Version:
131 lines (94 loc) 3.44 kB
'use strict'; var chai = require('chai'); var handyman = require('pipeline-handyman'); var isStream = require('isstream'); var sinon = require('sinon'); var sinonChai = require('sinon-chai'); var dirtyChai = require('dirty-chai'); var fs = require('fs-extra'); var path = require('path'); var rimraf = require('rimraf'); var validatePipeline = require('../src/index.js'); var expect = chai.expect; var esLint = require('gulp-eslint'); chai.should(); chai.use(sinonChai); chai.use(dirtyChai); describe('pipeline-validateJS', function () { var esLintFilePath; var mockLintConfigPath; var pipeline; before(function () { esLintFilePath = path.join(process.cwd(), '.eslintrc'); mockLintConfigPath = path.join(process.cwd(), 'node_modules/pipeline-validate-js/.eslintrc'); pipeline = validatePipeline.validateJS; try { // file exists, do nothing fs.accessSync(mockLintConfigPath); } catch (ex) { fs.copySync(esLintFilePath, mockLintConfigPath); } }); after(function () { rimraf.sync(mockLintConfigPath.replace('.eslintrc', '')); }); describe('validateJS method', function () { it('should expose a validateJS method', function () { expect(validatePipeline.validateJS).to.exist(); expect(validatePipeline.validateJS).to.be.a('function'); }); it('should return a stream object', function () { expect(validatePipeline.validateJS()).to.be.an('object'); expect(isStream(validatePipeline.validateJS())).to.be.true(); }); describe('validateJS pipeline with no options', function () { var sandbox = {}; var spy = {}; beforeEach(function () { sandbox = sinon.sandbox.create(); spy = sandbox.spy(handyman, 'log'); }); afterEach(function () { sandbox.restore(); }); it('should test validateJS() with no options', function () { pipeline(); spy.should.have.been.calledWith('Validating js with ESlint'); }); it('should utilize eslint.format when no options are provided', function () { var spy = sinon.spy(esLint, 'format'); pipeline(); expect(spy).to.have.been.called(); }); it('should utilize eslint.failOnError when no options are provided', function () { var spy = sinon.spy(esLint, 'failOnError'); pipeline(); expect(spy).to.have.been.called(); }); }); describe('ValidateJS Pipeline with custom formatter', function () { it('should utilize eslint.format when a custom formatter name is provided', function () { var spy = esLint.format; pipeline({ formatter: 'checkstyle' }); expect(spy).to.have.been.calledWith('checkstyle'); }); it('should utilize eslint.format when a custom formatter function is provided', function () { var spy = esLint.format; var dummyFunc = function () { }; pipeline({ formatter: dummyFunc }); expect(spy).to.have.been.calledWith(dummyFunc); }); }); describe('ValidateJS Pipeline without failing on an error', function () { it('should not utilize eslint.failOnError when the failOnError options is "false"', function () { var spy = esLint.failOnError; spy.reset(); pipeline({ failOnError: false }); expect(spy).to.have.not.been.called(); }); }); }); });