-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
¨Leonardo
committed
May 3, 2024
1 parent
7d54bea
commit 933f8e9
Showing
12 changed files
with
247 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# RSC CSS Modules | ||
|
||
Only RSC features, no SSR. |
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,22 @@ | ||
{ | ||
"name": "rsc-css-modules", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "waku dev", | ||
"build": "waku build", | ||
"start": "waku start" | ||
}, | ||
"dependencies": { | ||
"react": "19.0.0-beta-4508873393-20240430", | ||
"react-dom": "19.0.0-beta-4508873393-20240430", | ||
"react-server-dom-webpack": "19.0.0-beta-4508873393-20240430", | ||
"waku": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "18.2.74", | ||
"@types/react-dom": "18.2.24", | ||
"typescript": "5.4.4" | ||
} | ||
} |
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,16 @@ | ||
import styles from './app.module.css'; | ||
import { ClientCounter } from './ClientCounter.js'; | ||
|
||
const App = ({ name }: { name: string }) => { | ||
return ( | ||
<div data-testid="app-wrapper" className={styles.wrapper}> | ||
<title>Waku example</title> | ||
<p className={styles.text} data-testid="app-name"> | ||
{name} | ||
</p> | ||
<ClientCounter /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
20 changes: 20 additions & 0 deletions
20
e2e/fixtures/rsc-css-modules/src/components/ClientCounter.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,20 @@ | ||
'use client'; | ||
import { useState } from 'react'; | ||
import styles from './clientCounter.module.css'; | ||
|
||
export const ClientCounter = () => { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div className={styles.counterWrapper} data-testid="client-counter"> | ||
<p data-testid="count">{count}</p> | ||
<button | ||
className={styles.counterButton} | ||
data-testid="increment" | ||
onClick={() => setCount((c) => c + 1)} | ||
> | ||
Increment | ||
</button> | ||
</div> | ||
); | ||
}; |
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,9 @@ | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.text { | ||
font-size: 18px; | ||
color: blue; | ||
} |
9 changes: 9 additions & 0 deletions
9
e2e/fixtures/rsc-css-modules/src/components/clientCounter.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,9 @@ | ||
.counterWrapper { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 4px; | ||
} | ||
|
||
.counterButton { | ||
padding: 8px; | ||
} |
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,19 @@ | ||
import { lazy } from 'react'; | ||
import { defineEntries } from 'waku/server'; | ||
|
||
const App = lazy(() => import('./components/App.js')); | ||
|
||
export default defineEntries( | ||
// renderEntries | ||
async (input) => { | ||
return { | ||
App: <App name={input || 'Waku'} />, | ||
}; | ||
}, | ||
// getBuildConfig | ||
async () => [{ pathname: '/', entries: [{ input: '' }] }], | ||
// getSsrConfig | ||
() => { | ||
throw new Error('SSR should not be used in this test.'); | ||
}, | ||
); |
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,13 @@ | ||
import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { Root, Slot } from 'waku/client'; | ||
|
||
const rootElement = ( | ||
<StrictMode> | ||
<Root> | ||
<Slot id="App" /> | ||
</Root> | ||
</StrictMode> | ||
); | ||
|
||
createRoot(document.body).render(rootElement); |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "esnext", | ||
"downlevelIteration": true, | ||
"esModuleInterop": true, | ||
"module": "nodenext", | ||
"skipLibCheck": true, | ||
"noUncheckedIndexedAccess": true, | ||
"exactOptionalPropertyTypes": true, | ||
"types": ["react/experimental"], | ||
"jsx": "react-jsx", | ||
"outDir": "./dist", | ||
"composite": true | ||
}, | ||
"include": ["./src", "./waku.config.ts"] | ||
} |
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,16 @@ | ||
const DO_NOT_BUNDLE = ''; | ||
|
||
/** @type {import('waku/config').Config} */ | ||
export default { | ||
middleware: (cmd: 'dev' | 'start') => [ | ||
...(cmd === 'dev' | ||
? [ | ||
import( | ||
/* @vite-ignore */ DO_NOT_BUNDLE + 'waku/middleware/dev-server' | ||
), | ||
] | ||
: []), | ||
import('waku/middleware/rsc'), | ||
import('waku/middleware/fallback'), | ||
], | ||
}; |
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,77 @@ | ||
import { expect } from '@playwright/test'; | ||
import { execSync, exec, ChildProcess } from 'node:child_process'; | ||
import { fileURLToPath } from 'node:url'; | ||
import waitPort from 'wait-port'; | ||
import { debugChildProcess, getFreePort, terminate, test } from './utils.js'; | ||
import { rm } from 'node:fs/promises'; | ||
|
||
const waku = fileURLToPath( | ||
new URL('../packages/waku/dist/cli.js', import.meta.url), | ||
); | ||
|
||
const commands = [ | ||
{ | ||
command: 'dev', | ||
}, | ||
{ | ||
build: 'build', | ||
command: 'start', | ||
}, | ||
]; | ||
|
||
const cwd = fileURLToPath( | ||
new URL('./fixtures/rsc-css-modules', import.meta.url), | ||
); | ||
|
||
for (const { build, command } of commands) { | ||
test.describe(`rsc-css-modules: ${command}`, () => { | ||
let cp: ChildProcess; | ||
let port: number; | ||
test.beforeAll('remove cache', async () => { | ||
await rm(`${cwd}/dist`, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}); | ||
|
||
test.beforeAll(async () => { | ||
if (build) { | ||
execSync(`node ${waku} ${build}`, { cwd }); | ||
} | ||
port = await getFreePort(); | ||
cp = exec(`node ${waku} ${command} --port ${port}`, { cwd }); | ||
debugChildProcess(cp, fileURLToPath(import.meta.url), [ | ||
/ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time/, | ||
]); | ||
await waitPort({ port }); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await terminate(cp.pid!); | ||
}); | ||
|
||
test('css-modules classes', async ({ page }) => { | ||
await page.goto(`http://localhost:${port}/`); | ||
|
||
const wrapperClass = await page | ||
.getByTestId('app-wrapper') | ||
.getAttribute('class'); | ||
expect(wrapperClass).toContain('wrapper'); | ||
|
||
const appNameClass = await page | ||
.getByTestId('app-name') | ||
.getAttribute('class'); | ||
expect(appNameClass).toContain('text'); | ||
|
||
const clientcounterClass = await page | ||
.getByTestId('client-counter') | ||
.getAttribute('class'); | ||
expect(clientcounterClass).toContain('counterWrapper'); | ||
|
||
const incrementClass = await page | ||
.getByTestId('increment') | ||
.getAttribute('class'); | ||
expect(incrementClass).toContain('counterButton'); | ||
}); | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.