Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jul 19, 2020
1 parent 01d80e3 commit 121ebf8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/integration/no-duplicate-compile-error/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Abc() {
return <div id="a">hello</div>
}
61 changes: 61 additions & 0 deletions test/integration/no-duplicate-compile-error/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-env jest */
import {
check,
File,
findPort,
hasRedbox,
killApp,
launchApp,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'

jest.setTimeout(1000 * 60 * 3)

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

describe('no duplicate compile error output', () => {
it('show not show compile error on page refresh', async () => {
let stdout = ''
let stderr = ''

const appPort = await findPort()
const app = await launchApp(appDir, appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: true },
onStdout(msg) {
stdout += msg || ''
},
onStderr(msg) {
stderr += msg || ''
},
})

const browser = await webdriver(appPort, '/')

await browser.waitForElementByCss('#a')

const f = new File(join(appDir, 'pages', 'index.js'))
f.replace('<div id="a">hello</div>', '<div id="a"!>hello</div>')

try {
// Wait for compile error:
expect(await hasRedbox(browser, true)).toBe(true)

await browser.refresh()

// Wait for compile error to re-appear:
expect(await hasRedbox(browser, true)).toBe(true)
} finally {
f.restore()
}

// Wait for compile error to disappear:
await check(() => hasRedbox(browser).then((r) => (r ? 'yes' : 'no')), /no/)
await browser.waitForElementByCss('#a')

expect((stdout.match(/Unexpected token/g) || []).length).toBe(1)
expect(stderr).toBe('')

await killApp(app)
})
})

0 comments on commit 121ebf8

Please sign in to comment.