Skip to content

Commit

Permalink
Add tests for universal webpack (#3680)
Browse files Browse the repository at this point in the history
* Add tests for universal webpack

* Move tests to next-plugins

* Remove obsolete files

* Remove removed page

* Remove tests

* Rename test suite
  • Loading branch information
timneutkens authored and arunoda committed Feb 5, 2018
1 parent 70295f2 commit ed12293
Show file tree
Hide file tree
Showing 13 changed files with 757 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -113,6 +113,7 @@
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
"@zeit/next-css": "0.0.7",
"babel-eslint": "8.0.1",
"babel-jest": "21.2.0",
"babel-plugin-istanbul": "4.1.5",
Expand Down
1 change: 1 addition & 0 deletions test/integration/basic/test/index.test.js
Expand Up @@ -35,6 +35,7 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/link'),
renderViaHTTP(context.appPort, '/stateful'),
renderViaHTTP(context.appPort, '/stateless'),
renderViaHTTP(context.appPort, '/custom-extension'),
renderViaHTTP(context.appPort, '/styled-jsx'),
renderViaHTTP(context.appPort, '/with-cdm'),

Expand Down
6 changes: 6 additions & 0 deletions test/integration/custom-server/next.config.js
@@ -0,0 +1,6 @@
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
}
}
1 change: 1 addition & 0 deletions test/integration/next-plugins/.gitignore
@@ -0,0 +1 @@
!node_modules
@@ -0,0 +1,3 @@
.helloWorld {
color: red;
}
3 changes: 3 additions & 0 deletions test/integration/next-plugins/components/hello-webpack-css.js
@@ -0,0 +1,3 @@
import css from './hello-webpack-css.css'
import framework from 'css-framework/framework.css'
export default () => <div className={`${css.helloWorld} ${framework.frameworkClass}`}>Hello World</div>
9 changes: 9 additions & 0 deletions test/integration/next-plugins/next.config.js
@@ -0,0 +1,9 @@
const withCSS = require('@zeit/next-css')

module.exports = withCSS({
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
cssModules: true
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/integration/next-plugins/pages/webpack-css.js
@@ -0,0 +1,3 @@
import HelloWebpackCSS from '../components/hello-webpack-css'

export default () => <HelloWebpackCSS />
31 changes: 31 additions & 0 deletions test/integration/next-plugins/test/index.test.js
@@ -0,0 +1,31 @@
/* global jasmine, describe, beforeAll, afterAll */

import { join } from 'path'
import {
renderViaHTTP,
fetchViaHTTP,
findPort,
launchApp,
killApp
} from 'next-test-utils'

// test suits
import rendering from './rendering'

const context = {}
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5

describe('Next Plugins', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort, true)

// pre-build all pages at the start
await Promise.all([
renderViaHTTP(context.appPort, '/webpack-css')
])
})
afterAll(() => killApp(context.server))

rendering(context, 'Rendering via HTTP', (p, q) => renderViaHTTP(context.appPort, p, q), (p, q) => fetchViaHTTP(context.appPort, p, q))
})
22 changes: 22 additions & 0 deletions test/integration/next-plugins/test/rendering.js
@@ -0,0 +1,22 @@
/* global describe, test, expect */

import cheerio from 'cheerio'

export default function ({ app }, suiteName, render, fetch) {
async function get$ (path, query) {
const html = await render(path, query)
return cheerio.load(html)
}

describe(suiteName, () => {
test('renders css imports', async () => {
const $ = await get$('/webpack-css')
expect($('._46QtCORzC4BWRnIseSbG-').text() === 'Hello World')
})

test('renders non-js imports from node_modules', async () => {
const $ = await get$('/webpack-css')
expect($('._2pRSkKTPDMGLMnmsEkP__J').text() === 'Hello World')
})
})
}
6 changes: 6 additions & 0 deletions test/integration/production/next.config.js
@@ -0,0 +1,6 @@
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
}
}

0 comments on commit ed12293

Please sign in to comment.