Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
This commit also updates test format because PostCSS v6 keeps `raws`
property as much as possible.
  • Loading branch information
hail2u committed May 7, 2017
1 parent 7955635 commit 5acecc9
Show file tree
Hide file tree
Showing 23 changed files with 290 additions and 167 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -10,11 +10,11 @@
"url": "https://github.com/hail2u/node-css-mqpacker/issues"
},
"dependencies": {
"minimist": "^1.1.1",
"postcss": "^5.0.0"
"minimist": "^1.2.0",
"postcss": "^6.0.0"
},
"devDependencies": {
"nodeunit": "^0.10.2"
"nodeunit": "^0.11.0"
},
"engines": {
"node": ">=5.0.0"
Expand Down
111 changes: 72 additions & 39 deletions test/css-mqpacker_test.js
@@ -1,82 +1,120 @@
"use strict";

var fs = require("fs");
var path = require("path");
var postcss = require("postcss");
const fs = require("fs");
const path = require("path");
const postcss = require("postcss");

var mqpacker = require("../index");
const mqpacker = require("../index");

exports["Public API"] = function (test) {
var expected;
var input = "@media (min-width:1px) {\n .foo {\n color: black\n }\n}";
expected = postcss().process(input).css;
exports["Public API"] = (test) => {
const input = `.foo {
z-index: 0;
}
test.expect(2);
@media (min-width:1px) {
.foo {
z-index: 1;
}
}
`;
const expected = postcss().process(input).css;

test.expect(2);
test.strictEqual(
postcss([mqpacker()]).process(input).css,
expected
);

test.strictEqual(
mqpacker.pack(input).css,
expected
);

test.done();
};

exports["Option: PostCSS options"] = function (test) {
var expected;
var input = "@media (min-width:1px) {\n .foo {\n color: black\n }\n}\n\n/*# sourceMappingURL=from.css.map */\n";
var opts = {
exports["Option: PostCSS options"] = (test) => {
const input = `.foo {
z-index: 0;
}
@media (min-width:1px) {
.foo {
z-index: 1;
}
}
/*# sourceMappingURL=from.css.map */
`;
const opts = {
from: "from.css",
map: {
inline: false
}
};
var processed = mqpacker.pack(input, opts);
expected = postcss().process(input, opts);
const expected = postcss().process(input, opts);
const processed = mqpacker.pack(input, opts);

test.expect(2);

test.strictEqual(
processed.css,
expected.css
);

test.deepEqual(
processed.map,
expected.map
);

test.done();
};

exports["Option: sort"] = function (test) {
var expected = "@media (min-width: 1px) {\n .foo {\n z-index: 1\n }\n}\n@media (min-width: 2px) {\n .foo {\n z-index: 2\n }\n}";
var input = "@media (min-width: 2px) { .foo { z-index: 2 } }@media (min-width: 1px) { .foo { z-index: 1 } }";
var opts = {
exports["Option: sort"] = (test) => {
const expected = `.foo {
z-index: 0;
}
@media (min-width: 1px) {
.foo {
z-index: 1;
}
}
@media (min-width: 2px) {
.foo {
z-index: 2;
}
}
`;
const input = `.foo {
z-index: 0;
}
@media (min-width: 2px) {
.foo {
z-index: 2;
}
}
@media (min-width: 1px) {
.foo {
z-index: 1;
}
}
`;
const opts = {
sort: true
};

test.expect(4);

test.notStrictEqual(
mqpacker.pack(input).css,
expected
);

test.strictEqual(
mqpacker.pack(input, opts).css,
expected
);

test.notStrictEqual(
postcss([mqpacker()]).process(input).css,
postcss([mqpacker(opts)]).process(input).css
);

test.strictEqual(
mqpacker.pack(input, {
sort: function (c, d) {
Expand All @@ -85,29 +123,25 @@ exports["Option: sort"] = function (test) {
}).css,
expected
);

test.done();
};

exports["Real CSS"] = function (test) {
var testCases = fs.readdirSync(path.join(__dirname, "fixtures"));

var loadExpected = function (file) {
exports["Real CSS"] = (test) => {
const testCases = fs.readdirSync(path.join(__dirname, "fixtures"));
const loadExpected = (file) => {
file = path.join(__dirname, "expected", file);

return fs.readFileSync(file, "utf8");
};

var loadInput = function (file) {
const loadInput = (file) => {
file = path.join(__dirname, "fixtures", file);

return fs.readFileSync(file, "utf8");
};

test.expect(testCases.length);

testCases.forEach(function (testCase) {
var opts = {
testCases.forEach((testCase) => {
const opts = {
sort: false
};

Expand All @@ -121,6 +155,5 @@ exports["Real CSS"] = function (test) {
testCase
);
});

test.done();
};
23 changes: 14 additions & 9 deletions test/expected/keep-query-order.css
@@ -1,13 +1,18 @@
.foo {
z-index: 0;
}

@media (min-width: 99px) {
.foo {
z-index: 1
}
.bar {
z-index: 2
}
.foo {
z-index: 1;
}
.bar {
z-index: 2;
}
}

@media (min-width: 999px) {
.foo {
z-index: 3
}
.foo {
z-index: 3;
}
}
2 changes: 0 additions & 2 deletions test/expected/last-comment.css
Expand Up @@ -9,11 +9,9 @@
/* Comment */

@media (min-width: 999px) {

.foo {
z-index: 3;
}

.bar {
z-index: 4;
}
Expand Down
42 changes: 24 additions & 18 deletions test/expected/multiple-queries.css
@@ -1,24 +1,30 @@
.foo {
z-index: 0;
}

@media (min-width: 99px) {
.foo {
z-index: 1
}
.bar {
z-index: 2
}
.foo {
z-index: 1;
}
.bar {
z-index: 2;
}
}

@media (min-width: 999px) {
.baz {
z-index: 3
}
.qux {
z-index: 4
}
.baz {
z-index: 3;
}
.qux {
z-index: 4;
}
}

@media screen and (min-width: 999px) {
.quux {
z-index: 5
}
.corge {
z-index: 6
}
.quux {
z-index: 5;
}
.corge {
z-index: 6;
}
}
8 changes: 3 additions & 5 deletions test/expected/other-at-rule.css
Expand Up @@ -7,13 +7,11 @@
src: local("F");
}

@media (min-width: 99px){

.foo{
@media (min-width: 99px) {
.foo {
z-index: 1;
}

.bar{
.bar {
z-index: 2;
}
}
3 changes: 0 additions & 3 deletions test/expected/single-query.css
Expand Up @@ -11,15 +11,12 @@
}

@media (min-width: 999px) {

.foo {
z-index: 4;
}

.bar {
z-index: 5;
}

.baz {
z-index: 6;
}
Expand Down
38 changes: 23 additions & 15 deletions test/expected/sort_different-units.css
@@ -1,25 +1,33 @@
.foo {
z-index: 0;
}

@media (min-width: 16px) {
.foo {
z-index: 1
}
.foo {
z-index: 1;
}
}

@media (min-width: 1.0625em) {
.foo {
z-index: 2
}
.foo {
z-index: 2;
}
}

@media (min-width: 1.125rem) {
.foo {
z-index: 3
}
.foo {
z-index: 3;
}
}

@media (min-width: 2.29ex) {
.foo {
z-index: 4
}
.foo {
z-index: 4;
}
}

@media (min-width: 2.248ch) {
.foo {
z-index: 5
}
.foo {
z-index: 5;
}
}

0 comments on commit 5acecc9

Please sign in to comment.