Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSSLint mix helper from utils to mix up cli and rc options
- Loading branch information
Showing
4 changed files
with
190 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*jshint node:true*/ | ||
"use strict"; | ||
var | ||
stub = { | ||
logbook: function (log) { | ||
this.logs.push(log); | ||
}, | ||
readLogs: function () { | ||
return this.logs.slice(); | ||
}, | ||
|
||
getFullPath: function (path) { | ||
return path; | ||
}, | ||
getFiles: function (dir) { | ||
var | ||
filesobj = this.fakedFs[dir], | ||
fileix, | ||
out = []; | ||
for (fileix in filesobj) { | ||
if ( filesobj.hasOwnProperty(fileix) && /\.css$/.test(fileix) ) { | ||
out.push(dir + "/" + fileix); | ||
} | ||
} | ||
return out; | ||
}, | ||
readFile: function (path) { | ||
var | ||
spath = path.split("/"), | ||
spathLen = spath.length, | ||
i, | ||
out = this.fakedFs; | ||
|
||
for (i = 0; i < spathLen; i += 1) { | ||
out = out[spath[i]]; | ||
} | ||
|
||
return out; | ||
}, | ||
isDirectory: function (checkit) { | ||
var | ||
result = this.fakedFs[checkit]; | ||
return typeof result === "object"; | ||
}, | ||
print: function (msg) { | ||
this.logbook(msg); | ||
}, | ||
quit: function (signal) { | ||
this.logbook(signal); | ||
} | ||
}; | ||
|
||
module.exports = function (setup) { | ||
var | ||
api, | ||
setix; | ||
|
||
api = Object.create(stub); | ||
|
||
for (setix in setup) { | ||
if (setup.hasOwnProperty(setix)) { | ||
api[setix] = setup[setix]; | ||
} | ||
} | ||
|
||
api.logs = []; | ||
return api; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
"suites": { | ||
"config csslintrc override": { | ||
"args": [ | ||
"--config=.rc1", | ||
"dir" | ||
], | ||
"expecting": [ | ||
"csslint: No errors in dir/a.css.", | ||
"csslint: No errors in dir/b.css.", | ||
0 | ||
] | ||
}, | ||
"straight linting": { | ||
"args": [ | ||
"dir" | ||
], | ||
"expecting": [ | ||
"csslint: There is 1 problem in dir/a.css.", | ||
"csslint: There is 1 problem in dir/b.css.", | ||
0 | ||
] | ||
}, | ||
"version": { | ||
"args": [ | ||
"--version" | ||
], | ||
"expecting": [ | ||
"v@VERSION@", | ||
0 | ||
] | ||
} | ||
}, | ||
|
||
"fakedFs": { | ||
".rc1": "--ignore=important,ids", | ||
"dir": { | ||
"a.css": ".a {color: red!important;}", | ||
"b.css": "#a {color: red;}" | ||
}, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*jshint loopfunc:true, node:true */ | ||
// mainly for testing --config cli option | ||
"use strict"; | ||
function include(path, sandbox) { | ||
var | ||
vm = require("vm"), | ||
fs = require("fs"), | ||
file; | ||
|
||
file = fs.readFileSync(path); | ||
vm.runInNewContext(file, sandbox); | ||
} | ||
|
||
|
||
|
||
(function(){ | ||
|
||
var Assert = YUITest.Assert, | ||
suite = new YUITest.TestSuite("General Tests for CLI"), | ||
apiStub = require("./tests/cli/assets/apiStub.js"), | ||
data = require("./tests/cli/assets/data.js"), | ||
suites = data.suites, | ||
suiteix, | ||
sandbox = { | ||
CSSLint: CSSLint | ||
}; | ||
|
||
include(__dirname + "/src/cli/common.js", sandbox); /* expose sandbox.cli */ | ||
|
||
for (suiteix in suites) { | ||
if (suites.hasOwnProperty(suiteix)) { | ||
(function (suiteix) { | ||
|
||
suite.add(new YUITest.TestCase({ | ||
|
||
name: "Test " + suiteix, | ||
|
||
"Outcome logs should match expected": function (){ | ||
var | ||
it = suites[suiteix], | ||
expecting = it.expecting, | ||
expectingLen = expecting.length, | ||
outcome, | ||
api, | ||
exp, | ||
out, | ||
i = 0; | ||
|
||
data.args = it.args.slice(); | ||
api = apiStub(data); | ||
sandbox.cli(api); | ||
outcome = api.readLogs(); | ||
|
||
for (i; i < expectingLen; i += 1) { | ||
exp = expecting[i]; | ||
out = outcome[i]; | ||
|
||
if ( typeof out === "string") { | ||
out = /^.*/.exec(out.trim())[0]; | ||
} | ||
if ( exp !== out ) { | ||
Assert.fail("Expecting: " + exp + " Got: " + out); | ||
} | ||
} | ||
Assert.pass(); | ||
|
||
} | ||
})); | ||
})(suiteix); | ||
} | ||
} | ||
|
||
YUITest.TestRunner.add(suite); | ||
})(); |