Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
4dfe831b
Unverified
Commit
4dfe831b
authored
Jan 18, 2023
by
JJ Kasper
Committed by
GitHub
Jan 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project directory rename/remove handling (#44911)
parent
d7307cff
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
378 additions
and
44 deletions
+378
-44
next-dev.ts
packages/next/src/cli/next-dev.ts
+200
-22
base-server.ts
packages/next/src/server/base-server.ts
+32
-1
next-dev-server.ts
packages/next/src/server/dev/next-dev-server.ts
+6
-1
ReactRefreshLogBox-scss.test.ts.snap
...ce-app/__snapshots__/ReactRefreshLogBox-scss.test.ts.snap
+1
-1
project-directory-rename.test.ts
test/development/basic/project-directory-rename.test.ts
+68
-0
create-root-layout.test.ts
...e2e/app-dir/create-root-layout/create-root-layout.test.ts
+10
-9
index.test.ts
test/e2e/edge-configurable-runtime/index.test.ts
+5
-4
index.test.js
...integration/edge-runtime-module-errors/test/index.test.js
+2
-2
index.test.ts
...on/next-image-new/invalid-image-import/test/index.test.ts
+3
-2
index.test.ts
test/integration/project-dir-delete/index.test.ts
+49
-0
next-dev.ts
test/lib/next-modes/next-dev.ts
+1
-1
next-start.ts
test/lib/next-modes/next-start.ts
+1
-1
No files found.
packages/next/src/cli/next-dev.ts
View file @
4dfe831b
#!/usr/bin/env node
import
arg
from
'next/dist/compiled/arg/index.js'
import
{
existsSync
,
watchFile
}
from
'fs'
import
{
startServer
}
from
'../server/lib/start-server'
import
{
getPort
,
printAndExit
}
from
'../server/lib/utils'
import
*
as
Log
from
'../build/output/log'
...
...
@@ -18,11 +17,15 @@ import cluster from 'cluster'
import
{
Telemetry
}
from
'../telemetry/storage'
import
loadConfig
from
'../server/config'
import
{
findPagesDir
}
from
'../lib/find-pages-dir'
import
{
fileExists
}
from
'../lib/file-exists'
import
Watchpack
from
'next/dist/compiled/watchpack'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
let
isTurboSession
=
false
let
sessionStopHandled
=
false
let
sessionStarted
=
Date
.
now
()
let
dir
:
string
let
unwatchConfigFiles
:
()
=>
void
const
handleSessionStop
=
async
()
=>
{
if
(
sessionStopHandled
)
return
...
...
@@ -65,14 +68,37 @@ const handleSessionStop = async () => {
true
)
telemetry
.
flushDetached
(
'dev'
,
dir
)
}
catch
(
err
)
{
console
.
error
(
err
)
}
catch
(
_
)
{
// errors here aren't actionable so don't add
// noise to the output
}
process
.
exit
(
0
)
}
process
.
on
(
'SIGINT'
,
handleSessionStop
)
process
.
on
(
'SIGTERM'
,
handleSessionStop
)
if
(
cluster
.
isMaster
)
{
process
.
on
(
'SIGINT'
,
handleSessionStop
)
process
.
on
(
'SIGTERM'
,
handleSessionStop
)
}
else
{
process
.
on
(
'SIGINT'
,
()
=>
process
.
exit
(
0
))
process
.
on
(
'SIGTERM'
,
()
=>
process
.
exit
(
0
))
}
function
watchConfigFiles
(
dirToWatch
:
string
)
{
if
(
unwatchConfigFiles
)
{
unwatchConfigFiles
()
}
const
wp
=
new
Watchpack
()
wp
.
watch
({
files
:
CONFIG_FILES
.
map
((
file
)
=>
path
.
join
(
dirToWatch
,
file
))
})
wp
.
on
(
'change'
,
(
filename
)
=>
{
console
.
log
(
`\n> Found a change in
${
path
.
basename
(
filename
)}
. Restart the server to see the changes in effect.`
)
})
return
()
=>
wp
.
close
()
}
const
nextDev
:
CliCommand
=
async
(
argv
)
=>
{
const
validArgs
:
arg
.
Spec
=
{
...
...
@@ -121,10 +147,11 @@ const nextDev: CliCommand = async (argv) => {
process
.
exit
(
0
)
}
dir
=
getProjectDir
(
args
.
_
[
0
])
dir
=
getProjectDir
(
process
.
env
.
NEXT_PRIVATE_DEV_DIR
||
args
.
_
[
0
])
unwatchConfigFiles
=
watchConfigFiles
(
dir
)
// Check if pages dir exists and warn if not
if
(
!
existsSync
(
dir
))
{
if
(
!
(
await
fileExists
(
dir
,
'directory'
)
))
{
printAndExit
(
`> No such directory exists as the project root:
${
dir
}
`
)
}
...
...
@@ -392,12 +419,173 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
// this is a temporary solution until we can fix the memory leaks.
// the logic for the worker killing itself is in `packages/next/server/lib/start-server.ts`
if
(
!
process
.
env
.
__NEXT_DISABLE_MEMORY_WATCHER
&&
cluster
.
isMaster
)
{
cluster
.
fork
()
cluster
.
on
(
'exit'
,
(
worker
)
=>
{
if
(
worker
.
exitedAfterDisconnect
)
{
cluster
.
fork
()
let
config
:
NextConfig
const
setupFork
=
(
env
?:
Parameters
<
typeof
cluster
.
fork
>
[
0
])
=>
{
const
startDir
=
dir
let
shouldFilter
=
false
cluster
.
fork
({
...
env
,
FORCE_COLOR
:
'1'
,
})
// since errors can start being logged from the fork
// before we detect the project directory rename
// attempt suppressing them long enough to check
const
filterForkErrors
=
(
chunk
:
Buffer
,
fd
:
'stdout'
|
'stderr'
)
=>
{
const
cleanChunk
=
stripAnsi
(
chunk
+
''
)
if
(
cleanChunk
.
match
(
/
(
ENOENT|Module build failed|Module not found|Cannot find module
)
/
)
)
{
if
(
startDir
===
dir
)
{
try
{
// check if start directory is still valid
const
result
=
findPagesDir
(
startDir
,
!!
config
.
experimental
?.
appDir
)
shouldFilter
=
!
Boolean
(
result
.
pagesDir
||
result
.
appDir
)
}
catch
(
_
)
{
shouldFilter
=
true
}
}
if
(
shouldFilter
||
startDir
!==
dir
)
{
shouldFilter
=
true
return
}
}
process
[
fd
].
write
(
chunk
)
}
for
(
const
workerId
in
cluster
.
workers
)
{
cluster
.
workers
[
workerId
]?.
process
.
stdout
?.
on
(
'data'
,
(
chunk
)
=>
{
filterForkErrors
(
chunk
,
'stdout'
)
})
cluster
.
workers
[
workerId
]?.
process
.
stderr
?.
on
(
'data'
,
(
chunk
)
=>
{
filterForkErrors
(
chunk
,
'stderr'
)
})
}
}
const
handleClusterExit
=
()
=>
{
const
callback
=
async
(
worker
:
cluster
.
Worker
)
=>
{
// ignore if we killed the worker
if
((
worker
as
any
).
killed
)
return
// TODO: we should track how many restarts are
// occurring and how long in-between them
if
(
worker
.
exitedAfterDisconnect
)
{
setupFork
()
}
else
if
(
!
sessionStopHandled
)
{
await
handleSessionStop
()
process
.
exit
(
1
)
}
}
cluster
.
addListener
(
'exit'
,
callback
)
return
()
=>
cluster
.
removeListener
(
'exit'
,
callback
)
}
let
clusterExitUnsub
=
handleClusterExit
()
cluster
.
settings
.
stdio
=
[
'ipc'
,
'pipe'
,
'pipe'
]
setupFork
()
config
=
await
loadConfig
(
PHASE_DEVELOPMENT_SERVER
,
dir
)
const
handleProjectDirRename
=
(
newDir
:
string
)
=>
{
clusterExitUnsub
()
for
(
const
workerId
in
cluster
.
workers
)
{
try
{
// @ts-expect-error custom field
cluster
.
workers
[
workerId
].
killed
=
true
cluster
.
workers
[
workerId
]
!
.
process
.
kill
(
'SIGKILL'
)
}
catch
(
_
)
{}
}
process
.
chdir
(
newDir
)
// @ts-expect-error type is incorrect
cluster
.
settings
.
cwd
=
newDir
cluster
.
settings
.
exec
=
cluster
.
settings
.
exec
?.
replace
(
dir
,
newDir
)
setupFork
({
...
Object
.
keys
(
process
.
env
).
reduce
((
newEnv
,
key
)
=>
{
newEnv
[
key
]
=
process
.
env
[
key
]?.
replace
(
dir
,
newDir
)
return
newEnv
},
{}
as
typeof
process
.
env
),
NEXT_PRIVATE_DEV_DIR
:
newDir
,
})
clusterExitUnsub
=
handleClusterExit
()
}
const
parentDir
=
path
.
join
(
'/'
,
dir
,
'..'
)
const
watchedEntryLength
=
parentDir
.
split
(
'/'
).
length
+
1
const
previousItems
=
new
Set
()
const
wp
=
new
Watchpack
({
ignored
:
(
entry
:
string
)
=>
{
// watch only one level
return
!
(
entry
.
split
(
'/'
).
length
<=
watchedEntryLength
)
},
})
wp
.
watch
({
directories
:
[
parentDir
],
startTime
:
0
})
wp
.
on
(
'aggregated'
,
()
=>
{
const
knownFiles
=
wp
.
getTimeInfoEntries
()
const
newFiles
:
string
[]
=
[]
let
hasPagesApp
=
false
// if the dir still exists nothing to check
try
{
const
result
=
findPagesDir
(
dir
,
!!
config
.
experimental
?.
appDir
)
hasPagesApp
=
Boolean
(
result
.
pagesDir
||
result
.
appDir
)
}
catch
(
err
)
{
// if findPagesDir throws validation error let this be
// handled in the dev-server itself in the fork
if
((
err
as
any
).
message
?.
includes
(
'experimental'
))
{
return
}
}
// try to find new dir introduced
if
(
previousItems
.
size
)
{
for
(
const
key
of
knownFiles
.
keys
())
{
if
(
!
previousItems
.
has
(
key
))
{
newFiles
.
push
(
key
)
}
}
previousItems
.
clear
()
}
for
(
const
key
of
knownFiles
.
keys
())
{
previousItems
.
add
(
key
)
}
if
(
hasPagesApp
)
{
return
}
// if we failed to find the new dir it may have been moved
// to a new parent directory which we can't track as easily
// so exit gracefully
try
{
const
result
=
findPagesDir
(
newFiles
[
0
],
!!
config
.
experimental
?.
appDir
)
hasPagesApp
=
Boolean
(
result
.
pagesDir
||
result
.
appDir
)
}
catch
(
_
)
{}
if
(
hasPagesApp
&&
newFiles
.
length
===
1
)
{
Log
.
info
(
`Detected project directory rename, restarting in new location`
)
handleProjectDirRename
(
newFiles
[
0
])
watchConfigFiles
(
newFiles
[
0
])
dir
=
newFiles
[
0
]
}
else
{
process
.
exit
(
1
)
Log
.
error
(
`Project directory could not be found, restart Next.js in your new directory`
)
process
.
exit
(
0
)
}
})
}
else
{
...
...
@@ -440,16 +628,6 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
})
}
}
for
(
const
CONFIG_FILE
of
CONFIG_FILES
)
{
watchFile
(
path
.
join
(
dir
,
CONFIG_FILE
),
(
cur
:
any
,
prev
:
any
)
=>
{
if
(
cur
.
size
>
0
||
prev
.
size
>
0
)
{
console
.
log
(
`\n> Found a change in
${
CONFIG_FILE
}
. Restart the server to see the changes in effect.`
)
}
})
}
}
export
{
nextDev
}
packages/next/src/server/base-server.ts
View file @
4dfe831b
...
...
@@ -1924,6 +1924,37 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this
.
customErrorNo404Warn
()
}
if
(
!
result
)
{
// this can occur when a project directory has been moved/deleted
// which is handled in the parent process in development
if
(
this
.
renderOpts
.
dev
)
{
return
{
type
:
'html'
,
// wait for dev-server to restart before refreshing
body
:
RenderResult
.
fromStatic
(
`
<pre>missing required error components, refreshing...</pre>
<script>
async function check() {
const res = await fetch(location.href).catch(() => ({}))
if (res.status === 200) {
location.reload()
} else {
setTimeout(check, 1000)
}
}
check()
</script>`
),
}
}
throw
new
WrappedBuildError
(
new
Error
(
'missing required error components'
)
)
}
try
{
return
await
this
.
renderToResponseWithComponents
(
{
...
...
@@ -1934,7 +1965,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
err
,
},
},
result
!
result
)
}
catch
(
maybeFallbackError
)
{
if
(
maybeFallbackError
instanceof
NoFallbackError
)
{
...
...
packages/next/src/server/dev/next-dev-server.ts
View file @
4dfe831b
...
...
@@ -1443,7 +1443,12 @@ export default class DevServer extends Server {
// patched global in memory, creating a memory leak.
this
.
restorePatchedGlobals
()
return
super
.
findPageComponents
({
pathname
,
query
,
params
,
isAppPath
})
return
await
super
.
findPageComponents
({
pathname
,
query
,
params
,
isAppPath
,
})
}
catch
(
err
)
{
if
((
err
as
any
).
code
!==
'ENOENT'
)
{
throw
err
...
...
test/development/acceptance-app/__snapshots__/ReactRefreshLogBox-scss.test.ts.snap
View file @
4dfe831b
...
...
@@ -20,5 +20,5 @@ exports[`ReactRefreshLogBox app scss syntax errors 2`] = `
Syntax error: Selector \\"button\\" is not pure (pure selectors must contain at least one local class or id)
> 1 | button { font-size: 5px; }
| ^"
|
^"
`;
test/development/basic/project-directory-rename.test.ts
0 → 100644
View file @
4dfe831b
import
fs
from
'fs-extra'
import
webdriver
from
'next-webdriver'
import
{
check
,
findPort
,
hasRedbox
}
from
'next-test-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
createNext
}
from
'e2e-utils'
import
stripAnsi
from
'strip-ansi'
describe
(
'Project Directory Renaming'
,
()
=>
{
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
'pages/index.js'
:
`
export default function Page() {
return <p>hello world</p>
}
`
,
},
skipStart
:
true
,
})
next
.
forcedPort
=
(
await
findPort
())
+
''
await
next
.
start
()
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should detect project dir rename and restart'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
await
browser
.
eval
(
'window.beforeNav = 1'
)
let
newTestDir
=
`
${
next
.
testDir
}
-renamed`
await
fs
.
move
(
next
.
testDir
,
newTestDir
)
next
.
testDir
=
newTestDir
await
check
(
()
=>
stripAnsi
(
next
.
cliOutput
),
/Detected project directory rename, restarting in new location/
)
await
check
(
async
()
=>
{
return
(
await
browser
.
eval
(
'window.beforeNav'
))
===
1
?
'pending'
:
'done'
},
'done'
)
expect
(
await
hasRedbox
(
browser
,
false
)).
toBe
(
false
)
try
{
// should still HMR correctly
await
next
.
patchFile
(
'pages/index.js'
,
(
await
next
.
readFile
(
'pages/index.js'
)
).
replace
(
'hello world'
,
'hello again'
)
)
await
check
(
async
()
=>
{
if
(
!
(
await
browser
.
eval
(
'!!window.next'
)))
{
await
browser
.
refresh
()
}
return
browser
.
eval
(
'document.documentElement.innerHTML'
)
},
/hello again/
)
}
finally
{
await
next
.
patchFile
(
'pages/index.js'
,
(
await
next
.
readFile
(
'pages/index.js'
)
).
replace
(
'hello again'
,
'hello world'
)
)
}
})
})
test/e2e/app-dir/create-root-layout/create-root-layout.test.ts
View file @
4dfe831b
...
...
@@ -2,6 +2,7 @@ import path from 'path'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
check
}
from
'next-test-utils'
import
stripAnsi
from
'strip-ansi'
describe
(
'app-dir create root layout'
,
()
=>
{
const
isDev
=
(
global
as
any
).
isNextDev
...
...
@@ -41,10 +42,10 @@ describe('app-dir create root layout', () => {
)
await
check
(
()
=>
next
.
cliOutput
.
slice
(
outputIndex
),
()
=>
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
),
/did not have a root layout/
)
expect
(
next
.
cliOutput
.
slice
(
outputIndex
)).
toMatch
(
expect
(
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
)).
toMatch
(
'Your page app/route/page.js did not have a root layout. We created app/layout.js and app/head.js for you.'
)
...
...
@@ -101,10 +102,10 @@ describe('app-dir create root layout', () => {
)
await
check
(
()
=>
next
.
cliOutput
.
slice
(
outputIndex
),
()
=>
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
),
/did not have a root layout/
)
expect
(
next
.
cliOutput
.
slice
(
outputIndex
)).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
)).
toInclude
(
'Your page app/(group)/page.js did not have a root layout. We created app/(group)/layout.js and app/(group)/head.js for you.'
)
...
...
@@ -163,10 +164,10 @@ describe('app-dir create root layout', () => {
)
await
check
(
()
=>
next
.
cliOutput
.
slice
(
outputIndex
),
()
=>
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
),
/did not have a root layout/
)
expect
(
next
.
cliOutput
.
slice
(
outputIndex
)).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
)).
toInclude
(
'Your page app/(group)/route/second/inner/page.js did not have a root layout. We created app/(group)/route/second/layout.js and app/(group)/route/second/head.js for you.'
)
...
...
@@ -224,10 +225,10 @@ describe('app-dir create root layout', () => {
)
await
check
(
()
=>
next
.
cliOutput
.
slice
(
outputIndex
),
()
=>
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
),
/did not have a root layout/
)
expect
(
next
.
cliOutput
.
slice
(
outputIndex
)).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
.
slice
(
outputIndex
)
)).
toInclude
(
'Your page app/page.tsx did not have a root layout. We created app/layout.tsx and app/head.tsx for you.'
)
...
...
@@ -281,7 +282,7 @@ describe('app-dir create root layout', () => {
})
await
expect
(
next
.
start
()).
rejects
.
toThrow
(
'next build failed'
)
expect
(
next
.
cliOutput
).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
)
).
toInclude
(
"page.js doesn't have a root layout. To fix this error, make sure every page has a root layout."
)
await
next
.
destroy
()
...
...
test/e2e/edge-configurable-runtime/index.test.ts
View file @
4dfe831b
...
...
@@ -2,6 +2,7 @@ import { createNext, FileRef } from 'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
,
File
,
nextBuild
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
stripAnsi
from
'strip-ansi'
const
appDir
=
join
(
__dirname
,
'./app'
)
const
pagePath
=
'pages/index.jsx'
...
...
@@ -50,7 +51,7 @@ describe('Configurable runtime for pages and API routes', () => {
const
res
=
await
fetchViaHTTP
(
next
.
url
,
`/api/edge`
)
expect
(
res
.
status
).
toEqual
(
200
)
expect
(
next
.
cliOutput
).
not
.
toInclude
(
'error'
)
expect
(
next
.
cliOutput
).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
)
).
toInclude
(
`warn - /pages/api/edge provided runtime 'experimental-edge'. It can be updated to 'edge' instead.`
)
})
...
...
@@ -66,7 +67,7 @@ describe('Configurable runtime for pages and API routes', () => {
const
res
=
await
fetchViaHTTP
(
next
.
url
,
`/`
)
expect
(
res
.
status
).
toEqual
(
200
)
expect
(
next
.
cliOutput
).
not
.
toInclude
(
'error'
)
expect
(
next
.
cliOutput
).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
)
).
toInclude
(
`warn - You are using an experimental edge runtime, the API might change.`
)
})
...
...
@@ -82,7 +83,7 @@ describe('Configurable runtime for pages and API routes', () => {
await
next
.
start
()
const
res
=
await
fetchViaHTTP
(
next
.
url
,
`/`
)
expect
(
res
.
status
).
toEqual
(
200
)
expect
(
next
.
cliOutput
).
toInclude
(
expect
(
stripAnsi
(
next
.
cliOutput
)
).
toInclude
(
`error - Page /pages provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
)
expect
(
next
.
cliOutput
).
not
.
toInclude
(
'warn'
)
...
...
@@ -121,7 +122,7 @@ describe('Configurable runtime for pages and API routes', () => {
})
expect
(
output
.
code
).
toBe
(
1
)
expect
(
output
.
stderr
).
not
.
toContain
(
`Build failed`
)
expect
(
output
.
stderr
).
toContain
(
expect
(
stripAnsi
(
output
.
stderr
)
).
toContain
(
`Error: Page / provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
)
})
...
...
test/integration/edge-runtime-module-errors/test/index.test.js
View file @
4dfe831b
...
...
@@ -656,9 +656,9 @@ function expectModuleNotFoundProdError(
output
=
context
.
logs
.
output
)
{
const
moduleNotSupportedMessage
=
getUnsupportedModule
(
moduleName
)
expect
(
output
).
not
.
toContain
(
moduleNotSupportedMessage
)
expect
(
stripAnsi
(
output
)
).
not
.
toContain
(
moduleNotSupportedMessage
)
const
moduleNotFoundMessage
=
getModuleNotFound
(
moduleName
)
expect
(
output
).
toContain
(
moduleNotFoundMessage
)
expect
(
stripAnsi
(
output
)
).
toContain
(
moduleNotFoundMessage
)
}
function
expectModuleNotFoundDevError
(
...
...
test/integration/next-image-new/invalid-image-import/test/index.test.ts
View file @
4dfe831b
...
...
@@ -11,6 +11,7 @@ import {
nextBuild
,
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
stripAnsi
from
'strip-ansi'
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
:
number
...
...
@@ -26,9 +27,9 @@ function runTests({ isDev }) {
expect
(
await
hasRedbox
(
browser
,
true
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toBe
(
'Failed to compile'
)
expect
(
await
getRedboxSource
(
browser
)).
toBe
(
`./pages/index.js:3\n
${
msg
}
`
)
expect
(
st
derr
).
toContain
(
msg
)
expect
(
st
ripAnsi
(
stderr
)
).
toContain
(
msg
)
}
else
{
expect
(
st
derr
).
toContain
(
msg
)
expect
(
st
ripAnsi
(
stderr
)
).
toContain
(
msg
)
}
})
}
...
...
test/integration/project-dir-delete/index.test.ts
0 → 100644
View file @
4dfe831b
import
{
check
,
findPort
,
killApp
,
launchApp
,
renderViaHTTP
,
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
fs
from
'fs-extra'
import
stripAnsi
from
'strip-ansi'
describe
(
'Project Directory Delete Handling'
,
()
=>
{
it
(
'should gracefully exit on project dir delete'
,
async
()
=>
{
const
appDir
=
join
(
__dirname
,
'app'
)
const
appPort
=
await
findPort
()
await
fs
.
ensureDir
(
join
(
appDir
,
'pages'
))
await
fs
.
writeFile
(
join
(
appDir
,
'pages'
,
'index.js'
),
`
export default function Page() {
return <p>hello world</p>
}
`
)
let
output
=
''
const
app
=
await
launchApp
(
appDir
,
appPort
,
{
onStdout
(
msg
)
{
output
+=
msg
},
onStderr
(
msg
)
{
output
+=
msg
},
})
expect
(
await
renderViaHTTP
(
appPort
,
'/'
)).
toContain
(
'hello world'
)
await
fs
.
remove
(
appDir
)
await
check
(
()
=>
stripAnsi
(
output
),
/Project directory could not be found, restart Next
\.
js in your new directory/
)
try
{
await
killApp
(
app
)
}
catch
(
_
)
{}
})
})
test/lib/next-modes/next-dev.ts
View file @
4dfe831b
...
...
@@ -70,7 +70,7 @@ export class NextDevInstance extends NextInstance {
this
.
childProcess
.
on
(
'close'
,
(
code
,
signal
)
=>
{
if
(
this
.
isStopping
)
return
if
(
code
||
signal
)
{
throw
new
E
rror
(
require
(
'console'
).
e
rror
(
`next dev exited unexpectedly with code/signal
${
code
||
signal
}
`
)
}
...
...
test/lib/next-modes/next-start.ts
View file @
4dfe831b
...
...
@@ -110,7 +110,7 @@ export class NextStartInstance extends NextInstance {
this
.
childProcess
.
on
(
'close'
,
(
code
,
signal
)
=>
{
if
(
this
.
isStopping
)
return
if
(
code
||
signal
)
{
throw
new
E
rror
(
require
(
'console'
).
e
rror
(
`next start exited unexpectedly with code/signal
${
code
||
signal
}
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment