Add additional file serving tests (#12479)

* Test `static/` file name encoding

* Fix `static/` file name encoding

* Add additional file-serving tests

* bump

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
This commit is contained in:
JJ Kasper 2020-05-04 11:58:19 -05:00 committed by GitHub
parent 3af0fe5cf2
commit 00d930aae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 4502 additions and 3 deletions

View file

@ -272,9 +272,21 @@ export default class DevServer extends Server {
} }
protected async hasPage(pathname: string): Promise<boolean> { 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( const pageFile = await findPageFile(
this.pagesDir!, this.pagesDir!,
normalizePagePath(pathname), normalizedPath,
this.nextConfig.pageExtensions this.nextConfig.pageExtensions
) )
return !!pageFile return !!pageFile

1
test-file.txt Normal file
View file

@ -0,0 +1 @@
this is used for traverse testing

View file

@ -0,0 +1 @@
export default () => 'hi'

View file

@ -0,0 +1 @@
hi

View file

@ -0,0 +1 @@
hi

View file

@ -0,0 +1 @@
this is used for traverse testing

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
this is used for traverse testing

View file

@ -172,7 +172,10 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
if (typeof opts.onStdout === 'function') { if (typeof opts.onStdout === 'function') {
opts.onStdout(message) opts.onStdout(message)
} }
process.stdout.write(message)
if (opts.stdout !== false) {
process.stdout.write(message)
}
} }
function handleStderr(data) { function handleStderr(data) {
@ -180,7 +183,10 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
if (typeof opts.onStderr === 'function') { if (typeof opts.onStderr === 'function') {
opts.onStderr(message) opts.onStderr(message)
} }
process.stderr.write(message)
if (opts.stderr !== false) {
process.stderr.write(message)
}
} }
instance.stdout.on('data', handleStdout) instance.stdout.on('data', handleStdout)

1
test/test-file.txt Normal file
View file

@ -0,0 +1 @@
this is used for traverse testing