Skip to content

Commit

Permalink
Add additional file serving tests (vercel#12479)
Browse files Browse the repository at this point in the history
* Test `static/` file name encoding

* Fix `static/` file name encoding

* Add additional file-serving tests

* bump

Co-authored-by: Joe Haddad <[email protected]>
  • Loading branch information
ijjk and Timer authored May 4, 2020
1 parent 3af0fe5 commit 00d930a
Show file tree
Hide file tree
Showing 10 changed files with 4,502 additions and 3 deletions.
14 changes: 13 additions & 1 deletion packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,21 @@ export default class DevServer extends Server {
}

protected async hasPage(pathname: string): Promise<boolean> {
let normalizedPath: string

try {
normalizedPath = normalizePagePath(pathname)
} catch (err) {
console.error(err)
// if normalizing the page fails it means it isn't valid
// so it doesn't exist so don't throw and return false
// to ensure we return 404 instead of 500
return false
}

const pageFile = await findPageFile(
this.pagesDir!,
normalizePagePath(pathname),
normalizedPath,
this.nextConfig.pageExtensions
)
return !!pageFile
Expand Down
1 change: 1 addition & 0 deletions test-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is used for traverse testing
1 change: 1 addition & 0 deletions test/integration/file-serving/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'hi'
1 change: 1 addition & 0 deletions test/integration/file-serving/public/hello world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
1 change: 1 addition & 0 deletions test/integration/file-serving/static/hello world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
1 change: 1 addition & 0 deletions test/integration/file-serving/test-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is used for traverse testing
Loading

0 comments on commit 00d930a

Please sign in to comment.