Permalink
Browse files

Externalize the stylus-test-runner into own package

  • Loading branch information...
1 parent e82f616 commit 073a1780d4f46f0b376b825a961b7e7700151d18 @jasonkuhrt committed Feb 23, 2013
Showing with 7 additions and 129 deletions.
  1. +1 −6 Makefile
  2. +0 −6 package.json
  3. +0 −111 stylus-test-runner.js
  4. +6 −6 test-runner.js
View
@@ -2,11 +2,6 @@
test:
- @./node_modules/.bin/mocha \
- --require should \
- --reporter spec \
- test-runner.js
-
-
+ node test-runner.js
.PHONY: test
View
@@ -16,12 +16,6 @@
"test": "make test"
},
"devDependencies": {
- "mocha" : "~1.8.1",
- "stylus" : "~0.32.0",
- "should" : "~1.2.1",
- "clean-css" : "~0.9.1",
- "glob" : "~3.1.17",
- "lodash" : "~1.0.0-rc.3"
},
"author": "Jason Kuhrt <jasonkuhrt@me.com> (http://jasonkuhrt.com)",
"license": "MIT"
View
@@ -1,111 +0,0 @@
-
-
-
-// Stylus Test Runner
-// ------------------
-
-
-var fs = require('fs')
-var cleanCSS = require('clean-css')
-var Stylus = require('stylus')
-var glob = require('glob')
-var _ = require('lodash')
-
-
-
-module.exports = stylusTestRunner
-
-function stylusTestRunner(config) {
- var defaultConfig = { compress:true }
- describe(config.describe, function() {
- forEachTest(config, function(test) {
- it(test.description, function() {
- renderStylus(test.givenStylus, _.defaults(config, defaultConfig), function(actualCss) {
- actualCss.should.equal(test.expectedCss);
- })
- })
- })
- })
-}
-
-
-function renderStylus(stylusCode, config, callback) {
- stylus(stylusCode, config)
- .render(function(err, cssFromStylus) {
- if (err) throw err
- callback(cleanCSS.process(cssFromStylus))
- })
-}
-
-function forEachTest(config, callback) {
- var testFiles = _.reject(glob.sync(config.testDirPath + '/**/*.styl'), isEmptyFile)
- _.each(_.flatten(_.map(testFiles, getTestsFromFile)), callback)
-}
-
-
-function getTestsFromFile(filePath) {
- var fileContents = trimNewlines(fs.readFileSync(filePath, 'utf8'))
- return extractTestsFromString(fileContents)
-}
-
-
-
-function extractTestsFromString(string) {
- // Filter empty strings out, it seems that the
- // @it line leaves an empty string entry behind in the array
- return _.map(_.reject(string.split(/.*@it\s?/), isEmpty), extractTestFromString)
-}
-
-
-
-function extractTestFromString(test) {
- var description = test.match(/.*/)[0]
- test = test.replace(/.*/,'')
- stylusAndCss = test.split(/.*@expect.*/).map(trimNewlines)
-
- return {
- description : description,
- givenStylus : stylusAndCss[0],
- expectedCss : cleanCSS.process(stylusAndCss[1])
- }
-}
-
-
-
-// string utils
-
-function isEmpty(string) {
- return !string.length
-}
-
-function isEmptyFile(filePath) {
- return isEmpty(trimNewlines(fs.readFileSync(filePath, 'utf8')))
-}
-
-// whitespace mutation utils
-
-function trim(string) { return string.trim() }
-function trimNewlines(string) { return string.replace(/^(\s*|\n*)|(\s*|\n*)$/g,'') }
-
-
-
-
-
-
-// fix stylus
-
-function stylus(string, config) {
- // First through the whole config at stylus, it should ignore stuff it cannot handle
- // like use/import/include etc?
- var thisStylus = Stylus(string, config)
- // Enumerate over the config options that the stylus API only makes available by methods
- _.each(['use', 'import', 'include'], function(option){
- if (config[option]) _.each(arrayify(config[option]), thisStylus[option], thisStylus)
- })
-
- function arrayify(it) {
- return _.isArray(it) ? it : [it] ;
- }
-
- return thisStylus;
-}
View
@@ -7,11 +7,11 @@
var testRunnerConfig = {
- testDirPath : './test',
- describe : 'Shorthand Edge Omissions',
- use : require('./index'),
- import : 'shorthand-edge-omissions'
+ describe: 'Shorthand Edge Omissions',
+ stylus: {
+ use: require('./index'),
+ import: 'shorthand-edge-omissions'
+ }
}
-
-require('./stylus-test-runner')(testRunnerConfig)
+require('stylus-test-runner')(testRunnerConfig)

0 comments on commit 073a178

Please sign in to comment.