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
9d25194e
Unverified
Commit
9d25194e
authored
May 07, 2021
by
JJ Kasper
Committed by
GitHub
May 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure next/dynamic transpiles for tests (#24751)
Co-authored-by:
Tobias Koppers
<
tobias.koppers@googlemail.com
>
parent
4e8fac93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
9 deletions
+39
-9
react-loadable-plugin.ts
packages/next/build/babel/plugins/react-loadable-plugin.ts
+6
-4
next-babel-loader.unit.test.js
test/unit/next-babel-loader.unit.test.js
+33
-5
No files found.
packages/next/build/babel/plugins/react-loadable-plugin.ts
View file @
9d25194e
...
@@ -151,10 +151,12 @@ export default function ({
...
@@ -151,10 +151,12 @@ export default function ({
t
.
binaryExpression
(
t
.
binaryExpression
(
'+'
,
'+'
,
t
.
stringLiteral
(
t
.
stringLiteral
(
relativePath
(
(
state
.
file
.
opts
.
caller
.
pagesDir
state
.
file
.
opts
.
caller
.
pagesDir
,
?
relativePath
(
state
.
file
.
opts
.
filename
state
.
file
.
opts
.
caller
.
pagesDir
,
)
+
' -> '
state
.
file
.
opts
.
filename
)
:
state
.
file
.
opts
.
filename
)
+
' -> '
),
),
node
node
)
)
...
...
test/unit/next-babel-loader.unit.test.js
View file @
9d25194e
...
@@ -11,10 +11,13 @@ const path = require('path')
...
@@ -11,10 +11,13 @@ const path = require('path')
const
dir
=
path
.
resolve
(
os
.
tmpdir
())
const
dir
=
path
.
resolve
(
os
.
tmpdir
())
const
babel
=
async
(
const
babel
=
async
(
code
,
queryOpts
=
{})
=>
{
code
,
const
{
{
isServer
=
false
,
resourcePath
=
'index.js'
,
development
=
false
}
=
{}
isServer
=
false
,
)
=>
{
resourcePath
=
'index.js'
,
development
=
false
,
}
=
queryOpts
let
isAsync
=
false
let
isAsync
=
false
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
function
callback
(
err
,
content
)
{
function
callback
(
err
,
content
)
{
...
@@ -47,7 +50,10 @@ const babel = async (
...
@@ -47,7 +50,10 @@ const babel = async (
cwd
:
dir
,
cwd
:
dir
,
isServer
,
isServer
,
distDir
:
path
.
resolve
(
dir
,
'.next'
),
distDir
:
path
.
resolve
(
dir
,
'.next'
),
pagesDir
:
path
.
resolve
(
dir
,
'pages'
),
pagesDir
:
'pagesDir'
in
queryOpts
?
queryOpts
.
pagesDir
:
path
.
resolve
(
dir
,
'pages'
),
cache
:
false
,
cache
:
false
,
development
,
development
,
hasReactRefresh
:
Boolean
(
!
isServer
&&
development
),
hasReactRefresh
:
Boolean
(
!
isServer
&&
development
),
...
@@ -196,6 +202,28 @@ describe('next-babel-loader', () => {
...
@@ -196,6 +202,28 @@ describe('next-babel-loader', () => {
expect
(
code
).
toMatchInlineSnapshot
(
`"if(false){}"`
)
expect
(
code
).
toMatchInlineSnapshot
(
`"if(false){}"`
)
})
})
it
(
'should handle no pagesDir'
,
async
()
=>
{
const
code
=
await
babel
(
`
import dynamic from 'next/dynamic'
const Comp = dynamic(() => import('comp'))
export default function Page(props) {
return <Comp />
}
`
,
{
pagesDir
:
undefined
,
}
)
expect
(
code
.
replace
(
/modules:
\[
".*
?
"/
,
'modules:["/path/to/page"'
)
).
toMatchInlineSnapshot
(
`"import React from\\"react\\";var __jsx=React.createElement;import dynamic from'next/dynamic';var Comp=dynamic(function(){return import('comp');},{loadableGenerated:{webpack:function webpack(){return[require.resolveWeak('comp')];},modules:[\\"/path/to/page\\"+'comp']}});export default function Page(props){return __jsx(Comp,null);}"`
)
})
it
(
'should not drop unused exports by default'
,
async
()
=>
{
it
(
'should not drop unused exports by default'
,
async
()
=>
{
const
code
=
await
babel
(
const
code
=
await
babel
(
// effectful
// effectful
...
...
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