forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for invalid assetPrefix (vercel#9759)
* Add check for invalid assetPrefix * Update test/integration/invalid-config-values/test/index.test.js Co-Authored-By: JJ Kasper <[email protected]>
- Loading branch information
1 parent
a32af59
commit 2ba056a
Showing
4 changed files
with
87 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Invalid assetPrefix | ||
|
||
#### Why This Error Occurred | ||
|
||
The value of `assetPrefix` in `next.config.js` is set to something that is not a `string`. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Ensure that `assetPrefix` is a `string`. | ||
|
||
Example: | ||
|
||
```js | ||
module.exports = { | ||
assetPrefix: '/', | ||
} | ||
``` |
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 @@ | ||
export default () => 'hi' |
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,63 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
const appDir = join(__dirname, '../') | ||
const nextConfigPath = join(appDir, 'next.config.js') | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
const cleanUp = () => fs.remove(nextConfigPath) | ||
|
||
describe('Handles valid/invalid assetPrefix', () => { | ||
beforeAll(() => cleanUp()) | ||
afterAll(() => cleanUp()) | ||
|
||
it('should not error without usage of assetPrefix', async () => { | ||
await fs.writeFile( | ||
nextConfigPath, | ||
`module.exports = { | ||
}` | ||
) | ||
|
||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).not.toMatch(/Specified assetPrefix is not a string/) | ||
}) | ||
|
||
it('should not error when assetPrefix is a string', async () => { | ||
await fs.writeFile( | ||
nextConfigPath, | ||
`module.exports = { | ||
assetPrefix: '/hello' | ||
}` | ||
) | ||
|
||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).not.toMatch(/Specified assetPrefix is not a string/) | ||
}) | ||
|
||
it('should error on wrong usage of assetPrefix', async () => { | ||
await fs.writeFile( | ||
nextConfigPath, | ||
`module.exports = { | ||
assetPrefix: null | ||
}` | ||
) | ||
|
||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).toMatch(/Specified assetPrefix is not a string/) | ||
}) | ||
|
||
it('should error on usage of assetPrefix with undefined as value', async () => { | ||
await fs.writeFile( | ||
nextConfigPath, | ||
`module.exports = { | ||
assetPrefix: undefined | ||
}` | ||
) | ||
|
||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) | ||
expect(stderr).toMatch(/Specified assetPrefix is not a string/) | ||
}) | ||
}) |