Skip to content
This repository was archived by the owner on Jun 25, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var through = require("through2")
var cssnext = require("cssnext")
var gutil = require("gulp-util")
var objectAssign = require("object-assign")
var PluginError = gutil.PluginError

function transform(opts) {
return function(file, enc, cb) {
var contents
var transformed
var options = opts || {}
var options = objectAssign({}, opts)
if (file.isStream()) {
return cb(
new PluginError("gulp-cssnext", "streaming not supported")
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"cssnext": "^1.0.0",
"gulp-util": "^3.0.0",
"object-assign": "~4.0.1",
"through2": "^0.6.1"
},
"devDependencies": {
Expand Down
87 changes: 33 additions & 54 deletions test/cssnext.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
var tape = require("tape")
var gutil = require("gulp-util")
var through2 = require("through2")
var cssnext = require("..")

var fs = require("fs")
var path = require("path")

function read(file, encoding) {
return fs.readFileSync(path.resolve(__dirname, file), encoding)
}

tape("cssnext", function(test) {
var stream = cssnext()
var file = new gutil.File({
base: ".",
path: ".",
contents: new Buffer(
fs.readFileSync(
path.resolve(__dirname, "fixtures/index.css"),
{encoding: "utf8"}
)
),
contents: read("fixtures/index.css"),
})

stream.on("data", function(data) {
test.equal(
data.contents.toString(),
fs.readFileSync(
path.resolve(__dirname, "expected/index.css"),
{encoding: "utf8"}
)
)
test.equal(data.contents.toString(), read("expected/index.css", "utf8"))
test.end()
})
stream.end(file)
Expand All @@ -36,10 +30,7 @@ tape("cssnext throws if stream", function(test) {
var file = new gutil.File({
base: ".",
path: ".",
contents: fs.createReadStream(
path.resolve(__dirname, "fixtures/index.css"),
{encoding: "utf8"}
),
contents: through2(),
})
stream.on("error", function(err) {
test.equal(err.message, "streaming not supported")
Expand Down Expand Up @@ -72,45 +63,33 @@ tape("throws on cssnext error", function(test) {
tape(
"Resolves relative paths for consecutive files in different paths",
function(test) {
var stream = cssnext()
var file = new gutil.File({
base: "./test/fixtures/",
path: "./test/fixtures/import.css",
contents: new Buffer(
fs.readFileSync(
path.resolve(__dirname, "fixtures/import.css"),
{encoding: "utf8"}
)
),
})
stream.write(file)
test.plan(4)

var file2 = new gutil.File({
base: "./test/fixtures/import/",
path: "./test/fixtures/import/index.css",
contents: new Buffer(
fs.readFileSync(
path.resolve(__dirname, "fixtures/import/index.css"),
{encoding: "utf8"}
)
),
})
stream.write(file2)
function testTwoFiles(options) {
var stream = cssnext(options)

var count = 0
stream.on("data", function(data) {
var file1 = new gutil.File({
base: "./test/fixtures/",
path: "./test/fixtures/import.css",
contents: read("fixtures/import.css"),
})

test.equal(
data.contents.toString(),
fs.readFileSync(
path.resolve(__dirname, "expected/index.css"),
{encoding: "utf8"}
)
)
++count
if (count === 2) {
test.end()
}
})
var file2 = new gutil.File({
base: "./test/fixtures/import/",
path: "./test/fixtures/import/index.css",
contents: read("fixtures/import/index.css"),
})

stream.on("data", function(data) {
var expected = read("expected/index.css", "utf8")
test.equal(data.contents.toString(), expected)
})

stream.write(file1)
stream.end(file2)
}

testTwoFiles()
testTwoFiles({})
}
)