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 Importing Global CSS in CSS Modules #10008

Merged
merged 1 commit into from Jan 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,5 @@
{
"browserslist": [
"last 1 chrome version"
]
}
@@ -0,0 +1,5 @@
import styles from './styles.module.css'

export default function() {
return <div>{JSON.stringify(styles)}</div>
}
@@ -0,0 +1,3 @@
a {
all: initial;
}
@@ -0,0 +1 @@
@import './styles.css';
@@ -0,0 +1,5 @@
{
"browserslist": [
"last 1 chrome version"
]
}
@@ -0,0 +1,5 @@
import styles from './styles.module.css'

export default function() {
return <div>{JSON.stringify(styles)}</div>
}
@@ -0,0 +1,3 @@
a .foo {
all: initial;
}
@@ -0,0 +1 @@
@import './styles.css';
40 changes: 40 additions & 0 deletions test/integration/css-features/test/index.test.js
Expand Up @@ -99,3 +99,43 @@ describe('Custom Properties: Pass-Through Modern', () => {
)
})
})

describe('CSS Modules: Import Global CSS', () => {
const appDir = join(fixturesDir, 'module-import-global')

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(
`"a .styles_foo__31qlD{all:initial}"`
)
})
})

describe('CSS Modules: Importing Invalid Global CSS', () => {
const appDir = join(fixturesDir, 'module-import-global-invalid')

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

it('should fail to build', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
})
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('pages/styles.module.css')
expect(stderr).toContain('CssSyntax error: Selector "a" is not pure')
})
})