Skip to content

Commit

Permalink
Merge pull request #8 from billybonks/enhancement/rename-generateTest…
Browse files Browse the repository at this point in the history
…-property

Enhancement/rename generate test property
  • Loading branch information
billybonks authored Sep 8, 2016
2 parents 22e41f1 + 905fe99 commit ae26771
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
```
Expand Down Expand Up @@ -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
=====
Expand Down Expand Up @@ -90,10 +117,16 @@ 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}

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
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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"
}
Expand All @@ -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) {
Expand Down

0 comments on commit ae26771

Please sign in to comment.