Skip to content

Commit

Permalink
bundle: fix and document streams
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Sep 9, 2015
1 parent e5cb504 commit 2863a59
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ __api__
const sheetify = require('sheetify')

const bundler = sheetify('./index.css')
bundler.bundle((err, res) => {
if (err) return console.error(err)
console.log(res)
})
bundler.bundle().pipe(process.stdout)
```

## Options
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const styledeps = require('style-deps')
const assert = require('assert')
const xtend = require('xtend')
const noop = require('noop2')

module.exports = Sheetify

Expand All @@ -24,6 +25,7 @@ Sheetify.prototype.bundle = function (opts, done) {
done = opts
opts = {}
}
done = done || noop
assert.equal(typeof opts, 'object')
assert.equal(typeof done, 'function')

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
"dependencies": {
"cliclopts": "^1.1.1",
"minimist": "^1.2.0",
"noop2": "^2.0.0",
"style-deps": "^2.0.1",
"xtend": "^4.0.0"
},
"devDependencies": {
"concat-stream": "^1.5.0",
"dependency-check": "^2.5.0",
"faucet": "^0.0.1",
"istanbul": "^0.3.19",
"standard": "^5.2.1",
"tape": "^4.2.0",
"through2": "^2.0.0",
"wrap-selectors": "^0.1.0"
}
}
21 changes: 19 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const concat = require('concat-stream')
const wrap = require('wrap-selectors')
const test = require('tape')
const fs = require('fs')
Expand All @@ -7,6 +8,7 @@ require('./concat')
const sheetify = require('..')

test('basic', function (t) {
t.plan(2)
const expects = fs.readFileSync(__dirname + '/fixtures/basic-expected.css')
const bundler = sheetify(__dirname + '/fixtures/basic.css')

Expand All @@ -19,11 +21,27 @@ test('basic', function (t) {
bundler.bundle(function (err, output) {
t.ifError(err, 'bundled without error')
t.equal(String(expects).trim(), output.trim(), 'expected output')
t.end()
})
})

test('stream', function (t) {
t.plan(1)
const expects = fs.readFileSync(__dirname + '/fixtures/basic-expected.css')
const bundler = sheetify(__dirname + '/fixtures/basic.css')

bundler.transform(function (file) {
return function (ast, next) {
next(null, wrap()(ast))
}
})

bundler.bundle().pipe(concat(function (css) {
t.equal(expects.toString().trim(), css.toString().trim())
}))
})

test('imports', function (t) {
t.plan(2)
const expects = fs.readFileSync(__dirname + '/fixtures/imports-expected.css')
const bundler = sheetify(__dirname + '/fixtures/imports.css')

Expand All @@ -36,6 +54,5 @@ test('imports', function (t) {
bundler.bundle(function (err, output) {
t.ifError(err, 'bundled without error')
t.equal(String(expects).trim(), output.trim(), 'expected output')
t.end()
})
})

0 comments on commit 2863a59

Please sign in to comment.