-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/next-swc/crates/next-dev-tests/tests/integration/next/hmr/css/input/pages/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useRef } from 'react' | ||
import { Harness, useTestHarness } from '@turbo/pack-test-harness' | ||
|
||
export default function Page() { | ||
const iframeRef = useRef<HTMLIFrameElement | null>(null) | ||
|
||
useTestHarness((harness) => runTests(harness, iframeRef.current!)) | ||
|
||
return ( | ||
<iframe style={{ width: 800, height: 600 }} src="/page" ref={iframeRef} /> | ||
) | ||
} | ||
|
||
function runTests(harness: Harness, iframe: HTMLIFrameElement) { | ||
// These tests requires a longer timeout because we're rendering another page as well. | ||
const TIMEOUT = 20000 | ||
|
||
it( | ||
'updates the page without reloading', | ||
async () => { | ||
await harness.waitForLoaded(iframe) | ||
await harness.waitForHydration(iframe, '/page') | ||
|
||
iframe.contentWindow!.__NEXT_TEST_HMR = true | ||
|
||
let element = iframe.contentDocument!.getElementById('element')! | ||
expect(element).not.toBeNull() | ||
expect(getComputedStyle(element).color).toBe('rgb(255, 0, 0)') | ||
console.log(getComputedStyle(element).color) | ||
|
||
await harness.changeFile('pages/page.module.css', 'red', 'blue') | ||
await harness.waitForCondition( | ||
() => getComputedStyle(element).color === 'rgb(0, 0, 255)' | ||
) | ||
|
||
console.log(getComputedStyle(element).color) | ||
|
||
// Make sure the page didn't reload. | ||
expect(iframe.contentWindow!.__NEXT_TEST_HMR).toBe(true) | ||
}, | ||
TIMEOUT | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
...next-swc/crates/next-dev-tests/tests/integration/next/hmr/css/input/pages/page.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.page { | ||
color: red; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/next-swc/crates/next-dev-tests/tests/integration/next/hmr/css/input/pages/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useTestHarness } from '@turbo/pack-test-harness' | ||
import styles from './page.module.css' | ||
|
||
export default function Page() { | ||
useTestHarness((harness) => harness.markAsHydrated()) | ||
|
||
return ( | ||
<div id="element" className={styles.page}> | ||
Hello Worls | ||
</div> | ||
) | ||
} |