Skip to content

Commit

Permalink
Support Prefer Offline for testing (#44935)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh authored Jan 16, 2023
1 parent d45d0f9 commit 71efc03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions contributing/core/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Some test-specific environment variables can be used to help debug isolated test
- 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.
- 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.
- 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
- 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.

### Debugging

Expand Down
23 changes: 13 additions & 10 deletions test/lib/create-next-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,19 @@ async function createNextInstall({
await rootSpan
.traceChild('run generic install command')
.traceAsyncFn(async () => {
const runInstall = async () =>
await execa(
'pnpm',
['install', '--strict-peer-dependencies=false'],
{
cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'],
env: process.env,
}
)
const runInstall = async () => {
const args = ['install', '--strict-peer-dependencies=false']

if (process.env.NEXT_TEST_PREFER_OFFLINE === '1') {
args.push('--prefer-offline')
}

return await execa('pnpm', args, {
cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'],
env: process.env,
})
}

if (!areGenericDependencies(combinedDependencies)) {
await runInstall()
Expand Down

0 comments on commit 71efc03

Please sign in to comment.