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
ab0b2cf3
Unverified
Commit
ab0b2cf3
authored
Jul 09, 2019
by
Joe Haddad
Committed by
GitHub
Jul 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for module.exports from a page (#7842)
Closes
https://github.com/zeit/next.js/issues/7835
parent
c650dca3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
2 deletions
+66
-2
utils.ts
packages/next/build/utils.ts
+2
-2
[post].js
test/integration/auto-export/pages/[post].js
+7
-0
commonjs1.js
test/integration/auto-export/pages/commonjs1.js
+9
-0
commonjs2.js
test/integration/auto-export/pages/commonjs2.js
+3
-0
index.test.js
test/integration/auto-export/test/index.test.js
+45
-0
No files found.
packages/next/build/utils.ts
View file @
ab0b2cf3
...
@@ -269,7 +269,7 @@ export function isPageStatic(
...
@@ -269,7 +269,7 @@ export function isPageStatic(
try
{
try
{
require
(
'next-server/config'
).
setConfig
(
runtimeEnvConfig
)
require
(
'next-server/config'
).
setConfig
(
runtimeEnvConfig
)
const
mod
=
require
(
serverBundle
)
const
mod
=
require
(
serverBundle
)
const
Comp
=
mod
.
default
const
Comp
=
mod
.
default
||
mod
if
(
!
Comp
||
!
isValidElementType
(
Comp
)
||
typeof
Comp
===
'string'
)
{
if
(
!
Comp
||
!
isValidElementType
(
Comp
)
||
typeof
Comp
===
'string'
)
{
throw
new
Error
(
'INVALID_DEFAULT_EXPORT'
)
throw
new
Error
(
'INVALID_DEFAULT_EXPORT'
)
...
@@ -293,7 +293,7 @@ export function hasCustomAppGetInitialProps(
...
@@ -293,7 +293,7 @@ export function hasCustomAppGetInitialProps(
let
mod
=
require
(
_appBundle
)
let
mod
=
require
(
_appBundle
)
if
(
_appBundle
.
endsWith
(
'_app.js'
))
{
if
(
_appBundle
.
endsWith
(
'_app.js'
))
{
mod
=
mod
.
default
mod
=
mod
.
default
||
mod
}
else
{
}
else
{
// since we don't output _app in serverless mode get it from a page
// since we don't output _app in serverless mode get it from a page
mod
=
mod
.
_app
mod
=
mod
.
_app
...
...
test/integration/auto-export/pages/[post].js
0 → 100644
View file @
ab0b2cf3
import
{
useRouter
}
from
'next/router'
export
default
()
=>
{
const
{
query
}
=
useRouter
()
return
<
p
>
post
:
{
query
.
post
}
<
/p
>
}
test/integration/auto-export/pages/commonjs1.js
0 → 100644
View file @
ab0b2cf3
const
React
=
require
(
'react'
)
module
.
exports
=
function
()
{
return
(
<
div
>
<
h1
>
test1
<
/h1
>
<
/div
>
)
}
test/integration/auto-export/pages/commonjs2.js
0 → 100644
View file @
ab0b2cf3
const
React
=
require
(
'react'
)
module
.
exports
=
()
=>
<
div
>
test2
<
/div
>
test/integration/auto-export/test/index.test.js
0 → 100644
View file @
ab0b2cf3
/* eslint-env jest */
/* global jasmine */
import
webdriver
from
'next-webdriver'
import
path
from
'path'
import
{
nextBuild
,
nextStart
,
findPort
,
killApp
}
from
'next-test-utils'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
1
const
appDir
=
path
.
join
(
__dirname
,
'..'
)
let
appPort
let
app
describe
(
'Auto Export'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
it
(
'Supports commonjs 1'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/commonjs1'
)
const
html
=
await
browser
.
eval
(
'document.body.innerHTML'
)
expect
(
html
).
toMatch
(
/test1/
)
expect
(
html
).
toMatch
(
/nextExport/
)
await
browser
.
close
()
})
it
(
'Supports commonjs 2'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/commonjs2'
)
const
html
=
await
browser
.
eval
(
'document.body.innerHTML'
)
expect
(
html
).
toMatch
(
/test2/
)
expect
(
html
).
toMatch
(
/nextExport/
)
await
browser
.
close
()
})
it
(
'Refreshes query on mount'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/post-1'
)
const
html
=
await
browser
.
eval
(
'document.body.innerHTML'
)
expect
(
html
).
toMatch
(
/post.*post-1/
)
expect
(
html
).
toMatch
(
/nextExport/
)
})
afterAll
(
async
()
=>
{
await
killApp
(
app
)
})
})
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