-
Notifications
You must be signed in to change notification settings - Fork 86
fix: add better error messaging for builds #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,80 @@ | ||
import { checkNextSiteHasBuilt } from '../../plugin/src/helpers/verification' | ||
import { outdent } from 'outdent' | ||
|
||
import type { NetlifyPluginUtils } from '@netlify/build' | ||
type FailBuild = NetlifyPluginUtils['build']['failBuild'] | ||
|
||
jest.mock('fs', () => { | ||
return { | ||
existsSync: jest.fn() | ||
} | ||
}) | ||
|
||
describe('checkNextSiteHasBuilt', () => { | ||
let failBuildMock | ||
const { existsSync } = require('fs') | ||
|
||
beforeEach(() => { | ||
failBuildMock = (jest.fn() as unknown) as FailBuild | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('returns error message about incorrectly publishing the ".next" directory when "next export" was run', () => { | ||
existsSync.mockReturnValue(true) | ||
|
||
const expectedFailureMessage = outdent` | ||
Detected that "next export" was run, but site is incorrectly publishing the ".next" directory. | ||
The publish directory should be set to "out", and you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". | ||
` | ||
|
||
checkNextSiteHasBuilt({ publish: '.next', failBuild: failBuildMock }) | ||
|
||
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage) | ||
}) | ||
|
||
it('returns error message prompt to change publish directory to ".next"', () => { | ||
// False for not initially finding the specified 'publish' directory, | ||
// True for successfully finding a '.next' directory with a production build | ||
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true) | ||
|
||
const expectedFailureMessage = outdent` | ||
The directory "someCustomDir" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. | ||
However, a '.next' directory was found with a production build. | ||
Consider changing your 'publish' directory to '.next' | ||
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". | ||
` | ||
|
||
checkNextSiteHasBuilt({ publish: 'someCustomDir', failBuild: failBuildMock }) | ||
|
||
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage) | ||
}) | ||
|
||
it('returns error message prompt when publish directory is set to "out"', () => { | ||
existsSync.mockReturnValue(false) | ||
|
||
const expectedFailureMessage = outdent` | ||
The directory "out" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. | ||
Your publish directory is set to "out", but in most cases it should be ".next". | ||
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". | ||
` | ||
checkNextSiteHasBuilt({ publish: 'out', failBuild: failBuildMock }) | ||
|
||
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage) | ||
}) | ||
|
||
it('returns default error message when production build was not found', () => { | ||
existsSync.mockReturnValue(false) | ||
const expectedFailureMessage = outdent` | ||
The directory ".next" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. | ||
In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config. | ||
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". | ||
` | ||
checkNextSiteHasBuilt({ publish: '.next', failBuild: failBuildMock }) | ||
|
||
expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a const to avoid wording change errors?