Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jun 24, 2020
1 parent 94773d5 commit 5a40e5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
5 changes: 5 additions & 0 deletions test/integration/config-devtool-dev/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { useEffect } from 'react'

export default function Index(props) {
useEffect(() => {
throw new Error('this should render')
}, [])
return <div>Index Page</div>
}
56 changes: 30 additions & 26 deletions test/integration/config-devtool-dev/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
/* eslint-env jest */

import { check, findPort, killApp, launchApp } from 'next-test-utils'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
import {
check,
findPort,
getRedboxSource,
hasRedbox,
killApp,
launchApp,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'

jest.setTimeout(1000 * 30)

const appDir = join(__dirname, '../')

describe('devtool set in developmemt mode in next config', () => {
it('should warn when a devtool is set in development mode', async () => {
it('should warn and revert when a devtool is set in development mode', async () => {
let stderr = ''

const appPort = await findPort()
const app = await launchApp(join(__dirname, '..'), appPort, {
const app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: true },
onStderr(msg) {
stderr += msg || ''
Expand All @@ -26,29 +33,26 @@ describe('devtool set in developmemt mode in next config', () => {
false
)

await killApp(app)
expect(found).toBeTruthy()
})

// TODO: update test to check the error overlay correctly resolves source
// frames, which is a more robust test
it('should revert to the original devtool when user set in development mode', async () => {
const appPort = await findPort()
const app = await launchApp(join(__dirname, '..'), appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: true },
})
const browserFiles = await recursiveReadDir(
join(appDir, '.next', 'static'),
/.*/
)
const jsFiles = browserFiles.filter(
(file) => file.endsWith('.js') && file.includes('/pages/')
)

jsFiles.forEach((file) => {
expect(browserFiles.includes(`${file}.map`)).toBe(false)
})
const browser = await webdriver(appPort, '/')
expect(await hasRedbox(browser)).toBe(true)
if (process.platform === 'win32') {
// TODO: add win32 snapshot
} else {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"pages/index.js (5:10) @ eval
3 | export default function Index(props) {
4 | useEffect(() => {
> 5 | throw new Error('this should render')
| ^
6 | }, [])
7 | return <div>Index Page</div>
8 | }"
`)
}
await browser.close()

await killApp(app)
expect(found).toBeTruthy()
})
})

0 comments on commit 5a40e5b

Please sign in to comment.