Skip to content

Commit

Permalink
Test Importing Global CSS in CSS Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jan 9, 2020
1 parent 3497e7c commit 25ae4c1
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 0 deletions.
@@ -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')
})
})

0 comments on commit 25ae4c1

Please sign in to comment.