Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error when legacy methods are detected
- Loading branch information
Showing
4 changed files
with
115 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
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,7 @@ | ||
export async function unstable_getStaticProps() { | ||
return { | ||
props: {}, | ||
} | ||
} | ||
|
||
export default () => 'hi' |
81 changes: 81 additions & 0 deletions
81
test/integration/legacy-ssg-methods-error/test/index.test.js
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,81 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 | ||
|
||
const appDir = join(__dirname, '..') | ||
const indexPage = join(appDir, 'pages/index.js') | ||
let origIndexPage = '' | ||
|
||
const runTests = (serverless = false) => { | ||
if (serverless) { | ||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
beforeEach(() => | ||
fs.writeFile( | ||
nextConfig, | ||
` | ||
module.exports = { | ||
target: 'experimental-serverless-trace' | ||
} | ||
` | ||
) | ||
) | ||
|
||
afterAll(() => fs.remove(nextConfig)) | ||
} | ||
|
||
it('should error when legacy unstable_getStaticProps', async () => { | ||
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) | ||
expect(code).toBe(1) | ||
expect(stderr).toContain( | ||
`unstable_getStaticProps was replaced with getStaticProps. Please update your code.` | ||
) | ||
}) | ||
|
||
it('should error when legacy unstable_getServerProps', async () => { | ||
await fs.writeFile( | ||
indexPage, | ||
origIndexPage.replace('getStaticProps', 'getServerProps') | ||
) | ||
|
||
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) | ||
|
||
expect(code).toBe(1) | ||
expect(stderr).toContain( | ||
`unstable_getServerProps was replaced with getServerSideProps. Please update your code.` | ||
) | ||
}) | ||
|
||
it('should error when legacy unstable_getServerProps', async () => { | ||
await fs.writeFile( | ||
indexPage, | ||
origIndexPage.replace('getStaticProps', 'getStaticPaths') | ||
) | ||
|
||
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) | ||
|
||
expect(code).toBe(1) | ||
expect(stderr).toContain( | ||
`unstable_getStaticPaths was replaced with getStaticPaths. Please update your code.` | ||
) | ||
}) | ||
} | ||
|
||
describe('Mixed getStaticProps and getServerSideProps error', () => { | ||
beforeAll(async () => { | ||
origIndexPage = await fs.readFile(indexPage, 'utf8') | ||
}) | ||
afterEach(() => fs.writeFile(indexPage, origIndexPage)) | ||
|
||
describe('server mode', () => { | ||
runTests(false) | ||
}) | ||
|
||
describe('serverless mode', () => { | ||
runTests(true) | ||
}) | ||
}) |