Skip to content

Commit

Permalink
remove nib, reformat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Aug 18, 2015
1 parent bb4da6f commit e54bbe7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
var nib = require('nib'),
path = require('path'),
var path = require('path'),
pkg = require('./package.json');

exports = module.exports = function(opts) {
var implicit = (opts && opts.implicit == false) ? false : true;

return function(style){
style.use(nib()); // include nib
style.include(__dirname); // include axis

if (implicit) {
style.import('nib');
style.import('axis');
}
}
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
"type": "git",
"url": "git://github.com/jenius/axis.git"
},
"dependencies": {
"nib": "1.x"
},
"devDependencies": {
"accord": "0.20.x",
"stylus": "*",
"mocha": "2.x",
"should": "7.x",
"autoprefixer-stylus": "0.7.x",
"chai": "3.x",
"coffee-script": "1.9.x",
"css-parse": "2.x"
"css-parse": "2.x",
"mocha": "2.x",
"stylus": "*"
},
"scripts": {
"test": "mocha"
Expand Down
38 changes: 38 additions & 0 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var chai = require ('chai'),
path = require ('path'),
fs = require ('fs'),
accord = require ('accord'),
axis = require ('../..'),
autoprefixer = require ('autoprefixer-stylus'),
cssparse = require ('css-parse');

var test_path = path.join(__dirname, '../fixtures');
should = chai.should();

// utility functions

var compile = function(p){
return accord.load('stylus').renderFile(p, { use: [axis(), autoprefixer()] });
}

var match_expected = function(out, p, done) {
try {
var expected_path = path.join(path.dirname(p), path.basename(p, '.styl')) + '.css';
if (!fs.existsSync(expected_path)) { throw '"expected" file doesnt exist' };
var expected_contents = fs.readFileSync(expected_path, 'utf8');
cssparse(out).should.eql(cssparse(expected_contents))
} catch (err) {
return done(err)
}
done()
}

var compile_and_match = function(p, done) {
compile(p).done(function(out) { match_expected(out.result, p, done) }, done)
}

// expose needed variables globally for tests

global.test_path = test_path;
global.axis = axis;
global.compile_and_match = compile_and_match;
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--reporter spec
--compilers coffee:coffee-script/register
--require test/helpers/index
31 changes: 1 addition & 30 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
should = require 'should'
path = require 'path'
fs = require 'fs'
accord = require 'accord'
axis = require '../'
cssparse = require 'css-parse'

# utilities

test_path = path.join(__dirname, 'fixtures')

compile = (p) ->
accord.load('stylus').renderFile(p, { use: axis() })

match_expected = (out, p, done) ->
try
expected_path = path.join(path.dirname(p), path.basename(p, '.styl')) + '.css'
if not fs.existsSync(expected_path) then throw '"expected" file doesnt exist'
expected_contents = fs.readFileSync(expected_path, 'utf8')
cssparse(out).should.eql(cssparse(expected_contents))
catch err
return done(err)
done()

compile_and_match = (p, done) ->
compile(p)
.done(((out) => match_expected(out.result, p, done)), done)

# tests

describe 'api', ->

before ->
@pkg = require('../package.json')
before -> @pkg = require('../package.json')

it 'exposes the library path', ->
axis.path.should.match(/axis/)
Expand Down

0 comments on commit e54bbe7

Please sign in to comment.