Skip to content

Commit

Permalink
Test for unused css modules with layout (#41018)
Browse files Browse the repository at this point in the history
Similar to #40996.

This PR only adds a failing test that should pass. Also updates wrong url of previous test.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
Hannes Bornö committed Oct 11, 2022
1 parent 5162b64 commit e1e64e0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
@@ -0,0 +1,3 @@
export default function Inner() {
return <p>Inner Page</p>
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/app/app/css/css-page/unused-nested/layout.js
@@ -0,0 +1,10 @@
import { layout } from './styles'

export default function ServerLayout({ children }) {
return (
<>
<p className={layout.mod}>Layout</p>
{children}
</>
)
}
@@ -0,0 +1,3 @@
.this_should_not_be_included_in_inner_path {
color: wheat;
}
@@ -0,0 +1,3 @@
.mod {
color: tomato;
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app/app/css/css-page/unused-nested/page.js
@@ -0,0 +1,5 @@
import { page } from './styles'

export default function Page() {
return <p className={page.this_should_not_be_included_in_inner_path}>Page</p>
}
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app/app/css/css-page/unused-nested/styles.js
@@ -0,0 +1,4 @@
import layout from './only-used-in-layout.module.css'
import page from './only-used-in-first-page.module.css'

export { layout, page }
15 changes: 14 additions & 1 deletion test/e2e/app-dir/index.test.ts
Expand Up @@ -1261,13 +1261,26 @@ describe('app dir', () => {

if (!isDev) {
it('should not include unused css modules in the page in prod', async () => {
const browser = await webdriver(next.url, '/css/css-page')
const browser = await webdriver(next.url, '/css/css-page/unused')
expect(
await browser.eval(
`[...document.styleSheets].some(({ rules }) => [...rules].some(rule => rule.selectorText.includes('this_should_not_be_included')))`
)
).toBe(false)
})

// TODO-APP: Should not include unused css modules in pages
it.skip('should not include unused css modules in nested pages in prod', async () => {
const browser = await webdriver(
next.url,
'/css/css-page/unused-nested/inner'
)
expect(
await browser.eval(
`[...document.styleSheets].some(({ rules }) => [...rules].some(rule => rule.selectorText.includes('this_should_not_be_included_in_inner_path')))`
)
).toBe(false)
})
}
})

Expand Down

0 comments on commit e1e64e0

Please sign in to comment.