Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug for serverless. Adding tests
- Loading branch information
1 parent
deb0f3d
commit 03ca0c2
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import '../styles/styles.css' | ||
|
||
// This default export is required in a new `pages/_app.js` file. | ||
export default function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styles from '../styles/index.module.css' | ||
|
||
export default function Home() { | ||
return ( | ||
<div className={styles.hello}> | ||
<p>Hello World</p> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.hello { | ||
font: 15px Helvetica, Arial, sans-serif; | ||
background: #eee; | ||
padding: 100px; | ||
text-align: center; | ||
transition: 100ms ease-in background; | ||
} | ||
|
||
.hello:hover { | ||
background: #ccc; | ||
} | ||
|
||
.extra-style1 { | ||
background: #000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
body { | ||
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', | ||
'Arial', sans-serif; | ||
padding: 20px 20px 60px; | ||
max-width: 680px; | ||
margin: 0 auto; | ||
} | ||
|
||
.extra-style { | ||
font-size: 200%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
killApp, | ||
findPort, | ||
nextStart, | ||
nextBuild, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
import fs from 'fs-extra' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '../') | ||
const nextConfig = join(appDir, 'next.config.js') | ||
let appPort | ||
let app | ||
|
||
function runTests() { | ||
it('should inline critical CSS', async () => { | ||
const html = await renderViaHTTP(appPort, '/index') | ||
expect(html).toMatch( | ||
/<link rel="stylesheet" href="\/_next\/static\/css\/.*\.css" .*>/ | ||
) | ||
expect(html).toMatch(/body{font-family:SF Pro Text/) | ||
}) | ||
|
||
it('should not inline non-critical css', async () => { | ||
const html = await renderViaHTTP(appPort, '/index') | ||
expect(html).not.toMatch(/.extra-style/) | ||
}) | ||
} | ||
|
||
describe('CSS optimization for SSR apps', () => { | ||
beforeAll(async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
`module.exports = { experimental: {optimizeCss: true} }`, | ||
'utf8' | ||
) | ||
|
||
if (fs.pathExistsSync(join(appDir, '.next'))) { | ||
await fs.remove(join(appDir, '.next')) | ||
} | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests() | ||
}) | ||
|
||
describe('CSS optimization for serverless apps', () => { | ||
beforeAll(async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
`module.exports = { target: 'serverless', experimental: {optimizeCss: true} }`, | ||
'utf8' | ||
) | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests() | ||
}) |