Skip to content

Commit

Permalink
use e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jan 23, 2023
1 parent fd16286 commit 8d6cf07
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
34 changes: 31 additions & 3 deletions test/development/basic/next-dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,44 @@ import { createNext, FileRef } from 'e2e-utils'
import { renderViaHTTP, check, hasRedbox } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'

describe.each([[''], ['/docs']])(
'basic next/dynamic usage, basePath: %p',
(basePath: string) => {
const customDocumentGipFiles = {
'pages/_document.js': `
import { Html, Main, NextScript, Head } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
Document.getInitialProps = (ctx) => {
return ctx.defaultGetInitialProps(ctx)
}
`,
}

describe.each([
['', 'default'],
['/docs', 'default'],
['', 'document.getInitialProps'],
])(
'basic next/dynamic usage, basePath: %p - %p',
(basePath: string, testCase: string) => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
components: new FileRef(join(__dirname, 'next-dynamic/components')),
pages: new FileRef(join(__dirname, 'next-dynamic/pages')),
...(testCase === 'document.getInitialProps' &&
customDocumentGipFiles),
},
nextConfig: {
basePath,
Expand Down
1 change: 0 additions & 1 deletion test/integration/app-document/components/lazy.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/integration/app-document/components/shared-module.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration/app-document/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import App from 'next/app'
import React from 'react'
import { setState } from '../components/shared-module'
import { setState } from '../shared-module'

setState(typeof window === 'undefined' ? 'UPDATED' : 'UPDATED CLIENT')

Expand Down
3 changes: 0 additions & 3 deletions test/integration/app-document/pages/dynamic.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration/app-document/pages/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import currentState from '../components/shared-module'
import currentState from '../shared-module'

export default () => {
return <p id="currentstate">{currentState()}</p>
Expand Down
5 changes: 0 additions & 5 deletions test/integration/app-document/test/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ export default function ({ app }, suiteName, render, fetch) {
expect(src).toMatch(/\?ts=/)
})
})

test('It renders dynamic in SSR correctly when getInitialProps is specified', async () => {
const $ = await get$('/dynamic')
expect($('#lazy').text()).toBe('lazy-loaded')
})
})

describe('_app', () => {
Expand Down

0 comments on commit 8d6cf07

Please sign in to comment.