Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filesystempublicroutes test for Turbopack #61132

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 7 additions & 4 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,8 @@ function bindingToApi(binding: any, _wasm: boolean) {
nextConfig: NextConfigComplete,
projectPath: string
): Promise<string> {
let nextConfigSerializable = nextConfig as any
// Avoid mutating the existing `nextConfig` object.
let nextConfigSerializable = { ...(nextConfig as any) }

nextConfigSerializable.generateBuildId =
await nextConfig.generateBuildId?.()
Expand Down Expand Up @@ -1091,9 +1092,11 @@ function bindingToApi(binding: any, _wasm: boolean) {
: undefined

// loaderFile is an absolute path, we need it to be relative for turbopack.
if (nextConfig.images.loaderFile) {
nextConfig.images.loaderFile =
'./' + path.relative(projectPath, nextConfig.images.loaderFile)
if (nextConfigSerializable.images.loaderFile) {
nextConfigSerializable.images = {
...nextConfig.images,
loaderFile: path.relative(projectPath, nextConfig.images.loaderFile),
}
}

return JSON.stringify(nextConfigSerializable, null, 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
export default () => <div>exportpathmap was here</div>
import { useEffect } from 'react'
import { useState } from 'react'
export default function ExportPathMapRoute() {
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
})
return (
<div>
<h1>exportpathmap was here</h1>
{mounted ? <div id="page-was-loaded">Hello World</div> : null}
</div>
)
}
29 changes: 8 additions & 21 deletions test/integration/filesystempublicroutes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import { join } from 'path'
import getPort from 'get-port'
import {
fetchViaHTTP,
initNextServerScript,
killApp,
getPageFileFromBuildManifest,
} from 'next-test-utils'
import { fetchViaHTTP, initNextServerScript, killApp } from 'next-test-utils'
import webdriver from 'next-webdriver'

const appDir = join(__dirname, '../')
let appPort
Expand Down Expand Up @@ -40,23 +36,14 @@ describe('FileSystemPublicRoutes', () => {
const res = await fetch('/exportpathmap-route')
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(
process.env.TURBOPACK ? /turbopack/ : /exportpathmap was here/
)
expect(body).toMatch(/exportpathmap was here/)
})

it('should still handle /_next routes', async () => {
await fetch('/exportpathmap-route') // make sure it's built
const pageFile = getPageFileFromBuildManifest(
appDir,
'/exportpathmap-route'
)
const res = await fetch(join('/_next', pageFile))
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(
process.env.TURBOPACK ? /turbopack/ : /exportpathmap was here/
)
it('should serve JavaScript files correctly', async () => {
const browser = await webdriver(context.appPort, '/exportpathmap-route')

const text = await browser.waitForElementByCss('#page-was-loaded').text()
expect(text).toBe('Hello World')
})

it('should route to public folder files', async () => {
Expand Down
7 changes: 3 additions & 4 deletions test/turbopack-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10749,13 +10749,12 @@
},
"test/integration/filesystempublicroutes/test/index.test.js": {
"passed": [
"FileSystemPublicRoutes should not route to the index page",
"FileSystemPublicRoutes should route to exportPathMap defined routes in development",
"FileSystemPublicRoutes should route to public folder files",
"FileSystemPublicRoutes should still handle /_next routes"
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
],
"failed": [
"FileSystemPublicRoutes should not route to the index page",
"FileSystemPublicRoutes should route to exportPathMap defined routes in development"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
Expand Down
Loading