-
-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/TanStack/router
# Conflicts: # packages/start/src/client/createServerFn.ts
- Loading branch information
Showing
120 changed files
with
3,673 additions
and
291 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
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
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
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
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,10 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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 @@ | ||
{ | ||
"name": "create-start-e2e", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"test:e2e": "playwright test --project=chromium" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.48.2", | ||
"@tanstack/create-start": "workspace:^", | ||
"get-port-please": "^3.1.2", | ||
"tempy": "^3.1.0", | ||
"terminate": "^2.8.0", | ||
"wait-port": "^1.1.0" | ||
} | ||
} |
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,34 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
|
||
reporter: [['line']], | ||
timeout: 60000, | ||
use: { | ||
trace: 'on-first-retry', | ||
}, | ||
workers: 1, | ||
|
||
// use: { | ||
// /* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://localhost:3001/', | ||
// }, | ||
|
||
// webServer: { | ||
// command: 'pnpm run dev', | ||
// url: 'http://localhost:3001', | ||
// reuseExistingServer: !process.env.CI, | ||
// stdout: 'pipe', | ||
// }, | ||
|
||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
}) |
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,38 @@ | ||
import { temporaryDirectory } from 'tempy' | ||
import { getRandomPort } from 'get-port-please' | ||
import { unstable_scaffoldTemplate } from '@tanstack/create-start' | ||
import { test } from '../../utils/setup' | ||
|
||
// Before running any tests - create the project in the temporary directory | ||
const projectPath = temporaryDirectory() | ||
await unstable_scaffoldTemplate({ | ||
cfg: { | ||
packageManager: { | ||
installDeps: true, | ||
packageManager: 'pnpm', | ||
}, | ||
git: { | ||
setupGit: false, | ||
}, | ||
packageJson: { | ||
type: 'new', | ||
name: 'barebones-test', | ||
}, | ||
ide: { | ||
ide: 'vscode', | ||
}, | ||
}, | ||
targetPath: projectPath, | ||
templateId: 'barebones', | ||
}) | ||
|
||
const PORT = await getRandomPort() | ||
test.use({ projectPath }) | ||
test.use({ port: PORT }) | ||
test.use({ baseURL: `http://localhost:${PORT}` }) | ||
|
||
test.describe('barebones template e2e', () => { | ||
test('Navigating to index page', async ({ page }) => { | ||
await page.goto('/') | ||
}) | ||
}) |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"jsx": "react-jsx", | ||
"target": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"module": "ESNext" | ||
} | ||
} |
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,72 @@ | ||
import { exec, execSync } from 'node:child_process' | ||
import { test as baseTest } from '@playwright/test' | ||
import terminate from 'terminate/promise' | ||
import waitPort from 'wait-port' | ||
|
||
async function _setup( | ||
projectPath: string, | ||
port: number, | ||
): Promise<{ | ||
PID: number | ||
ADDR: string | ||
killProcess: () => Promise<void> | ||
deleteTempDir: () => void | ||
}> { | ||
const ADDR = `http://localhost:${port}` | ||
|
||
const childProcess = exec( | ||
`VITE_SERVER_PORT=${port} pnpm vinxi dev --port ${port}`, | ||
{ | ||
cwd: projectPath, | ||
}, | ||
) | ||
|
||
childProcess.stdout?.on('data', (data) => { | ||
const message = data.toString() | ||
console.log('Stdout:', message) | ||
}) | ||
|
||
childProcess.stderr?.on('data', (data) => { | ||
console.error('Stderr:', data.toString()) | ||
}) | ||
|
||
try { | ||
await waitPort({ port, timeout: 30000 }) // Added timeout | ||
} catch (err) { | ||
console.error('Failed to start server:', err) | ||
throw err | ||
} | ||
|
||
const PID = childProcess.pid! | ||
const killProcess = async () => { | ||
console.log('Killing process') | ||
try { | ||
await terminate(PID) | ||
} catch (err) { | ||
console.error('Failed to kill process:', err) | ||
} | ||
} | ||
const deleteTempDir = () => execSync(`rm -rf ${projectPath}`) | ||
|
||
return { PID, ADDR, killProcess, deleteTempDir } | ||
} | ||
|
||
type SetupApp = Awaited<ReturnType<typeof _setup>> | ||
|
||
export const test = baseTest.extend<{ | ||
setupApp: SetupApp | ||
projectPath: string | ||
port: number | ||
ensureServer: void | ||
}>({ | ||
projectPath: ['', { option: true }], | ||
port: [0, { option: true }], | ||
ensureServer: [ | ||
async ({ projectPath, port }, use) => { | ||
const setup = await _setup(projectPath, port) | ||
await use() | ||
await setup.killProcess() | ||
}, | ||
{ auto: true }, | ||
], | ||
}) |
63 changes: 63 additions & 0 deletions
63
e2e/start/basic/app/routes/-server-fns/allow-fn-return-null.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,63 @@ | ||
/** | ||
* This exported component checks whether the server function can | ||
* return null without throwing an error or returning something else. | ||
* @link https://github.com/TanStack/router/issues/2776 | ||
*/ | ||
|
||
import * as React from 'react' | ||
import { createServerFn } from '@tanstack/start' | ||
|
||
const $allow_return_null_getFn = createServerFn().handler(async () => { | ||
return null | ||
}) | ||
const $allow_return_null_postFn = createServerFn({ method: 'POST' }).handler( | ||
async () => { | ||
return null | ||
}, | ||
) | ||
|
||
export function AllowServerFnReturnNull() { | ||
const [getServerResult, setGetServerResult] = React.useState<any>('-') | ||
const [postServerResult, setPostServerResult] = React.useState<any>('-') | ||
|
||
return ( | ||
<div className="p-2 border m-2 grid gap-2"> | ||
<h3>Allow ServerFn to return `null`</h3> | ||
<p> | ||
This component checks whether the server function can return null | ||
without throwing an error. | ||
</p> | ||
<div> | ||
It should return{' '} | ||
<code> | ||
<pre>{JSON.stringify(null)}</pre> | ||
</code> | ||
</div> | ||
<p> | ||
{`GET: $allow_return_null_getFn returns`} | ||
<br /> | ||
<span data-testid="allow_return_null_getFn-response"> | ||
{JSON.stringify(getServerResult)} | ||
</span> | ||
</p> | ||
<p> | ||
{`POST: $allow_return_null_postFn returns`} | ||
<br /> | ||
<span data-testid="allow_return_null_postFn-response"> | ||
{JSON.stringify(postServerResult)} | ||
</span> | ||
</p> | ||
<button | ||
data-testid="test-allow-server-fn-return-null-btn" | ||
type="button" | ||
className="rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" | ||
onClick={() => { | ||
$allow_return_null_getFn().then(setGetServerResult) | ||
$allow_return_null_postFn().then(setPostServerResult) | ||
}} | ||
> | ||
Test Allow Server Fn Return Null | ||
</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
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
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
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
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
Oops, something went wrong.