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

Add CSS Resolve Test #9724

Merged
merged 1 commit into from
Dec 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"node-notifier": "5.4.0",
"node-sass": "4.12.0",
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"pixrem": "5.0.0",
"postcss-pseudoelements": "5.0.0",
"postcss-short-size": "4.0.0",
Expand Down
12 changes: 12 additions & 0 deletions test/integration/css-fixtures/npm-import-bad/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import App from 'next/app'
import '../styles/global.css'

class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}

export default MyApp
3 changes: 3 additions & 0 deletions test/integration/css-fixtures/npm-import-bad/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'nprogress/nprogress.css';
12 changes: 12 additions & 0 deletions test/integration/css-fixtures/npm-import/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import App from 'next/app'
import '../styles/global.css'

class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}

export default MyApp
3 changes: 3 additions & 0 deletions test/integration/css-fixtures/npm-import/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
1 change: 1 addition & 0 deletions test/integration/css-fixtures/npm-import/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '~nprogress/nprogress.css';
38 changes: 38 additions & 0 deletions test/integration/css/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,44 @@ describe('CSS Support', () => {
})
})

describe('Good CSS Import from node_modules', () => {
const appDir = join(fixturesDir, 'npm-import')

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

it('should build successfully', async () => {
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()).toMatch(/nprogress/)
})
})

describe('Bad CSS Import from node_modules', () => {
const appDir = join(fixturesDir, 'npm-import-bad')

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

it('should fail the build', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })

expect(stderr).toMatch(/Can't resolve '[^']*?nprogress[^']*?'/)
expect(stderr).toMatch(/Build error occurred/)
})
})

describe('Ordering with styled-jsx (dev)', () => {
const appDir = join(fixturesDir, 'with-styled-jsx')

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10989,6 +10989,11 @@ npm-run-path@^3.0.0:
gauge "~2.7.3"
set-blocking "~2.0.0"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
integrity sha1-y480xTIT2JVyP8urkH6UIq28r7E=

nth-check@^1.0.2, nth-check@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c"
Expand Down