Skip to content

Commit

Permalink
Ensure next.url is used instead of next.appPort (#44163)
Browse files Browse the repository at this point in the history
`appPort` shouldn't be used unless absolutely necessary as `next.url` is
more specific and allows more control.

x-ref:
https://github.com/vercel/next.js/actions/runs/3734223762/jobs/6336069606
  • Loading branch information
ijjk committed Dec 19, 2022
1 parent 3dd9af7 commit 19013a5
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 114 deletions.
2 changes: 1 addition & 1 deletion test/development/acceptance-app/helpers.ts
Expand Up @@ -20,7 +20,7 @@ export async function sandbox(
}
}
await next.start()
const browser = await webdriver(next.appPort, '/')
const browser = await webdriver(next.url, '/')
return {
browser,
session: {
Expand Down
2 changes: 1 addition & 1 deletion test/development/acceptance/helpers.ts
Expand Up @@ -29,7 +29,7 @@ export async function sandbox(
}
}
await next.start()
const browser = await webdriver(next.appPort, '/')
const browser = await webdriver(next.url, '/')
return {
session: {
async write(filename, content) {
Expand Down
40 changes: 20 additions & 20 deletions test/development/basic-basepath/hmr.test.ts
Expand Up @@ -36,7 +36,7 @@ describe('basic HMR', () => {
const newContactPagePath = join('pages', 'hmr', '_contact.js')
let browser
try {
browser = await webdriver(next.appPort, '/docs/hmr/contact')
browser = await webdriver(next.url, '/docs/hmr/contact')
const text = await browser.elementByCss('p').text()
expect(text).toBe('This is the contact page.')

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('basic HMR', () => {
it('should detect the changes and display it', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/hmr/about')
browser = await webdriver(next.url, '/docs/hmr/about')
const text = await browser.elementByCss('p').text()
expect(text).toBe('This is the about page.')

Expand Down Expand Up @@ -106,7 +106,7 @@ describe('basic HMR', () => {
it('should not reload unrelated pages', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/hmr/counter')
browser = await webdriver(next.url, '/docs/hmr/counter')
const text = await browser
.elementByCss('button')
.click()
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('basic HMR', () => {
it('should update styles correctly', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/hmr/style')
browser = await webdriver(next.url, '/docs/hmr/style')
const pTag = await browser.elementByCss('.hmr-style-page p')
const initialFontSize = await pTag.getComputedCss('font-size')

Expand Down Expand Up @@ -186,7 +186,7 @@ describe('basic HMR', () => {
const originalContent = await next.readFile(pagePath)
try {
browser = await webdriver(
next.appPort,
next.url,
'/docs/hmr/style-stateful-component'
)
const pTag = await browser.elementByCss('.hmr-style-page p')
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('basic HMR', () => {
const originalContent = await next.readFile(pagePath)
try {
browser = await webdriver(
next.appPort,
next.url,
'/docs/hmr/style-dynamic-component'
)
const div = await browser.elementByCss('#dynamic-component')
Expand All @@ -230,7 +230,7 @@ describe('basic HMR', () => {
expect(initialFontSize).toBe('100px')

const initialHtml = await renderViaHTTP(
next.appPort,
next.url,
'/docs/hmr/style-dynamic-component'
)
expect(initialHtml.includes('100px')).toBeTruthy()
Expand All @@ -250,7 +250,7 @@ describe('basic HMR', () => {
await waitFor(5000)

secondBrowser = await webdriver(
next.appPort,
next.url,
'/docs/hmr/style-dynamic-component'
)
// Check whether the this page has reloaded or not.
Expand All @@ -268,7 +268,7 @@ describe('basic HMR', () => {
expect(browserHtml.includes('font-size:100px')).toBe(false)

const editedHtml = await renderViaHTTP(
next.appPort,
next.url,
'/docs/hmr/style-dynamic-component'
)
expect(editedHtml.includes('200px')).toBeTruthy()
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('basic HMR', () => {
const newPage = join('pages', 'hmr', 'new-page.js')

try {
browser = await webdriver(next.appPort, '/docs/hmr/new-page')
browser = await webdriver(next.url, '/docs/hmr/new-page')

expect(await browser.elementByCss('body').text()).toMatch(
/This page could not be found/
Expand Down Expand Up @@ -335,7 +335,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about2')
browser = await webdriver(next.url, '/docs/hmr/about2')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))
Expand Down Expand Up @@ -368,14 +368,14 @@ describe('basic HMR', () => {
const aboutContent = await next.readFile(aboutPage)
let browser
try {
await renderViaHTTP(next.appPort, '/docs/hmr/about2')
await renderViaHTTP(next.url, '/docs/hmr/about2')

await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))

// Ensure dev server has time to break:
await new Promise((resolve) => setTimeout(resolve, 2000))

browser = await webdriver(next.appPort, '/docs/hmr/contact')
browser = await webdriver(next.url, '/docs/hmr/contact')

expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxSource(browser)).toMatch(/Unexpected eof/)
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about3.js')
const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about3')
browser = await webdriver(next.url, '/docs/hmr/about3')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(
Expand All @@ -435,7 +435,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about4.js')
const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about4')
browser = await webdriver(next.url, '/docs/hmr/about4')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about5.js')
const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about5')
browser = await webdriver(next.url, '/docs/hmr/about5')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about6.js')
const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about6')
browser = await webdriver(next.url, '/docs/hmr/about6')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(
Expand Down Expand Up @@ -565,7 +565,7 @@ describe('basic HMR', () => {

const aboutContent = await next.readFile(aboutPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/about7')
browser = await webdriver(next.url, '/docs/hmr/about7')
await check(() => getBrowserBodyText(browser), /This is the about page/)

await next.patchFile(
Expand Down Expand Up @@ -613,7 +613,7 @@ describe('basic HMR', () => {
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr')
browser = await webdriver(next.url, '/docs/hmr')
await browser.elementByCss('#error-in-gip-link').click()

expect(await hasRedbox(browser)).toBe(true)
Expand Down Expand Up @@ -658,7 +658,7 @@ describe('basic HMR', () => {
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
browser = await webdriver(next.appPort, '/docs/hmr/error-in-gip')
browser = await webdriver(next.url, '/docs/hmr/error-in-gip')

expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
Expand Down
12 changes: 6 additions & 6 deletions test/development/basic-basepath/misc.test.ts
Expand Up @@ -22,17 +22,17 @@ describe('misc basic dev tests', () => {
afterAll(() => next.destroy())

it('should set process.env.NODE_ENV in development', async () => {
const browser = await webdriver(next.appPort, '/docs/process-env')
const browser = await webdriver(next.url, '/docs/process-env')
const nodeEnv = await browser.elementByCss('#node-env').text()
expect(nodeEnv).toBe('development')
await browser.close()
})

it('should allow access to public files', async () => {
const data = await renderViaHTTP(next.appPort, '/docs/data/data.txt')
const data = await renderViaHTTP(next.url, '/docs/data/data.txt')
expect(data).toBe('data')

const legacy = await renderViaHTTP(next.appPort, '/docs/static/legacy.txt')
const legacy = await renderViaHTTP(next.url, '/docs/static/legacy.txt')
expect(legacy).toMatch(`new static folder`)
})

Expand All @@ -43,7 +43,7 @@ describe('misc basic dev tests', () => {
`/docs/_next/static/../routes-manifest.json`,
]
for (const path of pathsToCheck) {
const res = await fetchViaHTTP(next.appPort, path)
const res = await fetchViaHTTP(next.url, path)
const text = await res.text()
try {
expect(res.status).toBe(404)
Expand All @@ -56,7 +56,7 @@ describe('misc basic dev tests', () => {

it('should handle encoded / value for trailing slash correctly', async () => {
const res = await fetchViaHTTP(
next.appPort,
next.url,
'/docs/%2fexample.com/',
undefined,
{ redirect: 'manual' }
Expand All @@ -77,7 +77,7 @@ describe('misc basic dev tests', () => {
let foundLog = false
let browser
try {
browser = await webdriver(next.appPort, path)
browser = await webdriver(next.url, path)
const browserLogs = await browser.log('browser')

browserLogs.forEach((log) => {
Expand Down
21 changes: 9 additions & 12 deletions test/development/basic-basepath/next-dynamic.test.ts
Expand Up @@ -22,7 +22,7 @@ describe('basic next/dynamic usage', () => {
afterAll(() => next.destroy())

async function get$(path, query?: any) {
const html = await renderViaHTTP(next.appPort, path, query)
const html = await renderViaHTTP(next.url, path, query)
return cheerio.load(html)
}

Expand All @@ -49,7 +49,7 @@ describe('basic next/dynamic usage', () => {
it('should render even there are no physical chunk exists', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/no-chunk')
browser = await webdriver(next.url, '/docs/dynamic/no-chunk')
await check(
() => browser.elementByCss('body').text(),
/Welcome, normal/
Expand All @@ -68,7 +68,7 @@ describe('basic next/dynamic usage', () => {
it('should hydrate nested chunks', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/nested')
browser = await webdriver(next.url, '/docs/dynamic/nested')
await check(() => browser.elementByCss('body').text(), /Nested 1/)
await check(() => browser.elementByCss('body').text(), /Nested 2/)
await check(
Expand All @@ -95,7 +95,7 @@ describe('basic next/dynamic usage', () => {
it('should render the component Head content', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/head')
browser = await webdriver(next.url, '/docs/dynamic/head')
await check(() => browser.elementByCss('body').text(), /test/)
const backgroundColor = await browser
.elementByCss('.dynamic-style')
Expand All @@ -122,7 +122,7 @@ describe('basic next/dynamic usage', () => {
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/no-ssr')
browser = await webdriver(next.url, '/docs/dynamic/no-ssr')
await check(
() => browser.elementByCss('body').text(),
/Hello World 1/
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('basic next/dynamic usage', () => {
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/ssr-true')
browser = await webdriver(next.url, '/docs/dynamic/ssr-true')
await check(
() => browser.elementByCss('body').text(),
/Hello World 1/
Expand All @@ -177,7 +177,7 @@ describe('basic next/dynamic usage', () => {
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/docs/dynamic/chunkfilename')
browser = await webdriver(next.url, '/docs/dynamic/chunkfilename')
await check(
() => browser.elementByCss('body').text(),
/test chunkfilename/
Expand All @@ -200,7 +200,7 @@ describe('basic next/dynamic usage', () => {
let browser
try {
browser = await webdriver(
next.appPort,
next.url,
'/docs/dynamic/no-ssr-custom-loading'
)
await check(
Expand All @@ -226,10 +226,7 @@ describe('basic next/dynamic usage', () => {
it('should only load the rendered module in the browser', async () => {
let browser
try {
browser = await webdriver(
next.appPort,
'/docs/dynamic/multiple-modules'
)
browser = await webdriver(next.url, '/docs/dynamic/multiple-modules')
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toMatch(/hello1\.js/)
expect(html).not.toMatch(/hello2\.js/)
Expand Down
6 changes: 3 additions & 3 deletions test/development/basic/define-class-fields.test.ts
Expand Up @@ -30,7 +30,7 @@ describe('useDefineForClassFields SWC option', () => {
it('tsx should compile with useDefineForClassFields enabled', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/')
browser = await webdriver(next.url, '/')
await browser.elementByCss('#action').click()
await check(
() => browser.elementByCss('#name').text(),
Expand All @@ -46,7 +46,7 @@ describe('useDefineForClassFields SWC option', () => {
it("Initializes resident to undefined after the call to 'super()' when with useDefineForClassFields enabled", async () => {
let browser
try {
browser = await webdriver(next.appPort, '/animal')
browser = await webdriver(next.url, '/animal')
expect(await browser.elementByCss('#dog').text()).toBe('')
expect(await browser.elementByCss('#dogDecl').text()).toBe('dog')
} finally {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('useDefineForClassFields SWC option', () => {
it('set accessors from base classes won’t get triggered with useDefineForClassFields enabled', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/derived')
browser = await webdriver(next.url, '/derived')
await matchLogs$(browser).then(([data_foundLog, name_foundLog]) => {
expect(data_foundLog).toBe(true)
expect(name_foundLog).toBe(false)
Expand Down
2 changes: 1 addition & 1 deletion test/development/basic/emotion-swc.test.ts
Expand Up @@ -29,7 +29,7 @@ describe('emotion SWC option', () => {
it('should have styling from the css prop', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/')
browser = await webdriver(next.url, '/')
const color = await browser
.elementByCss('#test-element')
.getComputedCss('background-color')
Expand Down

0 comments on commit 19013a5

Please sign in to comment.