Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validation for pageExtensions and tests
- Loading branch information
Showing
8 changed files
with
84 additions
and
99 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export default () => 'Hello World' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,70 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' | ||
import fs from 'fs-extra' | ||
import { runNextCommand } from 'next-test-utils' | ||
|
||
// test suits | ||
import hmr from './hmr' | ||
|
||
const context = {} | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 | ||
|
||
const appDir = join(__dirname, '..') | ||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
describe('Page Extensions', () => { | ||
beforeAll(async () => { | ||
context.appPort = await findPort() | ||
context.server = await launchApp(join(__dirname, '../'), context.appPort) | ||
it('should throw if pageExtensions is not an array', async () => { | ||
await fs.writeFile(nextConfig, `module.exports = { pageExtensions: null }`) | ||
|
||
const { stderr } = await runNextCommand(['build', appDir], { stderr: true }) | ||
|
||
await fs.remove(nextConfig) | ||
|
||
expect(stderr).toContain( | ||
'Specified pageExtensions is not an array of strings, found "null". Please update this config or remove it' | ||
) | ||
}) | ||
|
||
it('should throw if pageExtensions is an empty array', async () => { | ||
await fs.writeFile(nextConfig, `module.exports = { pageExtensions: [] }`) | ||
|
||
const { stderr } = await runNextCommand(['build', appDir], { stderr: true }) | ||
|
||
// pre-build all pages at the start | ||
await Promise.all([renderViaHTTP(context.appPort, '/hmr/some-page')]) | ||
await fs.remove(nextConfig) | ||
|
||
expect(stderr).toContain( | ||
'Specified pageExtensions is an empty array. Please update it with the relevant extensions or remove it' | ||
) | ||
}) | ||
afterAll(() => killApp(context.server)) | ||
|
||
hmr(context, (p, q) => renderViaHTTP(context.appPort, p, q)) | ||
it('should throw if pageExtensions has invalid extensions', async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
`module.exports = { pageExtensions: ['js', 123] }` | ||
) | ||
|
||
const { stderr } = await runNextCommand(['build', appDir], { stderr: true }) | ||
|
||
await fs.remove(nextConfig) | ||
|
||
console.log('ERR', stderr) | ||
|
||
expect(stderr).toContain( | ||
'Specified pageExtensions is not an array of strings, found "123" of type "number". Please update this config or remove it' | ||
) | ||
}) | ||
|
||
it('should throw if @zeit/next-typescript is used', async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
`const withTypescript = require('@zeit/next-typescript') | ||
module.exports = withTypescript() | ||
` | ||
) | ||
|
||
const { stderr } = await runNextCommand(['build', appDir], { stderr: true }) | ||
|
||
await fs.remove(nextConfig) | ||
|
||
expect(stderr).toContain( | ||
'@zeit/next-typescript is no longer needed since Next.js has built-in support for TypeScript now' | ||
) | ||
}) | ||
}) |