-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) - Fixes #36681
- Loading branch information
Showing
5 changed files
with
98 additions
and
4 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
7 changes: 7 additions & 0 deletions
7
test/integration/next-image-new/both-basepath-trailingslash/next.config.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,7 @@ | ||
module.exports = { | ||
basePath: '/prefix', | ||
trailingSlash: true, | ||
images: { | ||
deviceSizes: [640, 828], | ||
}, | ||
} |
22 changes: 22 additions & 0 deletions
22
test/integration/next-image-new/both-basepath-trailingslash/pages/index.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,22 @@ | ||
import React from 'react' | ||
import Image from 'next/image' | ||
import img from '../public/test.jpg' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<p>Trailing Slash</p> | ||
<Image id="import-img" alt="import-img" src={img} priority /> | ||
<br /> | ||
<Image | ||
id="string-img" | ||
alt="string-img" | ||
src="/prefix/test.jpg" | ||
width={200} | ||
height={200} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
Binary file added
BIN
+6.61 KB
test/integration/next-image-new/both-basepath-trailingslash/public/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions
65
test/integration/next-image-new/both-basepath-trailingslash/test/index.test.ts
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,65 @@ | ||
/* eslint-env jest */ | ||
|
||
import { | ||
fetchViaHTTP, | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should correctly load image src from import', async () => { | ||
expect.assertions(3) | ||
const browser = await webdriver(appPort, '/prefix/') | ||
const img = await browser.elementById('import-img') | ||
const src = await img.getAttribute('src') | ||
expect(src).toBe( | ||
'/prefix/_next/image/?url=%2Fprefix%2F_next%2Fstatic%2Fmedia%2Ftest.fab2915d.jpg&w=828&q=75' | ||
) | ||
const res = await fetchViaHTTP(appPort, src) | ||
expect(res.status).toBe(200) | ||
expect(res.headers.get('content-type')).toBe('image/jpeg') | ||
}) | ||
it('should correctly load image src from string', async () => { | ||
expect.assertions(3) | ||
const browser = await webdriver(appPort, '/prefix/') | ||
const img = await browser.elementById('string-img') | ||
const src = await img.getAttribute('src') | ||
expect(src).toBe('/prefix/_next/image/?url=%2Fprefix%2Ftest.jpg&w=640&q=75') | ||
const res = await fetchViaHTTP(appPort, src) | ||
expect(res.status).toBe(200) | ||
expect(res.headers.get('content-type')).toBe('image/jpeg') | ||
}) | ||
} | ||
|
||
describe('Image Component basePath + trailingSlash Tests', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('server mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |