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

Test basic css module prefetching without compose #16134

Merged
merged 1 commit into from
Aug 18, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from './button.module.css'

export const Button = ({ className, ...rest }) => (
<a className={`${styles.button} ${className}`} {...rest} />
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.button {
background: hotpink;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Button } from '../components/button'
import Link from 'next/link'

function AnotherPage() {
return (
<div>
<h1>Another page</h1>
<Link href="/">
<Button id="link-index">Another Button instance</Button>
</Link>
</div>
)
}

export default AnotherPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.button {
background: lime;
}
18 changes: 18 additions & 0 deletions test/integration/css-fixtures/next-issue-12343/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Link from 'next/link'
import { Button } from '../components/button'
import styles from './homepage.module.css'

function HomePage() {
return (
<div>
<h1>Home page</h1>
<Link href="/another-page">
<Button id="link-other" className={styles.button}>
Another page
</Button>
</Link>
</div>
)
}

export default HomePage
93 changes: 93 additions & 0 deletions test/integration/css/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,4 +1396,97 @@ describe('CSS Support', () => {
tests()
})
})

// https://github.com/vercel/next.js/issues/12343
describe('Basic CSS Modules Ordering', () => {
const appDir = join(fixturesDir, 'next-issue-12343')
let app, appPort

function tests() {
async function checkGreenButton(browser) {
await browser.waitForElementByCss('#link-other')
const titleColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#link-other')).backgroundColor`
)
expect(titleColor).toBe('rgb(0, 255, 0)')
}
async function checkPinkButton(browser) {
await browser.waitForElementByCss('#link-index')
const titleColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#link-index')).backgroundColor`
)
expect(titleColor).toBe('rgb(255, 105, 180)')
}

it('should have correct color on index page (on load)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkGreenButton(browser)
} finally {
await browser.close()
}
})

it('should have correct color on index page (on hover)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkGreenButton(browser)
await browser.waitForElementByCss('#link-other').moveTo()
await waitFor(2000)
await checkGreenButton(browser)
} finally {
await browser.close()
}
})

it('should have correct color on index page (on nav)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkGreenButton(browser)
await browser.waitForElementByCss('#link-other').click()

// Wait for navigation:
await browser.waitForElementByCss('#link-index')
await checkPinkButton(browser)

// Navigate back to index:
await browser.waitForElementByCss('#link-index').click()
await checkGreenButton(browser)
} finally {
await browser.close()
}
})
}

describe('Development Mode', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})

tests()
})

describe('Production Mode', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
await nextBuild(appDir, [], {})
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})

tests()
})
})
})