Skip to content

Commit 55e966b

Browse files
authored
Test CSS Behavior (#9733)
* Test CSS Behavior * adjust files
1 parent 88de232 commit 55e966b

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { subClass } from './index.module.css'
2+
3+
export default function Home() {
4+
return (
5+
<div id="verify-yellow" className={subClass}>
6+
This text should be yellow on blue.
7+
</div>
8+
)
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.className {
2+
background: red;
3+
color: yellow;
4+
}
5+
6+
.subClass {
7+
composes: className;
8+
background: blue;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { subClass } from './index.module.css'
2+
3+
export default function Home() {
4+
return (
5+
<div id="verify-yellow" className={subClass}>
6+
This text should be yellow on blue.
7+
</div>
8+
)
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.subClass {
2+
composes: className from './other.css';
3+
background: blue;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.className {
2+
background: red;
3+
color: yellow;
4+
}

test/integration/css-modules/test/index.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,51 @@ describe('Valid CSS Module Usage from within node_modules', () => {
223223
)
224224
})
225225
})
226+
227+
describe('CSS Module Composes Usage (Basic)', () => {
228+
// This is a very bad feature. Do not use it.
229+
const appDir = join(fixturesDir, 'composes-basic')
230+
231+
beforeAll(async () => {
232+
await remove(join(appDir, '.next'))
233+
await nextBuild(appDir)
234+
})
235+
236+
it(`should've emitted a single CSS file`, async () => {
237+
const cssFolder = join(appDir, '.next/static/css')
238+
239+
const files = await readdir(cssFolder)
240+
const cssFiles = files.filter(f => /\.css$/.test(f))
241+
242+
expect(cssFiles.length).toBe(1)
243+
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
244+
245+
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
246+
`".index_className__3gr_q{background:red;color:#ff0}.index_subClass__FUvW6{background:#00f}"`
247+
)
248+
})
249+
})
250+
251+
describe('CSS Module Composes Usage (External)', () => {
252+
// This is a very bad feature. Do not use it.
253+
const appDir = join(fixturesDir, 'composes-external')
254+
255+
beforeAll(async () => {
256+
await remove(join(appDir, '.next'))
257+
await nextBuild(appDir)
258+
})
259+
260+
it(`should've emitted a single CSS file`, async () => {
261+
const cssFolder = join(appDir, '.next/static/css')
262+
263+
const files = await readdir(cssFolder)
264+
const cssFiles = files.filter(f => /\.css$/.test(f))
265+
266+
expect(cssFiles.length).toBe(1)
267+
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
268+
269+
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
270+
`".other_className__21NIP{background:red;color:#ff0}.index_subClass__FUvW6{background:#00f}"`
271+
)
272+
})
273+
})

0 commit comments

Comments
 (0)