Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Proper ordering of collected CSS #114

Merged
merged 1 commit into from
Sep 22, 2017
Merged
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
264 changes: 211 additions & 53 deletions src/server/__tests__/__snapshots__/collect.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,109 +1,215 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`classname in @rule critical 1`] = `"@supports (object-fit: cover) { .linaria {} }@media (min-width: 600px) { .linaria {} }@charset () { .linaria {} }@import () { .linaria {} }@namespace () { .linaria {} }@media () { .linaria {} }@supports () { .linaria {} }@document () { .linaria {} }@page () { .linaria {} }@font-face () { .linaria {} }@keyframes () { .linaria {} }@viewport () { .linaria {} }@counter-style () { .linaria {} }@font-feature-values () { .linaria {} }"`;
exports[`classname in @rule critical 1`] = `
"@supports (object-fit: cover) {
.linaria {
}
}
@media (min-width: 600px) {
.linaria {
}
}
@charset () {
.linaria {
}
}
@import () {
.linaria {
}
}
@namespace () {
.linaria {
}
}
@media () {
.linaria {
}
}
@supports () {
.linaria {
}
}
@document () {
.linaria {
}
}
@page () {
.linaria {
}
}
@font-face () {
.linaria {
}
}
@viewport () {
.linaria {
}
}
@counter-style () {
.linaria {
}
}
@font-feature-values () {
.linaria {
}
}
"
`;

exports[`classname in @rule other 1`] = `
"@supports (object-fit: cover) {
.other {
}
}
@media (min-width: 600px) {
.other {
}
}
@charset () {
.other {
}
}
@import () {
.other {
}
}
@namespace () {
.other {
}
}
@media () {
.other {
}
}
@supports () {
.other {
}
}
@document () {
.other {
}
}
@page () {
.other {
}
}
@font-face () {
.other {
}
}
@viewport () {
.other {
}
}
@counter-style () {
.other {
}
}
@font-feature-values () {
.other {
}
}
"

@supports (object-fit: cover) { .other {} }
@media (min-width: 600px) { .other {} }
@charset () { .other {} }
@import () { .other {} }
@namespace () { .other {} }
@media () { .other {} }
@supports () { .other {} }
@document () { .other {} }
@page () { .other {} }
@font-face () { .other {} }
@viewport () { .other {} }
@counter-style () { .other {} }
@font-feature-values () { .other {} }"
`;

exports[`collects complex css critical 1`] = `
"

".lotus {
vertical-align: top;
}
@media (max-width: 1200px) {
.lotus {
vertical-align: bottom;
}
}

@supports (object-fit: contain) {
.lotus {
object-fit: contain;
}

.linaria::before,
.linaria::after {
content: '';
content: \\"\\";
object-fit: contain;
}
}

@supports (object-fit: contain) {
.lotus {
object-fit: contain;
}

.linaria::before,
.linaria::after {
content: '';
content: \\"\\";
object-fit: contain;
}
}
@supports (object-fit: contain) {
.lotus {
object-fit: contain;
}

.lotus {
vertical-align: top;
.linaria::before,
.linaria::after {
content: \\"\\";
object-fit: contain;
}
}
@supports (object-fit: contain) {
.lotus {
object-fit: contain;
}

.linaria::before,
.linaria::after {
content: \\"\\";
object-fit: contain;
}
}
.linaria {
float: left;
flex: 1;
animation: custom-animation .2s;
animation: custom-animation 0.2s;
}

.linaria:hover {
float: right;
}

.linaria > span,
.linaria + .linaria,
.linaria ~ div {
display: none;
}

.linaria > span {
display: none;
}

.linaria::after {
display: block;
}

.lily {
color: #fff;
}

[data-theme=dark] .lily {
[data-theme=\\"dark\\"] .lily {
color: #000;
}

.linaria ~ div {}

.linaria.linaria2{}

.linaria ~ div {
}
.linaria.linaria2 {
}
@keyframes custom-animation {
0% { opacity: 0 }
50% { opacity: 0 }
100% { opacity: 1 }
}"
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
"
`;

exports[`collects complex css other 1`] = `
"

@supports (object-fit: cover) {
"@supports (object-fit: cover) {
.unrelated-nested {
float: left;
animation: custom-animation;
Expand All @@ -119,21 +225,50 @@ exports[`collects complex css other 1`] = `
}

.unrelated2 {
animation: custom-animation .3s;
animation: custom-animation 0.3s;
}

.unrelated3 {
flex: 0;
}"
}
"
`;

exports[`simple class name critical 1`] = `".linaria {}"`;
exports[`simple class name critical 1`] = `
".linaria {
}
"
`;

exports[`simple class name other 1`] = `".classname {}"`;
exports[`simple class name other 1`] = `
".classname {
}
"
`;

exports[`works with CSS combinators critical 1`] = `".linaria + span {}.linaria ~ div {}.linaria > a {}.linaria b {}"`;
exports[`works with CSS combinators critical 1`] = `
".linaria + span {
}
.linaria ~ div {
}
.linaria > a {
}
.linaria b {
}
"
`;

exports[`works with CSS combinators other 1`] = `".other + span {}.other ~ div {}.other > a {}.other b {}"`;
exports[`works with CSS combinators other 1`] = `
".other + span {
}
.other ~ div {
}
.other > a {
}
.other b {
}
"
`;

exports[`works with global css critical 1`] = `
"body {
Expand All @@ -146,11 +281,34 @@ html {

h1 {
font-weight: bold;
}.linaria:active {}.linaria::before {}"
}
.linaria:active {
}
.linaria::before {
}
"
`;

exports[`works with global css other 1`] = `".other:active {}.other::before {}"`;
exports[`works with global css other 1`] = `
".other:active {
}
.other::before {
}
"
`;

exports[`works with pseudo-class and pseudo-elements critical 1`] = `".linaria:active {}.linaria::before {}"`;
exports[`works with pseudo-class and pseudo-elements critical 1`] = `
".linaria:active {
}
.linaria::before {
}
"
`;

exports[`works with pseudo-class and pseudo-elements other 1`] = `".other:active {}.other::before {}"`;
exports[`works with pseudo-class and pseudo-elements other 1`] = `
".other:active {
}
.other::before {
}
"
`;
12 changes: 8 additions & 4 deletions src/server/__tests__/collect.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* @flow */

import dedent from 'dedent';
import prettier from 'prettier';
import collect from '../collect';

const prettyPrint = (src: string) =>
prettier.format(src, { parser: 'postcss' });

const testCollect = (html, css) => {
const { critical, other } = collect(html, css);
test('critical', () => expect(critical).toMatchSnapshot());
test('other', () => expect(other).toMatchSnapshot());
test('critical', () => expect(prettyPrint(critical)).toMatchSnapshot());
test('other', () => expect(prettyPrint(other)).toMatchSnapshot());
};

const html = dedent`
Expand Down Expand Up @@ -202,6 +206,6 @@ describe('works with global css', () => {
`;

const { critical, other } = collect(html, css, globalCSS);
test('critical', () => expect(critical).toMatchSnapshot());
test('other', () => expect(other).toMatchSnapshot());
test('critical', () => expect(prettyPrint(critical)).toMatchSnapshot());
test('other', () => expect(prettyPrint(other)).toMatchSnapshot());
});
Loading