Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jun 27, 2024
1 parent 846ccc6 commit ea2e381
Show file tree
Hide file tree
Showing 51 changed files with 206 additions and 187 deletions.
4 changes: 2 additions & 2 deletions docs/framework/react/guide/data-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/posts')({
// Pass the fetchPosts function to the route context
beforeLoad: () => ({
fetchPosts: () => console.log('foo'),
fetchPosts: () => console.info('foo'),
}),
loader: ({ context: { fetchPosts } }) => {
console.log(fetchPosts()) // 'foo'
console.info(fetchPosts()) // 'foo'

// ...
},
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/guide/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ function Component() {

useEffect(() => {
if (matchRoute({ to: '/users', pending: true })) {
console.log('The /users route is matched and pending')
console.info('The /users route is matched and pending')
}
})

Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-default-search-params/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type PostType = {
}

const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 300))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
.then((r) => r.data.slice(0, 10))
}

const fetchPost = async (postId: number) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 300))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-file-based-codesplitting/src/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type PostType = {
}

export const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand All @@ -24,7 +24,7 @@ export const fetchPost = async (postId: string) => {
}

export const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-file-based/src/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type PostType = {
}

export const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand All @@ -24,7 +24,7 @@ export const fetchPost = async (postId: string) => {
}

export const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')
Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-react-query-file-based/src/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {
export class PostNotFoundError extends Error {}

export const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand All @@ -25,7 +25,7 @@ export const fetchPost = async (postId: string) => {
}

export const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-react-query/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type PostType = {
}

const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
.then((r) => r.data.slice(0, 10))
}

const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand Down
6 changes: 3 additions & 3 deletions examples/react/basic-ssr-file-based/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export async function createServer(
}
})()

console.log('Rendering: ', url, '...')
console.info('Rendering: ', url, '...')
entry.render({ req, res, url, head: viteHead })
} catch (e) {
!isProd && vite.ssrFixStacktrace(e)
console.log(e.stack)
console.info(e.stack)
res.status(500).end(e.stack)
}
})
Expand All @@ -87,7 +87,7 @@ export async function createServer(
if (!isTest) {
createServer().then(async ({ app }) =>
app.listen(await getPort({ port: portNumbers(3000, 3100) }), () => {
console.log('Client Server: http://localhost:3000')
console.info('Client Server: http://localhost:3000')
}),
)
}
2 changes: 1 addition & 1 deletion examples/react/basic-ssr-file-based/src/routes/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {

export const Route = createFileRoute('/posts')({
loader: async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) =>
setTimeout(r, 300 + Math.round(Math.random() * 300)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostType } from '../posts'

export const Route = createFileRoute('/posts/$postId')({
loader: async ({ params }) => {
console.log(`Fetching post with id ${params.postId}...`)
console.info(`Fetching post with id ${params.postId}...`)

await new Promise((r) => setTimeout(r, Math.round(Math.random() * 300)))

Expand Down
6 changes: 3 additions & 3 deletions examples/react/basic-ssr-streaming-file-based/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export async function createServer(
}
})()

console.log('Rendering: ', url, '...')
console.info('Rendering: ', url, '...')
entry.render({ req, res, url, head: viteHead })
} catch (e) {
!isProd && vite.ssrFixStacktrace(e)
console.log(e.stack)
console.info(e.stack)
res.status(500).end(e.stack)
}
})
Expand All @@ -87,7 +87,7 @@ export async function createServer(
if (!isTest) {
createServer().then(async ({ app }) =>
app.listen(await getPort({ port: portNumbers(3000, 3100) }), () => {
console.log('Client Server: http://localhost:3000')
console.info('Client Server: http://localhost:3000')
}),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {

export const Route = createFileRoute('/posts')({
loader: async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) =>
setTimeout(r, 300 + Math.round(Math.random() * 300)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react'
import type { PostType } from '../posts'

async function fetchPostById(postId: string) {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)

await new Promise((r) => setTimeout(r, 100 + Math.round(Math.random() * 100)))

Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type PostType = {
}

const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 300))
return (
axios
Expand All @@ -32,7 +32,7 @@ const fetchPosts = async () => {
}

const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 300))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand Down
4 changes: 2 additions & 2 deletions examples/react/deferred-data/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ type CommentType = {
}

const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 100))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
.then((r) => r.data.slice(0, 10))
}

const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)

const commentsPromise = new Promise((r) => setTimeout(r, 2000))
.then(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function fetchInvoiceById(id: number) {
export async function postInvoice(partialInvoice: Partial<Invoice>) {
return actionDelayFn(() => {
if (partialInvoice.title?.includes('error')) {
console.log('error')
console.error('error')
throw new Error('Ouch!')
}
const invoice = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function fetchInvoiceById(id: number) {
export async function postInvoice(partialInvoice: Partial<Invoice>) {
return actionDelayFn(() => {
if (partialInvoice.title?.includes('error')) {
console.log('error')
console.error('error')
throw new Error('Ouch!')
}
const invoice = {
Expand Down
7 changes: 0 additions & 7 deletions examples/react/kitchen-sink-react-query/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,6 @@ const router = createRouter({
defaultPreloadStaleTime: 0,
})

// router.subscribe('onResolved', ({ pathChanged }) => {
// if (pathChanged) {
// console.log('invalidate')
// queryClient.getMutationCache().clear()
// }
// })

declare module '@tanstack/react-router' {
interface Register {
router: typeof router
Expand Down
2 changes: 1 addition & 1 deletion examples/react/kitchen-sink-react-query/src/mockTodos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function fetchInvoiceById(id: number) {
export async function postInvoice(partialInvoice: Partial<Invoice>) {
return actionDelayFn(() => {
if (partialInvoice.title?.includes('error')) {
console.log('error')
console.error('error')
throw new Error('Ouch!')
}
const invoice = {
Expand Down
2 changes: 1 addition & 1 deletion examples/react/kitchen-sink/src/mockTodos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function fetchInvoiceById(id: number) {
export async function postInvoice(partialInvoice: Partial<Invoice>) {
return actionDelayFn(() => {
if (partialInvoice.title?.includes('error')) {
console.log('error')
console.error('error')
throw new Error('Ouch!')
}
const invoice = {
Expand Down
4 changes: 2 additions & 2 deletions examples/react/location-masking/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type PhotoType = {
class NotFoundError extends Error {}

const fetchPhotos = async () => {
console.log('Fetching photos...')
console.info('Fetching photos...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<PhotoType[]>('https://jsonplaceholder.typicode.com/photos')
.then((r) => r.data.slice(0, 10))
}

const fetchPhoto = async (photoId: string) => {
console.log(`Fetching photo with id ${photoId}...`)
console.info(`Fetching photo with id ${photoId}...`)
await new Promise((r) => setTimeout(r, 500))
const photo = await axios
.get<PhotoType>(`https://jsonplaceholder.typicode.com/photos/${photoId}`)
Expand Down
4 changes: 2 additions & 2 deletions examples/react/quickstart-file-based/src/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {
export class PostNotFoundError extends Error {}

export const fetchPost = async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand All @@ -25,7 +25,7 @@ export const fetchPost = async (postId: string) => {
}

export const fetchPosts = async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<PostType[]>('https://jsonplaceholder.typicode.com/posts')
Expand Down
2 changes: 1 addition & 1 deletion examples/react/start-basic-rsc/app/routes/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const Route = createFileRoute('/posts')({
})

function PostsComponent() {
console.log('render PostsComponent')
console.info('render PostsComponent')
return renderRsc(Route.useLoaderData())
}
4 changes: 2 additions & 2 deletions examples/react/start-basic-rsc/app/utils/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type PostType = {

export const fetchPost = async (postId: string) => {
'use server'
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
await new Promise((r) => setTimeout(r, 500))
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
Expand All @@ -27,7 +27,7 @@ export const fetchPost = async (postId: string) => {

export const fetchPosts = async () => {
'use server'
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')
Expand Down
4 changes: 2 additions & 2 deletions examples/react/start-basic/app/utils/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {
}

export const fetchPost = createServerFn('GET', async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
.then((r) => r.data)
Expand All @@ -24,7 +24,7 @@ export const fetchPost = createServerFn('GET', async (postId: string) => {
})

export const fetchPosts = createServerFn('GET', async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
return axios
.get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')
.then((r) => r.data.slice(0, 10))
Expand Down
4 changes: 2 additions & 2 deletions examples/react/start-trellaux/app/utils/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {
}

export const fetchPost = createServerFn('GET', async (postId: string) => {
console.log(`Fetching post with id ${postId}...`)
console.info(`Fetching post with id ${postId}...`)
const post = await axios
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
.then((r) => r.data)
Expand All @@ -24,7 +24,7 @@ export const fetchPost = createServerFn('GET', async (postId: string) => {
})

export const fetchPosts = createServerFn('GET', async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
return axios
.get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')
.then((r) => r.data.slice(0, 10))
Expand Down
2 changes: 1 addition & 1 deletion examples/react/wip-with-bling/src/routes/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type CommentType = {
}

const fetchPosts = server$(async () => {
console.log('Fetching posts...')
console.info('Fetching posts...')
await new Promise((r) => setTimeout(r, 500))
return fetch('https://jsonplaceholder.typicode.com/posts')
.then((d) => d.json() as Promise<PostType[]>)
Expand Down
Loading

0 comments on commit ea2e381

Please sign in to comment.