Skip to content

Commit 71efc03

Browse files
authored
Support Prefer Offline for testing (vercel#44935)
1 parent d45d0f9 commit 71efc03

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

contributing/core/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Some test-specific environment variables can be used to help debug isolated test
7272
- When investigating failures in isolated tests you can use `NEXT_TEST_SKIP_CLEANUP=1` to prevent deleting the temp folder created for the test, then you can run `pnpm next` while inside of the temp folder to debug the fully set-up test project.
7373
- You can also use `NEXT_SKIP_ISOLATE=1` if the test doesn't need to be installed to debug and it will run inside of the Next.js repo instead of the temp directory, this can also reduce test times locally but is not compatible with all tests.
7474
- The `NEXT_TEST_MODE` env variable allows toggling specific test modes for the `e2e` folder, it can be used when not using `pnpm test-dev` or `pnpm test-start` directly. Valid test modes can be seen here: https://github.com/vercel/next.js/blob/aa664868c102ddc5adc618415162d124503ad12e/test/lib/e2e-utils.ts#L46
75+
- You can use `NEXT_TEST_PREFER_OFFLINE=1` while testing to configure the package manager to include the [`--prefer-offline`](https://pnpm.io/cli/install#--prefer-offline) argument during test setup. This is helpful when running tests in internet restricted environments such as planes or public wifi.
7576

7677
### Debugging
7778

test/lib/create-next-install.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,19 @@ async function createNextInstall({
159159
await rootSpan
160160
.traceChild('run generic install command')
161161
.traceAsyncFn(async () => {
162-
const runInstall = async () =>
163-
await execa(
164-
'pnpm',
165-
['install', '--strict-peer-dependencies=false'],
166-
{
167-
cwd: installDir,
168-
stdio: ['ignore', 'inherit', 'inherit'],
169-
env: process.env,
170-
}
171-
)
162+
const runInstall = async () => {
163+
const args = ['install', '--strict-peer-dependencies=false']
164+
165+
if (process.env.NEXT_TEST_PREFER_OFFLINE === '1') {
166+
args.push('--prefer-offline')
167+
}
168+
169+
return await execa('pnpm', args, {
170+
cwd: installDir,
171+
stdio: ['ignore', 'inherit', 'inherit'],
172+
env: process.env,
173+
})
174+
}
172175

173176
if (!areGenericDependencies(combinedDependencies)) {
174177
await runInstall()

0 commit comments

Comments
 (0)