-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Add test for styled-components SWC transform disabled #31214
Merged
timneutkens
merged 2 commits into
vercel:canary
from
timneutkens:add/disable-styled-components-by-default
Nov 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { join } from 'path' | ||
import webdriver from 'next-webdriver' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { fetchViaHTTP } from 'next-test-utils' | ||
|
||
describe('styled-components SWC transform', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
'next.config.js': new FileRef( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||
join(__dirname, 'styled-components-disabled/next.config.js') | ||
), | ||
pages: new FileRef(join(__dirname, 'styled-components-disabled/pages')), | ||
}, | ||
dependencies: { | ||
'styled-components': '5.3.3', | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
async function matchLogs$(browser) { | ||
let foundLog = false | ||
|
||
const browserLogs = await browser.log('browser') | ||
|
||
browserLogs.forEach((log) => { | ||
if (log.message.includes('Warning: Prop `%s` did not match.')) { | ||
foundLog = true | ||
} | ||
}) | ||
return foundLog | ||
} | ||
it('should have hydration mismatch with styled-components transform disabled', async () => { | ||
let browser | ||
try { | ||
browser = await webdriver(next.appPort, '/') | ||
|
||
// Compile /_error | ||
await fetchViaHTTP(next.appPort, '/404') | ||
|
||
try { | ||
// Try 4 times to be sure there is no mismatch | ||
expect(await matchLogs$(browser)).toBe(false) | ||
await browser.refresh() | ||
expect(await matchLogs$(browser)).toBe(false) | ||
await browser.refresh() | ||
expect(await matchLogs$(browser)).toBe(false) | ||
await browser.refresh() | ||
expect(await matchLogs$(browser)).toBe(false) | ||
throw new Error('did not find mismatch') | ||
} catch (err) { | ||
// Verify that it really has the logs | ||
expect(await matchLogs$(browser)).toBe(true) | ||
} | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
test/development/basic/styled-components-disabled/next.config.js
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 @@ | ||
module.exports = {} |
26 changes: 26 additions & 0 deletions
26
test/development/basic/styled-components-disabled/pages/_app.js
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,26 @@ | ||
import { createGlobalStyle, ThemeProvider } from 'styled-components' | ||
|
||
const GlobalStyle = createGlobalStyle` | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
` | ||
|
||
const theme = { | ||
colors: { | ||
primary: '#0070f3', | ||
}, | ||
} | ||
|
||
export default function App({ Component, pageProps }) { | ||
return ( | ||
<> | ||
<GlobalStyle /> | ||
<ThemeProvider theme={theme}> | ||
<Component {...pageProps} /> | ||
</ThemeProvider> | ||
</> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
test/development/basic/styled-components-disabled/pages/_document.js
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,30 @@ | ||
import Document from 'next/document' | ||
import { ServerStyleSheet } from 'styled-components' | ||
|
||
export default class MyDocument extends Document { | ||
static async getInitialProps(ctx) { | ||
const sheet = new ServerStyleSheet() | ||
const originalRenderPage = ctx.renderPage | ||
|
||
try { | ||
ctx.renderPage = () => | ||
originalRenderPage({ | ||
enhanceApp: (App) => (props) => | ||
sheet.collectStyles(<App {...props} />), | ||
}) | ||
|
||
const initialProps = await Document.getInitialProps(ctx) | ||
return { | ||
...initialProps, | ||
styles: ( | ||
<> | ||
{initialProps.styles} | ||
{sheet.getStyleElement()} | ||
</> | ||
), | ||
} | ||
} finally { | ||
sheet.seal() | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test/development/basic/styled-components-disabled/pages/index.js
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,38 @@ | ||
import styled, { css } from 'styled-components' | ||
const Button = styled.a` | ||
/* This renders the buttons above... Edit me! */ | ||
display: inline-block; | ||
border-radius: 3px; | ||
padding: 0.5rem 0; | ||
margin: 0.5rem 1rem; | ||
width: 11rem; | ||
background: transparent; | ||
color: white; | ||
border: 2px solid white; | ||
|
||
/* The GitHub button is a primary button | ||
* edit this to target it specifically! */ | ||
${(props) => | ||
props.primary && | ||
css` | ||
background: white; | ||
color: black; | ||
`} | ||
` | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<Button | ||
href="https://github.com/styled-components/styled-components" | ||
target="_blank" | ||
rel="noopener" | ||
primary | ||
> | ||
GitHub | ||
</Button> | ||
|
||
<Button href="/docs">Documentation</Button> | ||
</div> | ||
) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True is the default, same for ssr