Unverified Commit 61384522 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[test]: add ability to run test-deploy with pre-existing deployment (#88829)

When digging into failing deployment tests, I often will re-run the test
itself without wanting to change anything about Next.js or the test
application, especially when I suspect a logic bug in the test itself or
need to figure out what's causing a flake.

This adds an environment variable that can be used to skip the
build/deploy step and will use an existing deployment URL to run the
tests against.

I suggest reviewing this [without
whitespace](https://github.com/vercel/next.js/pull/88829/changes?w=1).
parent d2ea7d32
...@@ -92,6 +92,8 @@ these can be leveraged by prefixing the `pnpm test` command. ...@@ -92,6 +92,8 @@ these can be leveraged by prefixing the `pnpm test` command.
it can be used when not using `pnpm test-dev` or `pnpm test-start` directly. it can be used when not using `pnpm test-dev` or `pnpm test-start` directly.
Valid test modes can be seen here: Valid test modes can be seen here:
https://github.com/vercel/next.js/blob/aa664868c102ddc5adc618415162d124503ad12e/test/lib/e2e-utils.ts#L46 https://github.com/vercel/next.js/blob/aa664868c102ddc5adc618415162d124503ad12e/test/lib/e2e-utils.ts#L46
- Use `NEXT_TEST_DEPLOY_URL` with `pnpm test-deploy` to skip the Vercel deploy step and run
deploy-mode assertions against an existing deployment URL.
- You can use `NEXT_TEST_PREFER_OFFLINE=1` while testing to configure the package manager to include the - 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. [`--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 Wi-Fi. This is helpful when running tests in internet-restricted environments such as planes or public Wi-Fi.
......
...@@ -42,6 +42,8 @@ export class NextDeployInstance extends NextInstance { ...@@ -42,6 +42,8 @@ export class NextDeployInstance extends NextInstance {
super.setup(parentSpan) super.setup(parentSpan)
await super.createTestDir({ parentSpan, skipInstall: true }) await super.createTestDir({ parentSpan, skipInstall: true })
const existingDeployUrl = process.env.NEXT_TEST_DEPLOY_URL?.trim()
// ensure Vercel CLI is installed // ensure Vercel CLI is installed
try { try {
const res = await execa('vercel', ['--version']) const res = await execa('vercel', ['--version'])
...@@ -84,6 +86,17 @@ export class NextDeployInstance extends NextInstance { ...@@ -84,6 +86,17 @@ export class NextDeployInstance extends NextInstance {
) )
vercelFlags.push('--global-config', vcConfigDir) vercelFlags.push('--global-config', vcConfigDir)
} }
if (existingDeployUrl) {
try {
this._url = new URL(existingDeployUrl).toString()
} catch (err) {
throw new Error(
`Invalid NEXT_TEST_DEPLOY_URL value: ${existingDeployUrl}`,
{ cause: err }
)
}
require('console').log(`Using existing deployment URL: ${this._url}`)
} else {
require('console').log(`Linking project at ${this.testDir}`) require('console').log(`Linking project at ${this.testDir}`)
// link the project // link the project
...@@ -167,6 +180,7 @@ export class NextDeployInstance extends NextInstance { ...@@ -167,6 +180,7 @@ export class NextDeployInstance extends NextInstance {
// the CLI gives just the deployment URL back when not a TTY // the CLI gives just the deployment URL back when not a TTY
this._url = deployRes.stdout this._url = deployRes.stdout
}
this._parsedUrl = new URL(this._url) this._parsedUrl = new URL(this._url)
// If configured, we should configure the `/etc/hosts` file to point the // If configured, we should configure the `/etc/hosts` file to point the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment