Skip to content

Commit

Permalink
#21 set from and to processing options
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Apr 11, 2015
1 parent 88191a8 commit 2068405
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function (processors, options) {
}
}

opts.from = file.path
opts.from = opts.to = file.path

// Generate separate source map for gulp-sourcemap
if (file.sourceMap) {
Expand All @@ -58,7 +58,7 @@ module.exports = function (processors, options) {
map = result.map.toJSON()
map.file = file.relative
map.sources = [].map.call(map.sources, function (source) {
return path.relative(file.base, source)
return path.join(path.dirname(file.relative), source)
})
applySourceMap(file, map)
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
"vinyl-sourcemaps-apply": "^0.1.4"
},
"devDependencies": {
"es6-promise": "^2.0.1",
"gulp-sourcemaps": "^1.5.1",
"mocha": "^2.2.1"
"mocha": "^2.2.1",
"proxyquire": "^1.4.0",
"sinon": "^1.14.1"
}
}
48 changes: 45 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global it, Promise */
/* global it, beforeEach, afterEach, describe, Promise */

require('es6-promise').polyfill()
var assert = require('assert')
var gutil = require('gulp-util')
var sourceMaps = require('gulp-sourcemaps')
var postcss = require('./index')

var proxyquire = require('proxyquire')
var sinon = require('sinon')

it('should transform css with multiple processors', function (cb) {

Expand Down Expand Up @@ -111,6 +111,48 @@ it('should correctly generate relative source map', function (cb) {
})


describe('PostCSS Guidelines', function () {

var sandbox = sinon.sandbox.create()
var postcssStub = {
use: sandbox.stub()
, process: sandbox.stub()
}
var postcss = proxyquire('./index', {
postcss: function () {
return postcssStub
}
})


afterEach(function () {
sandbox.restore()
})


it('should set `from` and `to` processing options to `file.path`', function (cb) {

var stream = postcss([ doubler ])
var cssPath = __dirname + '/src/fixture.css'
postcssStub.process.returns(Promise.resolve({css:''}))

stream.on('data', function () {
postcssStub.process.calledWith('a {}', {from: cssPath, to: cssPath})
cb()
})

stream.write(new gutil.File({
contents: new Buffer('a {}')
, path: cssPath
}))

stream.end()

})

})


function doubler (css) {
css.eachDecl(function (decl) {
decl.parent.prepend(decl.clone())
Expand Down

0 comments on commit 2068405

Please sign in to comment.