Files
next.js/test/integration/next-image-legacy/trailing-slash/test/index.test.ts

83 lines
2.1 KiB
TypeScript

/* eslint-env jest */
import {
check,
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
describe('Image Component Trailing Slash Tests', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2F(immutable%2F)?media%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
}
}
})
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next start', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
await check(async () => {
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2F(immutable%2F)?media%2Ftest(.+).jpg&w=828&q=75/
)
return 'success'
}, 'success')
} finally {
if (browser) {
await browser.close()
}
}
})
}
)
})