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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test CSS Behavior #9733

Merged
merged 2 commits into from Dec 13, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/integration/css-fixtures/composes-basic/pages/index.js
@@ -0,0 +1,9 @@
import { subClass } from './index.module.css'

export default function Home() {
return (
<div id="verify-yellow" className={subClass}>
This text should be yellow on blue.
</div>
)
}
@@ -0,0 +1,9 @@
.className {
background: red;
color: yellow;
}

.subClass {
composes: className;
background: blue;
}
@@ -0,0 +1,9 @@
import { subClass } from './index.module.css'

export default function Home() {
return (
<div id="verify-yellow" className={subClass}>
This text should be yellow on blue.
</div>
)
}
@@ -0,0 +1,4 @@
.subClass {
composes: className from './other.css';
background: blue;
}
@@ -0,0 +1,4 @@
.className {
background: red;
color: yellow;
}
48 changes: 48 additions & 0 deletions test/integration/css-modules/test/index.test.js
Expand Up @@ -223,3 +223,51 @@ describe('Valid CSS Module Usage from within node_modules', () => {
)
})
})

describe('CSS Module Composes Usage (Basic)', () => {
// This is a very bad feature. Do not use it.
const appDir = join(fixturesDir, 'composes-basic')

beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
})

it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')

const files = await readdir(cssFolder)
const cssFiles = files.filter(f => /\.css$/.test(f))

expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')

expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`".index_className__3gr_q{background:red;color:#ff0}.index_subClass__FUvW6{background:#00f}"`
)
})
})

describe('CSS Module Composes Usage (External)', () => {
// This is a very bad feature. Do not use it.
const appDir = join(fixturesDir, 'composes-external')

beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
})

it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')

const files = await readdir(cssFolder)
const cssFiles = files.filter(f => /\.css$/.test(f))

expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')

expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`".other_className__21NIP{background:red;color:#ff0}.index_subClass__FUvW6{background:#00f}"`
)
})
})