Skip to content

Commit

Permalink
update tests and keep dynamic in client component
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 13, 2022
1 parent d21a770 commit 3ea78c9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
6 changes: 5 additions & 1 deletion test/e2e/app-dir/app/app/dashboard/index/dynamic.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ import styles from './dynamic.module.css'

export default function Dynamic() {
let [state] = useState('next dynamic')
return <p className={styles.dynamic}>hello from modern the {state}</p>
return (
<p id="css-text-dynamic" className={styles.dynamic}>
hello from modern the {state}
</p>
)
}
4 changes: 3 additions & 1 deletion test/e2e/app-dir/app/app/dashboard/index/lazy.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import styles from './lazy.module.css'
export default function LazyComponent() {
return (
<>
<p className={styles.lazy}>hello from lazy</p>
<p id="css-text-lazy" className={styles.lazy}>
hello from lazy
</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dynamic from 'next/dynamic'

const Dynamic = dynamic(() => import('./dynamic.client'))

export function NextDynamicClientComponent() {
return <Dynamic />
}
11 changes: 0 additions & 11 deletions test/e2e/app-dir/app/app/dashboard/index/next-dynamic.server.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/e2e/app-dir/app/app/dashboard/index/page.server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LazyClientComponent } from './react-lazy.client.js'
import { NextDynamicClientComponent } from './next-dynamic.server.js'
import { LazyClientComponent } from './react-lazy.client'
import { NextDynamicClientComponent } from './next-dynamic.client'

export default function DashboardIndexPage() {
return (
Expand Down
21 changes: 17 additions & 4 deletions test/e2e/app-dir/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { check, fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import path from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
Expand Down Expand Up @@ -64,11 +64,24 @@ describe('app dir', () => {
it('should serve /index as separate page', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from app/dashboard/index')
// should load chunks generated via async import correctly
expect(html).toContain('hello from lazy')
})

it('should load chunks generated via async import correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from lazy')
// TODO-APP: handle css modules fouc in dev
it.skip('should handle css imports in next/dynamic correctly', async () => {
const browser = await webdriver(next.url, '/dashboard/index')

expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#css-text-dynamic')).color`
)
).toBe('rgb(0, 0, 255)')
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#css-text-lazy')).color`
)
).toBe('rgb(128, 0, 128)')
})

it('should include layouts when no direct parent layout', async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/app-dir/rsc-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ describe('app dir - react server components', () => {
expect(gotInlinedData).toBe(true)
}
)
})

it('should support partial hydration with inlined server data in browser', async () => {
// Should end up with "next_streaming_data".
const browser = await webdriver(next.url, '/partial-hydration', {
waitHydration: false,
Expand Down

0 comments on commit 3ea78c9

Please sign in to comment.