Skip to content

Commit

Permalink
Convert test to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed May 22, 2023
1 parent a9f1051 commit 9a4321f
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Link from 'next/link'
import type { GetStaticProps } from 'next'

export function getStaticProps({ draftMode }) {
type Props = {
random: number
draftMode: string
}

export const getStaticProps: GetStaticProps<Props> = ({ draftMode }) => {
return {
props: {
random: Math.random(),
Expand All @@ -10,7 +16,7 @@ export function getStaticProps({ draftMode }) {
}
}

export default function Another(props) {
export default function Another(props: Props) {
return (
<>
<h1>Another</h1>
Expand Down
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/disable.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: false })
res.end('Check your cookies...')
}
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/enable.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/enable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: true })
res.end('Check your cookies...')
}
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/read.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default (req: NextApiRequest, res: NextApiResponse) => {
const { draftMode } = req
res.json({ draftMode })
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useState } from 'react'
import Link from 'next/link'
import type { GetStaticProps } from 'next'

export function getStaticProps({ draftMode }) {
type Props = {
random: number
draftMode: string
}

export const getStaticProps: GetStaticProps<Props> = ({ draftMode }) => {
return {
props: {
random: Math.random(),
Expand All @@ -11,7 +17,7 @@ export function getStaticProps({ draftMode }) {
}
}

export default function Home(props) {
export default function Home(props: Props) {
const [count, setCount] = useState(0)
return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import Link from 'next/link'
import type { GetServerSideProps } from 'next'

export function getServerSideProps({ res, draftMode }) {
type Props = {
random: number
draftMode: string
}

export const getServerSideProps: GetServerSideProps<Props> = async ({
res,
draftMode,
}) => {
// test override header
res.setHeader('Cache-Control', 'public, max-age=3600')
return {
Expand All @@ -11,7 +20,7 @@ export function getServerSideProps({ res, draftMode }) {
}
}

export default function SSP(props) {
export default function SSP(props: Props) {
return (
<>
<h1>Server Side Props</h1>
Expand Down
19 changes: 19 additions & 0 deletions test/integration/draft-mode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

0 comments on commit 9a4321f

Please sign in to comment.