From f58ea6e656293c36c87e3ff0f6cdd3fb6e706836 Mon Sep 17 00:00:00 2001 From: Todor Totev <51530311+TodorTotev@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:25:37 +0300 Subject: [PATCH] Fix message on getStaticPaths conflict with getServerSideProps (#13874) * initial * Update tests Co-authored-by: Joe Haddad Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/next/lib/constants.ts | 2 +- .../babel-plugin-next-ssg-transform.test.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 1d744b843eee2f..b50274579fae0a 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -28,7 +28,7 @@ export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps w export const SERVER_PROPS_GET_INIT_PROPS_CONFLICT = `You can not use getInitialProps with getServerSideProps. Please remove getInitialProps.` -export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps with getServerSideProps. To use SSG, please remove getServerSideProps` +export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps` export const PAGES_404_GET_INITIAL_PROPS_ERROR = `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/next.js/404-get-initial-props` diff --git a/test/unit/babel-plugin-next-ssg-transform.test.js b/test/unit/babel-plugin-next-ssg-transform.test.js index ba43bc964824b5..0884de4776d5cd 100644 --- a/test/unit/babel-plugin-next-ssg-transform.test.js +++ b/test/unit/babel-plugin-next-ssg-transform.test.js @@ -498,5 +498,43 @@ describe('babel plugin (next-ssg-transform)', () => { `"import other from'other';const[foo]=other;export var __N_SSG=true;export default function Home(){return __jsx(\\"div\\",null);}"` ) }) + + it('errors for incorrect mix of functions', () => { + expect(() => + babel(trim` + export function getStaticProps() {} + export function getServerSideProps() {} + `) + ).toThrowError( + `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps` + ) + + expect(() => + babel(trim` + export function getServerSideProps() {} + export function getStaticProps() {} + `) + ).toThrowError( + `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps` + ) + + expect(() => + babel(trim` + export function getStaticPaths() {} + export function getServerSideProps() {} + `) + ).toThrowError( + `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps` + ) + + expect(() => + babel(trim` + export function getServerSideProps() {} + export function getStaticPaths() {} + `) + ).toThrowError( + `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps` + ) + }) }) })