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
a7b046d9
Unverified
Commit
a7b046d9
authored
Jan 03, 2023
by
Jan Kaifer
Committed by
GitHub
Jan 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache package lock when running tests to speed up installation (#44520)
parent
b6530bb3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
28 deletions
+87
-28
repo-setup.js
.github/actions/next-stats-action/src/prepare/repo-setup.js
+3
-3
basic.test.ts
test/e2e/test-utils-tests/basic/basic.test.ts
+12
-17
create-next-install.js
test/lib/create-next-install.js
+72
-8
No files found.
.github/actions/next-stats-action/src/prepare/repo-setup.js
View file @
a7b046d9
...
...
@@ -84,7 +84,7 @@ module.exports = (actionInfo) => {
pkgs
=
await
fs
.
readdir
(
path
.
join
(
repoDir
,
'packages'
))
}
catch
(
err
)
{
if
(
err
.
code
===
'ENOENT'
)
{
console
.
log
(
'no packages to link'
)
require
(
'console'
)
.
log
(
'no packages to link'
)
return
pkgPaths
}
throw
err
...
...
@@ -105,7 +105,7 @@ module.exports = (actionInfo) => {
const
pkgDataPath
=
path
.
join
(
pkgPath
,
'package.json'
)
if
(
!
fs
.
existsSync
(
pkgDataPath
))
{
console
.
log
(
`Skipping
${
pkgDataPath
}
`
)
require
(
'console'
)
.
log
(
`Skipping
${
pkgDataPath
}
`
)
continue
}
const
pkgData
=
require
(
pkgDataPath
)
...
...
@@ -137,7 +137,7 @@ module.exports = (actionInfo) => {
pkgData
.
files
=
[]
}
pkgData
.
files
.
push
(
'native'
)
console
.
log
(
require
(
'console'
)
.
log
(
'using swc binaries: '
,
await
exec
(
`ls
${
path
.
join
(
path
.
dirname
(
pkgDataPath
),
'native'
)}
`
...
...
test/e2e/test-utils-tests/basic/basic.test.ts
View file @
a7b046d9
import
{
createNext
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
fetchViaHTTP
}
from
'next-test-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
describe
(
'createNext'
,
()
=>
{
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
__dirname
,
createNextDescribe
(
'createNextDescribe'
,
{
files
:
__dirname
,
},
({
next
})
=>
{
it
(
'should work'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/'
)
expect
(
await
res
.
text
()).
toContain
(
'Hello World'
)
})
})
afterAll
(()
=>
next
.
destroy
())
it
(
'should work'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
expect
(
await
res
.
text
()).
toContain
(
'Hello World'
)
})
})
}
)
test/lib/create-next-install.js
View file @
a7b046d9
...
...
@@ -7,6 +7,24 @@ const { randomBytes } = require('crypto')
const
{
linkPackages
}
=
require
(
'../../.github/actions/next-stats-action/src/prepare/repo-setup'
)()
/**
* These are simple dependencies provided by default. We want to optimize this special case.
*/
const
areGenericDependencies
=
(
dependencies
)
=>
Object
.
keys
(
dependencies
).
length
===
6
&&
Object
.
entries
(
dependencies
).
every
(([
dep
,
version
])
=>
{
if
(
dep
===
'next'
)
return
true
return
(
[
'react'
,
'react-dom'
,
'typescript'
,
'@types/react'
,
'@types/node'
,
].
includes
(
dep
)
&&
version
===
'latest'
)
})
async
function
createNextInstall
({
parentSpan
,
dependencies
,
...
...
@@ -29,6 +47,10 @@ async function createNextInstall({
`next-repo-
${
randomBytes
(
32
).
toString
(
'hex'
)}${
dirSuffix
}
`
)
require
(
'console'
).
log
(
'Using following temporary directories:'
)
require
(
'console'
).
log
(
installDir
)
require
(
'console'
).
log
(
tmpRepoDir
)
await
rootSpan
.
traceChild
(
' enruse swc binary'
).
traceAsyncFn
(
async
()
=>
{
// ensure swc binary is present in the native folder if
// not already built
...
...
@@ -137,15 +159,57 @@ async function createNextInstall({
await
rootSpan
.
traceChild
(
'run generic install command'
)
.
traceAsyncFn
(
async
()
=>
{
await
execa
(
'pnpm'
,
[
'install'
,
'--strict-peer-dependencies=false'
],
{
cwd
:
installDir
,
stdio
:
[
'ignore'
,
'inherit'
,
'inherit'
],
env
:
process
.
env
,
const
runInstall
=
async
()
=>
await
execa
(
'pnpm'
,
[
'install'
,
'--strict-peer-dependencies=false'
],
{
cwd
:
installDir
,
stdio
:
[
'ignore'
,
'inherit'
,
'inherit'
],
env
:
process
.
env
,
}
)
if
(
!
areGenericDependencies
(
combinedDependencies
))
{
await
runInstall
()
}
else
{
const
cacheDir
=
path
.
join
(
origRepoDir
,
'test'
,
'tmp'
,
'genericInstallCache'
)
const
cachedFiles
=
[
// We can't cache node-modules because .pnpm store must be on the same mount - we can't move it between mountpoints
// 'node_modules',
'pnpm-lock.yaml'
,
]
if
(
await
fs
.
access
(
cacheDir
)
.
then
(()
=>
true
)
.
catch
(()
=>
false
)
)
{
require
(
'console'
).
log
(
'We are able to prepopulate pnpm install from cache'
)
cachedFiles
.
forEach
((
file
)
=>
{
fs
.
copy
(
path
.
join
(
cacheDir
,
file
),
path
.
join
(
installDir
,
file
)
)
})
}
)
await
runInstall
()
await
fs
.
ensureDir
(
cacheDir
)
cachedFiles
.
forEach
((
file
)
=>
{
fs
.
copy
(
path
.
join
(
installDir
,
file
),
path
.
join
(
cacheDir
,
file
))
})
}
})
}
...
...
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