Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/e2e/url-imports/next.lock/lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"http://localhost:12345/value1.js": {
"integrity": "sha512-S1eh3STyIGuRSfoAVU0jhxVY2MoRXSC/JduKMKuATb91ArhG0G2rvRNsGvD2kZo/jENlbrMtWNkzK2dGLgaUfg==",
"contentType": "application/javascript; charset=UTF-8"
},
"http://localhost:12345/value2.js": {
"integrity": "sha512-R4XoB/ZTbRL9FGcM5d3hkxtxmMUXaKNKCqRKZPDy1v7Hh61HPLidPQHga1XMurakZPoJnCC5a5jRdOAagn3LRA==",
"contentType": "application/javascript; charset=UTF-8"
},
"http://localhost:12345/value3.js": {
"integrity": "sha512-xtYaDPwejlXaMwQOdnYldln3wA5UYqIaJXMuCdBmyjgRX3zSKKd/AbGYobURfITmpzkz7U7E5GEK2Ju17qCZkw==",
"contentType": "application/javascript; charset=UTF-8"
},
"http://localhost:12345/value4.js": {
"integrity": "sha512-orh6tVnh1jjxWNNLduiv0pUcW0guzwTmy52JQGdz4D2LL2IgIlJaC0w4+YBtIBXa2kKGho839WgGAK0sC0Folw==",
"contentType": "application/javascript; charset=UTF-8"
},
"https://github.com/vercel/next.js/raw/canary/test/integration/url/public/vercel.png": "no-cache",
"https://github.com/vercel/next.js/raw/canary/test/integration/url/public/vercel.png?_=image": "no-cache",
"https://github.com/vercel/next.js/raw/canary/test/integration/url/public/vercel.png?_=ssg": "no-cache",
"https://github.com/vercel/next.js/raw/canary/test/integration/url/public/vercel.png?_=ssr": "no-cache",
"https://github.com/vercel/next.js/raw/canary/test/integration/url/public/vercel.png?_=static": "no-cache",
"version": 1
}
1 change: 1 addition & 0 deletions test/e2e/url-imports/source/value1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42 // 1
1 change: 1 addition & 0 deletions test/e2e/url-imports/source/value2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42 // 2
1 change: 1 addition & 0 deletions test/e2e/url-imports/source/value3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42 // 3
1 change: 1 addition & 0 deletions test/e2e/url-imports/source/value4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42 // 4
94 changes: 94 additions & 0 deletions test/e2e/url-imports/url-imports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
getBrowserBodyText,
startStaticServer,
stopApp,
retry,
} from 'next-test-utils'
import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path'

// experimental.urlImports is not implemented in Turbopack
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
`Handle url imports`,
() => {
let staticServer
let staticServerPort
beforeAll(async () => {
staticServerPort = 12345
staticServer = await startStaticServer(
join(__dirname, 'source'),
undefined,
staticServerPort
)
})
afterAll(async () => {
await stopApp(staticServer)
})

const { next } = nextTestSetup({
files: isNextDev
? {
// exclude next.lock here, should be generated automatically in dev
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
pages: new FileRef(join(__dirname, 'pages')),
public: new FileRef(join(__dirname, 'public')),
}
: __dirname,
})

const expectedServer =
/Hello <!-- -->42<!-- -->\+<!-- -->42<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png/
const expectedClient = new RegExp(
expectedServer.source.replace(/<!-- -->/g, '')
)

for (const page of ['/static', '/ssr', '/ssg']) {
it(`should render the ${page} page`, async () => {
const html = await next.render(page)
expect(html).toMatch(expectedServer)
})

it(`should client-render the ${page} page`, async () => {
const browser = await next.browser(page)
await retry(async () =>
expect(await getBrowserBodyText(browser)).toMatch(expectedClient)
)
})
}

it(`should render a static url image import`, async () => {
const browser = await next.browser('/image')
await browser.waitForElementByCss('#static-image')
await retry(async () =>
expect(
await browser.elementByCss('#static-image').getAttribute('src')
).toMatch(
/^\/_next\/image\?url=%2F_next%2Fstatic%2Fmedia%2Fvercel\.[0-9a-f]{8}\.png&/
)
)
})

it(`should allow url import in css`, async () => {
const browser = await next.browser('/css')

await browser.waitForElementByCss('#static-css')
await retry(async () =>
expect(
await browser
.elementByCss('#static-css')
.getComputedCss('background-image')
).toMatch(
/^url\("http:\/\/localhost:\d+\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png"\)$/
)
)
})

it('should respond on value api', async () => {
const data = await next
.fetch('/api/value')
.then((res) => res.ok && res.json())

expect(data).toEqual({ value: 42 })
})
}
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 46 additions & 0 deletions test/e2e/url/url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getBrowserBodyText, retry } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'

describe(`Handle new URL asset references`, () => {
const { next } = nextTestSetup({
files: __dirname,
})

const expectedServer =
/Hello <!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png<!-- -->\+<!-- -->\/_next\/static\/media\/vercel\.[0-9a-f]{8}\.png/
const expectedClient = new RegExp(
expectedServer.source.replace(/<!-- -->/g, '')
)

for (const page of ['/static', '/ssr', '/ssg']) {
it(`should render the ${page} page`, async () => {
const html = await next.render(page)
expect(html).toMatch(expectedServer)
})

it(`should client-render the ${page} page`, async () => {
const browser = await next.browser(page)
await retry(async () =>
expect(await getBrowserBodyText(browser)).toMatch(expectedClient)
)
})
}

it('should respond on size api', async () => {
const data = await next
.fetch('/api/size')
.then((res) => res.ok && res.json())

expect(data).toEqual({ size: 30079 })
})

it('should respond on basename api', async () => {
const data = await next
.fetch('/api/basename')
.then((res) => res.ok && res.json())

expect(data).toEqual({
basename: expect.stringMatching(/^vercel\.[0-9a-f]{8}\.png$/),
})
})
})
3 changes: 0 additions & 3 deletions test/integration/url-imports/.gitignore

This file was deleted.

125 changes: 0 additions & 125 deletions test/integration/url-imports/test/index.test.js

This file was deleted.

83 changes: 0 additions & 83 deletions test/integration/url/test/index.test.js

This file was deleted.

Loading