Skip to content

Commit

Permalink
Test basic css module prefetching without compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Aug 12, 2020
1 parent 9e65c6a commit 01be846
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
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 @@ -1051,4 +1051,97 @@ describe('CSS Support', () => {
expect(cssMapFiles.length).toBe(1)
})
})

// 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()
})
})
})

0 comments on commit 01be846

Please sign in to comment.