From 0802ed9b2f919322efb16cbf414085be339eb3a9 Mon Sep 17 00:00:00 2001 From: billybonks Date: Thu, 8 Sep 2016 18:47:09 +0800 Subject: [PATCH 1/2] rename generateTests to disableTestGeneration, so plugin generates tests by default --- README.md | 41 ++++++++++++++++++++++++++++++++++------- index.js | 14 ++++++++------ tests/test.js | 13 ++++--------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0a9df1c..ddca6d0 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,11 @@ var node = new StyleLint('app/styles'); the default output will be the same SCSS files, in the same tree structure. -###Generating Tests +###Tests -`var node = new StyleLint('app/styles', {generateTests:true});` - -Instead of receiving a tree of scss files, the plugin will output a tree of test files +Tests are automatically generated +If tests are generated the plugin will output a tree of test files **original tree** ``` @@ -60,7 +59,35 @@ new Funnel(node, { srcDir:'tests', }); ``` -See below for more advaned test configurations + +If test generation is disabled the plugin will return the original tree + +** Disable test generation ** +set the option `disableTestGeneration:true` + +`var node = new StyleLint('app/styles', {disableTestGeneration:true});` + +** Custom test generator ** +If you want to build your own test generator set the `testGenerator` option to a function that will generate the tests + +```javascript +StyleLinter.prototype.testGenerator = function(relativePath, errors) { + var assertions = []; + var module = "module('Style Lint');\n"; + var test = "test('" + relativePath + " should pass stylelint', function() {\n"; + if(!errors){ + var assertion = " ok(\'true , "+relativePath+" passed stylelint\');"; + return module+test+assertion+"\n});\n"; + } else { + for(var i = 0; i < errors.warnings.length; i++){ + var warning = errors.warnings[i]; + var index = warning.line+':'+warning.column; + assertions.push(" ok(" + false + ", '"+index +" "+this.escapeErrorString(warning.text)+"');"); + } + return module+test+assertions.join('\n')+"\n});\n"; + } +}; +``` Configuration ===== @@ -90,9 +117,9 @@ If true it will generate a unit test if the file fails lint. If true it will generate a unit test if the passes fails lint. -`generateTests` {boolean} +`disableTestGeneration` {boolean} -If true it will generate tests for both passing and failing tests, overrides the testPassingFiles and testFailingFiles +Will disable generation of tests `disableConsoleLogging` {boolean} diff --git a/index.js b/index.js index 6d3f5ff..5a69d2f 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ StyleLinter.prototype.constructor = StyleLinter; /* Used to extract and delete options from input hash */ StyleLinter.prototype.availableOptions = ['onError', - 'generateTests', + 'disableTestGeneration', 'testFailingFiles', 'testPassingFiles' , 'testGenerator', @@ -23,7 +23,7 @@ StyleLinter.prototype.availableOptions = ['onError', * - linterConfig (StyleLint options) * - onError (Hook when error occurs) * - testGenerator (Hook for custom test generation) - * - generateTests (Generate tests for all files) + * - disableTestGeneration (Disable generatation tests for all files) * - testFailingFiles (Generate tests for failing files) * - testPassingFiles (Generate tests for passing files) * - log (Disables error logging in console) @@ -56,11 +56,13 @@ function StyleLinter(inputNodes, options) { formatter: 'string' }); - if(this.generateTests === false || this.generateTests === true){ - this.testFailingFiles = this.generateTests; - this.testPassingFiles = this.generateTests; + if(typeof this.testFailingFiles === 'undefined' && typeof this.testPassingFiles === 'undefined' && typeof this.disableTestGeneration === 'undefined'){ + this.testFailingFiles = true; + this.testPassingFiles = true; + }else if( typeof this.disableTestGeneration !== 'undefined' ){ + this.testFailingFiles = typeof this.testFailingFiles === 'undefined' ? !this.disableTestGeneration : this.testFailingFiles; + this.testPassingFiles = typeof this.testPassingFiles === 'undefined' ? !this.disableTestGeneration : this.testPassingFiles; } - this.linterConfig.files = null; this.setSyntax(this.linterConfig.syntax); diff --git a/tests/test.js b/tests/test.js index f0c56a3..e67e256 100644 --- a/tests/test.js +++ b/tests/test.js @@ -127,9 +127,9 @@ describe('Broccoli StyleLint Plugin', function() { it('sets options on object', function(){ var linterConfig = {syntax:'scss'}; - var options = {linterConfig:linterConfig, generateTests:true}; + var options = {linterConfig:linterConfig, disableTestGeneration:true}; var linter = new StyleLinter('', options); - expect(linter.generateTests).to.equal(true); + expect(linter.disableTestGeneration).to.equal(true); expect(linter.linterConfig).to.eql(linterConfig); }); @@ -145,7 +145,6 @@ describe('Broccoli StyleLint Plugin', function() { describe('Generate Tests', function(){ it('accepted testGenerator property', function() { var opt = { - generateTests:true, testGenerator:function(relativePath, errors){ return "custom test" } @@ -157,12 +156,8 @@ describe('Broccoli StyleLint Plugin', function() { ).to.eventually.equal(test); }) - it('generates all tests regardless of other test config when true', function() { - generatorOptionsTest(3,{generateTests:true}); - }); - - it('generates no tests regardless of other test config when false', function() { - generatorOptionsTest(3,{generateTests:true}); + it('generates no tests regardless of other test config when disableTestGeneration is true', function() { + generatorOptionsTest(3,{disableTestGeneration:true}); }); }); function buildAndAssertFile(options, relativePath, equal) { From 905fe99763e8e080738811687638664d62a7fc3f Mon Sep 17 00:00:00 2001 From: billybonks Date: Thu, 8 Sep 2016 18:48:06 +0800 Subject: [PATCH 2/2] add missing options to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ddca6d0..401c5e1 100644 --- a/README.md +++ b/README.md @@ -124,3 +124,9 @@ Will disable generation of tests `disableConsoleLogging` {boolean} If true it will disable logging of errors to console + +`log` {boolean} +If true it will log results to console + +`console` {object} +A custom console object