hello world
`; exports[`css prop react kitchen sink 1`] = ` -.css-bold-15qcrjv-18w8kdp { +.glamor-4 { display: -webkit-box; - display: -moz-box; display: -ms-flexbox; - display: -webkit-flex; display: flex; font-weight: bold; -} - -.css-small-1wh34bm-yjtkkb { - font-size: 6; -} - -.css-flexCenter-mdk64u-llada3 { - display: -webkit-box; - display: -moz-box; - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -webkit-justify-content: center; - -ms-flex-pack: center; -webkit-box-pack: center; + -ms-flex-pack: center; justify-content: center; - -webkit-align-items: center; - -ms-flex-align: center; -webkit-box-align: center; + -ms-flex-align: center; align-items: center; } -.css-tree-17jiuxc-pi0syi { +.glamor-0 { + font-size: 6px; color: red; } -.css-tree-14jcta0-1fj87hp { +.glamor-1 { color: blue; } -.css-tree-1gdxe9e-1vltlgj { - display: -webkit-box; - display: -moz-box; +.glamor-2 { + display: -webkit-inline-box; display: -ms-inline-flexbox; - display: -webkit-inline-flex; display: inline-flex; } -.css-tree-1g8ltio-i3faqz { +.glamor-3 { color: red; - border-radius: 5; + border-radius: 5px; } -.css-tree-1g8ltio-i3faqz:hover { +.glamor-3:hover { font-weight: bold; color: gray; }Hello
World
hello world
@@ -96,14 +79,14 @@ exports[`css prop react kitchen sink 1`] = ` `; exports[`css prop react string expression 1`] = ` -.css-tree-7sqgip-8upfq4 { +.glamor-0 { color: red; background: blue; font-size: 48px; }hello world
diff --git a/test/__snapshots__/css.test.js.snap b/test/__snapshots__/css.test.js.snap index 8025db85b..dfaec41dc 100644 --- a/test/__snapshots__/css.test.js.snap +++ b/test/__snapshots__/css.test.js.snap @@ -1,83 +1,133 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`css composes 1`] = `"css-cls1-vyoujf-va5xsk css-cls1-vyoujf"`; - -exports[`css composes 2`] = `"css-cls2-1qb2ovg-1em6aur css-cls2-1qb2ovg css-cls1-vyoujf-va5xsk css-cls1-vyoujf"`; - -exports[`css composes 3`] = ` -".css-cls1-1gi569l-b877w5 { background: white; - color: black; - text-decoration: underline; - display: block; - border-radius: 3px; - padding: 25px; - width: 500px; - z-index: 100; - font-size: 18px; - text-align: center; - border: solid 1px red; }.css-15famh2{}.css-cls2-1qb2ovg-1em6aur { - -webkit-justify-content: center; - -ms-flex-pack: center; - -webkit-box-pack: center; - justify-content: center; }.css-cls1-vyoujf-va5xsk { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; }" +exports[`css composes 1`] = ` +.glamor-0 { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; +} + + +`; + +exports[`css composes with objects 1`] = ` +.glamor-0 { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + display: block; + width: 30px; + height: calc(40vw - 50px); + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; +} + +.glamor-0:hover { + color: blue; +} + +.glamor-0:after { + content: " "; + color: red; +} + +@media (min-width: 420px) { + .glamor-0 { + color: green; + } +} + + `; -exports[`css composes with objects 1`] = `"css-1puxias"`; - -exports[`css composes with objects 2`] = `"css-cls2-1qb2ovg-1em6aur css-cls2-1qb2ovg css-1puxias"`; - -exports[`css composes with objects 3`] = ` -".css-cls1-1gi569l-b877w5 { background: white; - color: black; - text-decoration: underline; - display: block; - border-radius: 3px; - padding: 25px; - width: 500px; - z-index: 100; - font-size: 18px; - text-align: center; - border: solid 1px red; }.css-15famh2{}.css-cls2-1qb2ovg-1em6aur { - -webkit-justify-content: center; - -ms-flex-pack: center; - -webkit-box-pack: center; - justify-content: center; }.css-cls1-vyoujf-va5xsk { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; }.css-xmm9em{display:-webkit-box;display:-ms-flexbox;display:flex}.css-1puxias{display:-webkit-box;display:-ms-flexbox;display:flex;display:block;width:30px;height:calc(40vw - 50px)}.css-1puxias:hover{color:blue}.css-1puxias:after{content:\\" \\";color:red}@media(min-width: 420px){.css-1puxias{color:green}}" +exports[`css composes with undefined values 1`] = ` +.glamor-0 { + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; +} + + `; -exports[`css composes with undefined values 1`] = `"css-cls2-1qb2ovg-1em6aur css-cls2-1qb2ovg css-15famh2"`; - -exports[`css composes with undefined values 2`] = ` -".css-cls1-1gi569l-b877w5 { background: white; - color: black; - text-decoration: underline; - display: block; - border-radius: 3px; - padding: 25px; - width: 500px; - z-index: 100; - font-size: 18px; - text-align: center; - border: solid 1px red; }.css-15famh2{}.css-cls2-1qb2ovg-1em6aur { - -webkit-justify-content: center; - -ms-flex-pack: center; - -webkit-box-pack: center; - justify-content: center; }" +exports[`css computed key is only dynamic 1`] = ` +.glamor-0 { + font-size: 10px; + width: 20px; +} + + `; -exports[`css handles more than 10 dynamic properties 1`] = `"css-cls1-1gi569l-b877w5 css-cls1-1gi569l"`; - -exports[`css handles more than 10 dynamic properties 2`] = ` -".css-cls1-1gi569l-b877w5 { background: white; - color: black; - text-decoration: underline; - display: block; - border-radius: 3px; - padding: 25px; - width: 500px; - z-index: 100; - font-size: 18px; - text-align: center; - border: solid 1px red; }" +exports[`css flushes correctly 1`] = ` +.glamor-0 { + display: -webkit-box; + display: -ms-flexbox; + display: flex; +} + + `; -exports[`css handles objects 1`] = `"css-xmm9em"`; +exports[`css flushes correctly 2`] = ` + +`; + +exports[`css handles more than 10 dynamic properties 1`] = ` +.glamor-0 { + -webkit-text-decoration: underline; + text-decoration: underline; + border-right: solid blue 54px; + background: white; + color: black; + display: block; + border-radius: 3px; + padding: 25px; + width: 500px; + z-index: 100; + font-size: 18px; + text-align: center; +} + + +`; + +exports[`css handles objects 1`] = ` +.glamor-0 { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + color: blue; + font-size: 20px; + height: 50px; + width: 20px; +} + + +`; + +exports[`css null rule 1`] = ` + +`; diff --git a/test/__snapshots__/font-face.test.js.snap b/test/__snapshots__/font-face.test.js.snap index 5dc1c8505..2964673ce 100644 --- a/test/__snapshots__/font-face.test.js.snap +++ b/test/__snapshots__/font-face.test.js.snap @@ -1,21 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`font-face adds font-face to sheet 1`] = ` -"@font-face {font-family: 'Patrick Hand SC'; - font-style: normal; - font-weight: 400; - src: local('Patrick Hand SC'), local('PatrickHandSC-Regular'), url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2) format('woff2'); - unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;}" -` +exports[`font-face adds font-face to sheet 1`] = `"@font-face{font-family:'Patrick Hand SC';font-style:normal;font-weight:400;src:local('Patrick Hand SC'), local('PatrickHandSC-Regular'), url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2) format('woff2');unicode-range:U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;}"`; exports[`font-face adds font-face to sheet with interpolation 1`] = ` -"@font-face {font-family: 'Patrick Hand SC'; - font-style: normal; - font-weight: 400; - src: local('Patrick Hand SC'), local('PatrickHandSC-Regular'), url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2) format('woff2'); - unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;}@font-face {font-family: MyHelvetica; - src: local(\\"Helvetica Neue Bold\\"), +"@font-face{font-family:'Patrick Hand SC';font-style:normal;font-weight:400;src:local('Patrick Hand SC'), local('PatrickHandSC-Regular'), url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2) format('woff2');unicode-range:U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;}@font-face{font-family:MyHelvetica;src:local(\\"Helvetica Neue Bold\\"), local(\\"HelveticaNeue-Bold\\"), - url(MgOpenModernaBold.ttf); - font-weight: bold;}" -` + url(MgOpenModernaBold.ttf);font-weight:bold;}" +`; diff --git a/test/__snapshots__/inject-global.test.js.snap b/test/__snapshots__/inject-global.test.js.snap index 3d8a6aaa3..afc879b40 100644 --- a/test/__snapshots__/inject-global.test.js.snap +++ b/test/__snapshots__/inject-global.test.js.snap @@ -1,13 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`injectGlobal 1`] = ` -"html { - background: pink; - }html.active { - background: red; - }body { - color: yellow; - margin: 0; - padding: 0; - }" -`; +exports[`injectGlobal 1`] = `"html {background:pink;}html.active {background:red;}body {color:yellow;margin:0px;padding:0px;}"`; diff --git a/test/__snapshots__/keyframes.test.js.snap b/test/__snapshots__/keyframes.test.js.snap index 832a5245b..db944dbab 100644 --- a/test/__snapshots__/keyframes.test.js.snap +++ b/test/__snapshots__/keyframes.test.js.snap @@ -1,58 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`keyframes keyframes with interpolation 1`] = ` -"@keyframes animation-bounce-10a3qiv-cmo0tx { from, 20%, 53%, 80%, to { - -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000); - animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000); - -webkit-transform: translate3d(0,0,0); - -ms-transform: translate3d(0,0,0); - transform: translate3d(0,0,0); - } - - 40%, 43% { - -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); - animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); - -webkit-transform: translate3d(0, -30px, 0); - -ms-transform: translate3d(0, -30px, 0); - transform: translate3d(0, -30px, 0); - } - - 70% { - -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); - animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); - -webkit-transform: translate3d(0, -15px, 0); - -ms-transform: translate3d(0, -15px, 0); - transform: translate3d(0, -15px, 0); - } - - 90% { - -webkit-transform: translate3d(0,-4px,0); - -ms-transform: translate3d(0,-4px,0); - transform: translate3d(0,-4px,0); - } }.css-H1-o0kcx2-fy8ana { font-size: 20px; - -webkit-animation: animation-bounce-10a3qiv-cmo0tx 2s linear infinite; - animation: animation-bounce-10a3qiv-cmo0tx 2s linear infinite; }@keyframes animation-1fpnjxj-1mmv2re { from { - -webkit-transform: rotate(0deg); - -ms-transform: rotate(0deg); - transform: rotate(0deg); - } - - to { - -webkit-transform: rotate(360deg); - -ms-transform: rotate(360deg); - transform: rotate(360deg); - } }" +.glamor-0 { + -webkit-animation: animation_1cnjdtk 2s linear infinite; + animation: animation_1cnjdtk 2s linear infinite; +} + +hello world
) .toJSON() - expect(tree).toMatchSnapshotWithEmotion() + expect(tree).toMatchSnapshotWithGlamor() }) test('string expression', () => { const tree = renderer .create( -hello world
+hello world
) .toJSON() - expect(tree).toMatchSnapshotWithEmotion() + expect(tree).toMatchSnapshotWithGlamor() }) test('kitchen sink', () => { @@ -51,7 +51,7 @@ describe('css prop react', () => { const tree = renderer .create(+
Hello
World @@ -89,6 +89,6 @@ describe('css prop react', () => { ) .toJSON() - expect(tree).toMatchSnapshotWithEmotion() + expect(tree).toMatchSnapshotWithGlamor() }) }) diff --git a/test/css.test.js b/test/css.test.js index 13aeacf9e..fbbd69da4 100644 --- a/test/css.test.js +++ b/test/css.test.js @@ -1,12 +1,19 @@ /* eslint-env jest */ -import { sheet, css } from '../src/index' +import React from 'react' +import renderer from 'react-test-renderer' +import { matcher, serializer } from 'jest-glamor-react' +import { sheet, css, flush } from '../src/index' + +expect.addSnapshotSerializer(serializer(sheet)) +expect.extend(matcher) describe('css', () => { test('handles more than 10 dynamic properties', () => { const cls1 = css` + text-decoration: ${'underline'}; + border-right: solid blue 54px; background: ${'white'}; color: ${'black'}; - text-decoration: ${'underline'}; display: ${'block'}; border-radius: ${'3px'}; padding: ${'25px'}; @@ -14,13 +21,10 @@ describe('css', () => { z-index: ${100}; font-size: ${'18px'}; text-align: ${'center'}; - border: ${'solid 1px red'}; ` - expect(cls1).toMatchSnapshot() - expect( - sheet.tags.map(tag => tag.textContent || '').join('') - ).toMatchSnapshot() + const tree = renderer.create(
).toJSON() + expect(tree).toMatchSnapshotWithGlamor() }) test('composes with undefined values', () => { @@ -28,10 +32,8 @@ describe('css', () => { composes: ${undefined}; justifyContent: center; ` - expect(cls2).toMatchSnapshot() - expect( - sheet.tags.map(tag => tag.textContent || '').join('') - ).toMatchSnapshot() + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() }) test('composes', () => { @@ -42,16 +44,29 @@ describe('css', () => { composes: ${cls1}; justifyContent: center; ` - expect(cls1).toMatchSnapshot() - expect(cls2).toMatchSnapshot() - expect( - sheet.tags.map(tag => tag.textContent || '').join('') - ).toMatchSnapshot() + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() }) test('handles objects', () => { - const cls1 = css({ display: 'flex' }) - expect(cls1).toMatchSnapshot() + const cls1 = css({ + display: 'flex', + color: `${'blue'}`, + fontSize: `${'20px'}`, + height: `${50}`, + width: 20 + }) + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() + }) + + test('computed key is only dynamic', () => { + const cls1 = css({ + fontSize: 10, + [`w${'idth'}`]: 20 + }) + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() }) test('composes with objects', () => { @@ -59,7 +74,7 @@ describe('css', () => { display: ['flex', 'block'], width: 30, height: 'calc(40vw - 50px)', - ':hover': {color: 'blue'}, + ':hover': { color: 'blue' }, ':after': { content: '" "', color: 'red' @@ -73,10 +88,23 @@ describe('css', () => { justifyContent: center; ` - expect(cls1).toMatchSnapshot() - expect(cls2).toMatchSnapshot() - expect( - sheet.tags.map(tag => tag.textContent || '').join('') - ).toMatchSnapshot() + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() + }) + test('null rule', () => { + const cls1 = css() + + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() + }) + test('flushes correctly', () => { + const cls1 = css` + display: flex; + ` + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshotWithGlamor() + flush() + const tree2 = renderer.create().toJSON() + expect(tree2).toMatchSnapshotWithGlamor() }) }) diff --git a/test/extract/.babelrc b/test/extract/.babelrc index 2efecbb12..c31fa42db 100644 --- a/test/extract/.babelrc +++ b/test/extract/.babelrc @@ -4,5 +4,5 @@ "env", "react" ], - "plugins": ["../babel-plugin-emotion-test"] + "plugins": [["../babel-plugin-emotion-test", {extractStatic: true}]] } diff --git a/test/extract/__snapshots__/extract.test.js.snap b/test/extract/__snapshots__/extract.test.js.snap index df273dc7f..1d5baa017 100644 --- a/test/extract/__snapshots__/extract.test.js.snap +++ b/test/extract/__snapshots__/extract.test.js.snap @@ -1,157 +1,55 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`styled another attr 1`] = ` -.css-PlaygroundWrapper-1shjoz3-tra3vx { - color: #343a40; -} - - -`; - -exports[`styled attr 1`] = ` -.css-H1-nt9mdf-vddukf { - font-size: 48; - margin: 4rem; -} - - -`; - -exports[`styled basic render 1`] = ` -.vars-ch9j2 { - --css-H1-1t8i2zo-0: 20px; -} - +exports[`styled basic render nested 1`] = `