This repository has been archived by the owner on Oct 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from filamentgroup/original-definitions
Original definitions
- Loading branch information
Showing
9 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@media (min-width:50em){ | ||
.bio{font-size:1em;} | ||
.bio img{float:left;} | ||
} | ||
|
||
.baz {} | ||
|
||
.foo {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@media (min-width:50em){ | ||
.bio{ | ||
font-size:1em; | ||
color: red; | ||
} | ||
.bio img { | ||
float:left; | ||
-moz-box-sizing:content-box; | ||
} | ||
} | ||
|
||
.baz{font-size:1em;} | ||
|
||
.foo{font-size:1em;color:blue;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.foo{font-size:1em;} | ||
.foo{color:blue;} | ||
.bar{font-size:1em;} | ||
|
||
@media (min-width:50em){ | ||
.bio{font-size:1em;} | ||
.bio img { | ||
float:left; | ||
-moz-box-sizing:content-box; | ||
} | ||
} | ||
|
||
@media (min-width:1000em){ | ||
.bio{font-size:3em;} | ||
} | ||
|
||
.baz{font-size:1em;} | ||
|
||
@media (min-width:50em){ | ||
.bio{color: red;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@media (min-width:50em){ | ||
.bio{} | ||
} | ||
|
||
@supports (box-shadow:50em){ | ||
.bio{} | ||
} | ||
|
||
@document url(http://example.com) { | ||
.bio{background-color: blue;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@media (min-width:50em){ | ||
.bio{color: red;} | ||
} | ||
|
||
@supports (box-shadow:50em){ | ||
.bio{width: 100%;} | ||
} | ||
|
||
@document url(http://example.com) { | ||
.bio{background-color: blue;border-size: 1px;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@media (min-width:50em){ | ||
.bio{color: red;} | ||
} | ||
|
||
@supports (box-shadow:50em){ | ||
.bio{width: 100%;} | ||
} | ||
|
||
@document url(http://example.com) { | ||
.bio{border-size: 1px;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*global require:true*/ | ||
(function( exports ){ | ||
"use strict"; | ||
|
||
var path = require("path"); | ||
var critical = require(path.join( "..", "..", "critical.js") ); | ||
var fs = require("fs"); | ||
|
||
function readTestCSSFile(name){ | ||
return fs | ||
.readFileSync(path.join(__dirname, "..", "files", name + ".css")) | ||
.toString(); | ||
} | ||
|
||
function testDefs(test, opts) { | ||
test.expect(1); | ||
|
||
var result = critical | ||
.restoreOriginalDefs(opts.original, opts.critical, { compress: true }) | ||
.replace(/\s/g, ""); | ||
|
||
test.equal(result, opts.expected.replace(/\s/g, "")); | ||
test.done(); | ||
} | ||
|
||
exports.restoreOriginalDefs = { | ||
"adds stripped definitions": function(test) { | ||
testDefs(test, { | ||
original: "body { color: red; }", | ||
critical: "body {}", | ||
expected: "body { color:red; }" | ||
}); | ||
}, | ||
|
||
"adds muliple stripped definitions": function(test) { | ||
testDefs(test, { | ||
original: "body { color: red; font-size: 20px; }", | ||
critical: "body {}", | ||
expected: "body { color:red; font-size:20px; }" | ||
}); | ||
}, | ||
|
||
"does not include removed selectors": function(test) { | ||
testDefs(test, { | ||
original: "body { color: red; } div.removed {}", | ||
critical: "body {}", | ||
expected: "body { color:red; }" | ||
}); | ||
}, | ||
|
||
"includes media queries": function(test) { | ||
testDefs(test, { | ||
original: "@media (max-width: 600px) { body { color: red; } } @media (max-width: 400px) { body { color: red; } }", | ||
critical: "@media (max-width: 600px) { body {} }", | ||
expected: "@media (max-width: 600px) { body { color:red; } }" | ||
}); | ||
}, | ||
|
||
"includes complex media queries": function(test) { | ||
testDefs(test, { | ||
original: readTestCSSFile("media"), | ||
critical: readTestCSSFile("media-critical"), | ||
expected: readTestCSSFile("media-expected") | ||
}); | ||
}, | ||
|
||
"includes nested rules": function(test) { | ||
testDefs(test, { | ||
original: readTestCSSFile("nested"), | ||
critical: readTestCSSFile("nested-critical"), | ||
expected: readTestCSSFile("nested-expected") | ||
}); | ||
} | ||
}; | ||
}(typeof exports === "object" && exports || this)); |