-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add insertionPoint option in EmotionCache * yarn changeset * yarn lint * Add tests as per view * Updated changeset, improved tests * Update packages/sheet/src/index.js * Update packages/cache/__tests__/index.js Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Improve tests * Use @testing-library * Address comments from review * Fix some flow issues * fix selectors * small tweaks Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
Showing
10 changed files
with
235 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
'@emotion/cache': minor | ||
'@emotion/sheet': minor | ||
--- | ||
|
||
Add insertionPoint option to the EmotionCache, to insert rules after the specified element. | ||
|
||
```jsx | ||
const head = document.querySelector('head') | ||
|
||
// <meta name="emotion-insertion-point" content=""> | ||
const emotionInsertionPoint = document.createElement('meta') | ||
emotionInsertionPoint.setAttribute('name', 'emotion-insertion-point') | ||
emotionInsertionPoint.setAttribute('content', '') | ||
|
||
head.appendChild(emotionInsertionPoint) | ||
|
||
// the emotion sheets should be inserted right after the meta tag | ||
const cache = createCache({ | ||
key: 'my-app', | ||
insertionPoint: emotionInsertionPoint | ||
}) | ||
|
||
function App() { | ||
return ( | ||
<CacheProvider value={cache}> | ||
<Main /> | ||
</CacheProvider> | ||
) | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,3 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should accept insertionPoint option 1`] = ` | ||
<head> | ||
<style | ||
id="first" | ||
/> | ||
<style | ||
data-emotion="test-insertion-point" | ||
data-s="" | ||
> | ||
.test-insertion-point-83n355{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;color:blue;} | ||
</style> | ||
<style | ||
id="last" | ||
/> | ||
</head> | ||
`; | ||
|
||
exports[`throws correct error with invalid key 1`] = `"Emotion key must only contain lower case alphabetical characters and - but \\".\\" was passed"`; |
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 |
---|---|---|
@@ -1,8 +1,36 @@ | ||
// @flow | ||
/** @jsx jsx */ | ||
import 'test-utils/next-env' | ||
import { safeQuerySelector } from 'test-utils' | ||
import createCache from '@emotion/cache' | ||
import { jsx, CacheProvider } from '@emotion/react' | ||
import { render } from '@testing-library/react' | ||
|
||
test('throws correct error with invalid key', () => { | ||
expect(() => { | ||
createCache({ key: '.' }) | ||
}).toThrowErrorMatchingSnapshot() | ||
}) | ||
|
||
it('should accept insertionPoint option', () => { | ||
const head = safeQuerySelector('head') | ||
|
||
head.innerHTML = ` | ||
<style id="first"></style> | ||
<style id="last"></style> | ||
` | ||
|
||
// the sheet should be inserted between the first and last style nodes | ||
const cache = createCache({ | ||
key: 'test-insertion-point', | ||
insertionPoint: safeQuerySelector('#first') | ||
}) | ||
|
||
render( | ||
<CacheProvider value={cache}> | ||
<div css={{ display: 'flex', color: 'blue' }} /> | ||
</CacheProvider> | ||
) | ||
|
||
expect(document.head).toMatchSnapshot() | ||
}) |
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
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
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