Skip to content

Commit

Permalink
added test for empty next.config file
Browse files Browse the repository at this point in the history
  • Loading branch information
James Mosier committed Jan 22, 2020
1 parent 5461cd8 commit dd11ed7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/integration/invalid-config-file/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'hi'
50 changes: 50 additions & 0 deletions test/integration/invalid-config-file/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import { nextBuild } from 'next-test-utils'

const appDir = join(__dirname, '../')
const nextConfigPath = join(appDir, 'next.config.js')
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

const cleanUp = () => fs.remove(nextConfigPath)

describe('Handles valid/invalid next.config.js', () => {
beforeAll(() => cleanUp())
afterAll(() => cleanUp())

it('should not error when config has an exported object', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
}`
)

const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).not.toMatch(
/`next.config.js` file found, but nothing was exported from it/
)
})

// it('should not error when config has an exported function', async () => {
// await fs.writeFile(
// nextConfigPath,
// `module.exports = () => {
// return {}
// }`
// )

// const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
// expect(stderr).not.toMatch(/`next.config.js` file found, but nothing was exported from it/)
// })

it('should error when no export is defined', async () => {
await fs.writeFile(nextConfigPath, `{}`)

const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).toMatch(
/`next.config.js` file found, but nothing was exported from it/
)
})
})

0 comments on commit dd11ed7

Please sign in to comment.